R中的曲线拟合问题
我这里有一个简单的问题,因为我对R语言还不熟悉。我觉得这段代码不适合曲线拟合:多边形拟合肯定是正确的,但对数和指数拟合我不确定(e拟合是错误的)。任何帮助都将不胜感激,谢谢-萨姆R中的曲线拟合问题,r,R,我这里有一个简单的问题,因为我对R语言还不熟悉。我觉得这段代码不适合曲线拟合:多边形拟合肯定是正确的,但对数和指数拟合我不确定(e拟合是错误的)。任何帮助都将不胜感激,谢谢-萨姆 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) p
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')
}
polyFit否,如下所示:
eFit <- function(xs,ys) {
expEstimate = lm(log(ys) ~ xs)
plot(xs, ys,pch='@')
lines(xs, exp(predict(expEstimate)),col='green')
}
eFit我觉得你们的型号还不错。也许你的问题是你没有改变你的预测。例如,在eFit
中,预测日志(ys)
,并根据ys
绘制它们。可能您应该绘制exp(predict(logEstimate))
。像这样吗?:eFit