0
因为我是R语言的新手,所以在这里我只提一个简短的问题。我不觉得这个代码适合曲线拟合:poly拟合肯定会检查出来,但是我不确定的日志和指数拟合(e fit是否错误)。任何帮助将不胜感激,谢谢。萨姆R中的曲线拟合问题
polyFit <- function(xs,ys,degree) { #polynomial fitting a data set degree 3
fit3 <- lm(ys~poly(xs,degree,raw=TRUE))
xx <- seq(0,160, length=50)
plot(xs,ys,pch='@')
lines(xx, predict(fit3, data.frame(xs=xx)), col="green")
}
logFit <- function(xs,ys) { #graph the data set with log(x), y
logEstimate = lm(ys ~ log(xs))
plot(xs,ys,pch='@')
lines(xs,predict(logEstimate),col='green')
}
eFit <- function(xs,ys) {
logEstimate = lm(log(ys) ~ xs)
plot(xs,ys,pch='@')
lines(xs,predict(logEstimate),col='green')
}
澄清,XS = X点,YS = Y点
我认为你的模型很好。可能你的问题是你没有改变你的预测。例如,在你的'eFit'中,你预测'log(ys)',并将它们绘制成'ys'。可能你应该画出'exp(预测(logEstimate))'。 – Gregor 2014-10-30 18:18:01
所以像这样?:eFit < - function(xs,ys)logEstimate = lm(log(ys)〜xs) plot(xs,ys,pch ='@') lines(predict(logEstimate),ys ,col ='green') } – user3558177 2014-10-30 18:46:15