获取R中回归线上一点的置信区间? [英] Get Confidence Interval For One Point On Regression Line In R?

查看:307
本文介绍了获取R中回归线上一点的置信区间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得回归线上1点的CI?我很确定我应该为此使用confint(),但是如果我尝试这样做

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.

我在做什么错了?

推荐答案

您要使用predict()而不是confint().而且,正如Joran所指出的,您需要明确要确定给定x的置信区间还是预测区间. (置信区间表示给定x处y值的期望值的不确定性.预测区间表示具有x值的单个采样点的预测y值周围的不确定性.)

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.)

这是如何在R中执行此操作的简单示例:

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

这篇关于获取R中回归线上一点的置信区间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆