我有两个不同的置信区间。我做错了什么?

问题描述 投票:0回答:1

我使用 R 计算了 OLS 回归截距的 90% 置信区间。当我使用 confint(model, '(Intercept)', level=0.90) 时,我得到了与使用 [beta0- 计算的 CI 不同的 CI qnorm(0.95)*beta0_se, beta0+qnorm(0.95)*beta0_se]。 这是 R 代码和输出。

library(estimatr)
mtcars <- read.csv("mtcars.csv")
model <- lm_robust(mpg ~ hp, data = mtcars)
summary(model)

beta0_estimate <- summary(model)$coefficients["(Intercept)", "Estimate"]
beta0_se <- summary(model)$coefficients["(Intercept)", "Std. Error"]

confint(model, '(Intercept)', level = 0.90)
beta0_estimate-qnorm(0.95)*beta0_se
beta0_estimate+qnorm(0.95)*beta0_se
Call:
lm_robust(formula = mpg ~ hp, data = mtcars)

Standard error type:  HC2 

Coefficients:
            Estimate Std. Error t value  Pr(>|t|) CI Lower CI Upper DF
(Intercept) 30.09886    2.19301  13.725 1.814e-14 25.62013 34.57759 30
hp          -0.06823    0.01471  -4.637 6.485e-05 -0.09828 -0.03818 30

Multiple R-squared:  0.6024 ,   Adjusted R-squared:  0.5892 
F-statistic:  21.5 on 1 and 30 DF,  p-value: 6.485e-05
                 5 %     95 %
(Intercept) 26.37675 33.82097
[1] 26.49168
[1] 33.70604

我也尝试过95%的置信区间,问题仍然存在。

r statistics linear-regression lm confidence-interval
1个回答
0
投票

置信区间基于学生 t 分布,因此您需要使用

qt()
而不是
qnorm()

> beta0_estimate + qt(0.95,30)*beta0_se * c(-1, 1)
[1] 26.37675 33.82097
© www.soinside.com 2019 - 2024. All rights reserved.