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?
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