【发布时间】:2019-04-23 06:34:46
【问题描述】:
R 中曲线拟合的任何资源? 我遇到了https://systatsoftware.com/products/sigmaplot/product-uses/sigmaplot-products-uses-curve-fitting-using-sigmaplot/
R 中是否有类似的推荐或库?
谢谢!
【问题讨论】:
标签: r curve-fitting
R 中曲线拟合的任何资源? 我遇到了https://systatsoftware.com/products/sigmaplot/product-uses/sigmaplot-products-uses-curve-fitting-using-sigmaplot/
R 中是否有类似的推荐或库?
谢谢!
【问题讨论】:
标签: r curve-fitting
您好,在 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 中曲线拟合的一个简单说明。那里有大量可用的教程,也许你可以从这里开始:
【讨论】: