[英]Curve Fitting in R
R中曲线拟合的任何资源? 我遇到了https://sysstatsoftware.com/products/sigmaplot/product-uses/sigmaplot-products-uses-curve-fitting-using-sigmaplot/
R 中有任何类似的建议或库吗?
谢谢!
嗨,在 R 中进行曲线拟合的方法不止一种,而是几种。您可以从以下简单的事情开始
x <- c(32,64,96,118,126,144,152.5,158)
#make y as response variable
y <- c(99.5,104.8,108.5,100,86,64,35.3,15)
plot(x,y,pch=19)
这应该给你下面的情节。 观察曲线告诉我们我们可以在这里拟合一些很好的多项式曲线。
现在我们可以在下面的数据上拟合我们的曲线:
linMod <- lm(y~x)
#second degree polynomial model
linMod2 <- lm(y~poly(x,2,raw=TRUE))
#third degree polynomial model
linMod3 <- lm(y~poly(x,3,raw=TRUE))
#fourth degree polynomial model
linMod4 <- lm(y~poly(x,4,raw=TRUE))
#generate new data in range of 50 numbers starting from 30 and ending at 160
newData <- seq(30,160, length=50)
plot(x,y,pch=19,ylim=c(0,150))
lines(newData, predict(linMod, data.frame(x=newData)), col="red")
lines(newData, predict(linMod2, data.frame(x=newData)), col="green")
lines(newData, predict(linMod3, data.frame(x=newData)), col="blue")
lines(newData, predict(linMod4, data.frame(x=newData)), col="purple")
给我们:
这只是 R 中曲线拟合的一个简单说明。 有大量可用的教程,也许您可以从这里开始查看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.