如何在 R 中找到 glm 模型的置信区间?


要为 lm 模型(线性回归模型)找到置信区间,我们可以使用 confint 函数,而且无需传达置信水平,因为默认值是 95%。这也可以用于 glm 模型(广义线性模型)。请查看以下示例以了解 confint 对 glm 模型的输出。

示例 1

实时演示

> set.seed(3214)
> x1<-rpois(20,5)
> y1<-sample(0:1,20,replace=TRUE)
> Model1<-glm(y1~x1,family="binomial")
> summary(Model1)

输出

Call:
glm(formula = y1 ~ x1, family = "binomial")

Deviance Residuals:
Min 1Q Median 3Q Max
-1.6360 -1.4156 0.7800 0.8567 0.9946

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.34851 1.17554 0.296 0.767
x1 0.09794 0.21421 0.457 0.648

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 24.435 on 19 degrees of freedom
Residual deviance: 24.221 on 18 degrees of freedom
AIC: 28.221

Number of Fisher Scoring iterations: 4

> confint(Model1)
Waiting for profiling to be done...
2.5 % 97.5 %
(Intercept) -1.9946211 2.8014055
x1 -0.3179604 0.5537196

示例 2

实时演示

> x2<-runif(200,2,5)
> y2<-sample(0:1,200,replace=TRUE)
> Model2<-glm(y2~x2,family="binomial")
> summary(Model2)

输出

Call:
glm(formula = y2 ~ x2, family = "binomial")

Deviance Residuals:
Min 1Q Median 3Q Max
-1.162 -1.152 -1.145 1.202 1.211

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.009208 0.631317 -0.015 0.988
x2 -0.013999 0.169522 -0.083 0.934

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 277.08 on 199 degrees of freedom
Residual deviance: 277.07 on 198 degrees of freedom
AIC: 281.07

Number of Fisher Scoring iterations: 3

> confint(Model2)
Waiting for profiling to be done...
2.5 % 97.5 %
(Intercept) -1.2517839 1.2317974
x2 -0.3473611 0.3192271

示例 3

实时演示

> x3<-runif(5000,2,5)
> y3<-sample(0:1,5000,replace=TRUE)
> Model3<-glm(y3~x3,family="binomial")
> summary(Model3)

输出

Call:
glm(formula = y3 ~ x3, family = "binomial")

Deviance Residuals:
Min 1Q Median 3Q Max
-1.177 -1.166 -1.156 1.188 1.199

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.03254 0.11913 0.273 0.785
x3 -0.01674 0.03288 -0.509 0.611

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 6930.6 on 4999 degrees of freedom
Residual deviance: 6930.3 on 4998 degrees of freedom
AIC: 6934.3

Number of Fisher Scoring iterations: 3

> confint(Model3)
Waiting for profiling to be done...
2.5 % 97.5 %
(Intercept) -0.20096508 0.2660569
x3 -0.08119495 0.0476911

更新于: 2020 年 11 月 19 日

6K+ 浏览量

启动你的职业生涯

完成课程获得认证

开始学习
广告