Get Confidence Interval For One Point On Regression Line In R?

我的梦境 提交于 2019-11-28 02:08:38

问题


How do I get the CI for one point on the regression line? I'm quite sure I should use confint() for that, but if I try this

confint(model,param=value)

it just gives me the same number as if I just type in

confint(model)

if I try without a value, it does not give me any values at all.

What am I doing wrong?


回答1:


You want predict() instead of confint(). Also, as Joran noted, you'll need to be clear about whether you want the confidence interval or prediction interval for a given x. (A confidence interval expresses uncertainty about the expected value of y-values at a given x. A prediction interval expresses uncertainty surrounding the predicted y-value of a single sampled point with that value of x.)

Here's a simple example of how to do this in R:

df <- data.frame(x=1:10, y=1:10 + rnorm(10))

f <- lm(y~x, data=df)

predict(f, newdata=data.frame(x=c(0, 5.5, 10)), interval="confidence")
#         fit       lwr       upr
# 1 0.5500246 -1.649235  2.749284
# 2 5.7292889  4.711230  6.747348
# 3 9.9668688  8.074662 11.859075

predict(f, newdata=data.frame(x=c(0, 5.5, 10)), interval="prediction")
#         fit       lwr       upr
# 1 0.5500246 -3.348845  4.448895
# 2 5.7292889  2.352769  9.105809
# 3 9.9668688  6.232583 13.701155


来源:https://stackoverflow.com/questions/12732424/get-confidence-interval-for-one-point-on-regression-line-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!