1 year ago
#356917
SleepyFrog2
Having trouble getting a discrete example of Predict functions confidence interval calculation in R
Hi all I am looking to figure out how the Predict function is calculating the confidence intervals. I know there are similar questions, but I have trouble conceptualizing longer equations without numerical representation (one reason I love coding, I just stink!).
My two part question is really how did Predict calculate the confidence interval of say the $3.5 below. Lower and upper bounds have different deltas throughout so I know the margin of error is different. I tried look through several formulas for margin of error to add to yhat and could not figure this out or what standard deviation was actually being used (I used the population stdev to no avail).
lastly if someone could just provide some sort of example function for the limits when it draws to a graph. There was a very good response here https://stats.stackexchange.com/questions/85560/shape-of-confidence-interval-for-predicted-values-in-linear-regression I just still have no clue how it looks implemented.
if you changed models to logistic (glm) would CI be calculated similarly? or would assumptions of residual error break it.
Thank you!
#fake example of giving someone money and how much a smile is returned
Money<-c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8)
Smile<-c(2.618684,3.004371,2.226206,3.218504,4.206926,5.361271,6.484110,5.412502,3.309511,7.934290,8.286108,8.421875,9.865312,10.163182,9.381625,12.789413,12.404028,12.002910,13.805863,11.978898,13.448826,17.288642,17.105757,16.648129
)
model<-lm(Smile~Money)
new.money=data.frame(Money=c(3,3.5,4.6,5.6))
prediction<-predict(model,new.money, interval="confidence") #start the prediction
prediction<-cbind(new.money,prediction)
print(prediction)
The output is:
Money fit lwr upr
1 3.0 6.049064 5.555977 6.542151
2 3.5 7.051695 6.601570 7.501819
3 4.6 9.257482 8.844543 9.670421
4 5.6 11.262743 10.805119 11.720368
r
statistics
regression
confidence-interval
standard-error
0 Answers
Your Answer