簡體   English   中英

如何使用R中的confint計算95%CI?

[英]How is 95% CI calculated using confint in R?

我使用confint幫助頁面中提供的示例

> fit <- lm(100/mpg ~ disp + hp + wt + am, data=mtcars)
> summary(fit)

Call:
lm(formula = 100/mpg ~ disp + hp + wt + am, data = mtcars)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.6923 -0.3901  0.0579  0.3649  1.2608 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept) 0.740648   0.738594   1.003  0.32487   
disp        0.002703   0.002715   0.996  0.32832   
hp          0.005275   0.003253   1.621  0.11657   
wt          1.001303   0.302761   3.307  0.00267 **
am          0.155815   0.375515   0.415  0.68147   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.6754 on 27 degrees of freedom
Multiple R-squared: 0.8527,     Adjusted R-squared: 0.8309 
F-statistic: 39.08 on 4 and 27 DF,  p-value: 7.369e-11 

> confint(fit)
                   2.5 %      97.5 %
(Intercept) -0.774822875 2.256118188
disp        -0.002867999 0.008273849
hp          -0.001400580 0.011949674
wt           0.380088737 1.622517536
am          -0.614677730 0.926307310
> confint(fit, "wt")
       2.5 %   97.5 %
> wt 0.3800887 1.622518

>confint.default(fit,"wt")
       2.5 %   97.5 %
wt 0.4079023 1.594704

> 1.001303 + 1.96*0.302761
[1] 1.594715
> 1.001303 - 1.96*0.302761
[1] 0.4078914

因此,從confint.default獲得的95%CI是基於漸近正態性的。 對於confint怎么confint

謝謝

您可以查看每種方法的代碼。

# View code for 'default'
confint.default
# View code of lm objects
getAnywhere(confint.lm)

差異似乎是默認使用普通分位數,而線性模型的方法則使用T分位數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM