How to compute standard error for predicted data in R using predict

随声附和 提交于 2019-12-07 10:42:29

You should probably be a bit more careful with data inside and outside data.frames. Your newdata= parameter should be a data.frame with column names that match the original prodicters. Something like this would be better

a_b <- data.frame(
    a=c(60, 65, 70, 75, 80, 85, 90, 95, 100, 105),
    b=c(26, 24.7, 20, 16.1, 12.6, 10.6, 9.2, 7.6, 6.9, 6.9)
)

plot(b~a, a_b, col = "purple")

reg <- lm(b ~ a, a_b)
abline(reg,col="red")

z <- predict(reg, newdata=data.frame(a=110), se.fit=TRUE)
# $fit
#        1 
# 1.353333 
# 
# $se.fit
# [1] 1.466349
# 
# $df
# [1] 8
# 
# $residual.scale
# [1] 2.146516
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!