让我们有一些线性模型,例如简单的方差分析:
# data generation
set.seed(1.234)
Ng <- c(41, 37, 42)
data <- rnorm(sum(Ng), mean = rep(c(-1, 0, 1), Ng), sd = 1)
fact <- as.factor(rep(LETTERS[1:3], Ng))
m1 = lm(data ~ 0 + fact)
summary(m1)
结果如下:
Call:
lm(formula = data ~ 0 + fact)
Residuals:
Min 1Q Median 3Q Max
-2.30047 -0.60414 -0.04078 0.54316 2.25323
Coefficients:
Estimate Std. Error t value Pr(>|t|)
factA -0.9142 0.1388 -6.588 1.34e-09 ***
factB 0.1484 0.1461 1.016 0.312
factC 1.0990 0.1371 8.015 9.25e-13 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.8886 on 117 degrees of freedom
Multiple R-squared: 0.4816, Adjusted R-squared: 0.4683
F-statistic: 36.23 on 3 and 117 DF, p-value: < 2.2e-16
现在,我尝试两种不同的方法来估计这些参数的置信区间
c = coef(summary(m1))
# 1st method: CI limits from SE, assuming normal distribution
cbind(low = c[,1] - qnorm(p = 0.975) * c[,2],
high = c[,1] + qnorm(p = 0.975) * c[,2])
# 2nd method
confint(m1)
问题:
- 估计线性回归系数的分布是什么?正常还是?
- 为什么两种方法产生不同的结果?假设正态分布和正确的SE,我希望两种方法的结果相同。
非常感谢你!
数据〜0 +事实
答案后编辑:
答案是正确的,这将与confint(m1)
!产生完全相同的结果。
# 3rd method
cbind(low = c[,1] - qt(p = 0.975, df = sum(Ng) - 3) * c[,2],
high = c[,1] + qt(p = 0.975, df = sum(Ng) - 3) * c[,2])
相关:stats.stackexchange.com/questions/111559/…–
—
好奇的