在 R 中获取预测函数置信区间计算的离散示例时遇到问题
嗨,我要弄清楚预测函数如何计算置信区间。我知道有类似的问题,但是我很难将较长的方程式概念化而没有数值表示(我喜欢编码的原因之一,我只是臭!)。
我的两个问题是如何预测如何计算以下$ 3.5的置信区间。下限和上限在整个过程中都有不同的三角洲,因此我知道误差余量是不同的。我尝试浏览几个公式以添加到YHAT中,无法弄清楚这一点,或者实际上使用了哪种标准偏差(我使用人口STDEV无济于事)。
最后,如果某人可以为限制提供某种示例函数,则当它绘制到图形时。这里有很好的回应 https:/https:/ /stats.stackexchange.com/questions/85560/shape-of-confidence-interval-for-predistic-values-in-linear-recression 我只是不知道它的实现方式。
如果您将模型更改为逻辑(GLM),CI是否会类似地计算?或假设残留错误会损坏它。
谢谢你!
#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)
输出是:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论