r - calculate x value using polynomial line of best fit - Stack Overflow

I am calculating a line of best fit for a set of data, then using that line to infer y values for new x

I am calculating a line of best fit for a set of data, then using that line to infer y values for new x values. Some calculated y values make sense and look appropriate, yet several do not fall on the line of best fit.

# calculate line of best fit
y <- c(0.1, 0.5, 0.6, 0.7, 0.8, 1.1, 1.3)
x <- c(20, 30, 50, 150, 650, 800, 860)
poly <- lm(y ~ stats::poly(x,6, raw=TRUE))

# visualize
plot(x, y, main="Polynomial Fit (Degree 6)", xlab="depth mbsf", ylab="sed age", pch=16)
lines(x, predict(poly, data.frame(x=x)), col="blue")

# calculate new y for new x
new_x <- c(15,20,22,25,30,40,80,110,150,280,290,645,675,
           810,815,818,820,825,845,860)
ycalc <- predict(poly, newdata = data.frame(x= new_x))
points(new_x, ycalc, col="red", pch=19, cex=2)
text(new_x, ycalc, labels = round(ycalc, 2), pos=4, col="red")

Can someone explain to me why x=30 does not fall on the line of best fit? With my real data there are several points like x=30.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743753181a4501278.html

相关推荐

  • r - calculate x value using polynomial line of best fit - Stack Overflow

    I am calculating a line of best fit for a set of data, then using that line to infer y values for new x

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信