繁体   English   中英

如何在 R 中使用 glm 获得“二项式比例的 95%CI”

[英]How to get “95%CI for a Binomial Proportion” using glm in R

我参考了站点Interval Estimation for a Binomial Proportion Using glm in R,获得“渐近”95% CI。 我认为二项式链接没有“身份”,但下面的程序得到了答案。 为什么? 如果你知道,请给我一些建议。

本例,n=10,x=2,渐近 95%CI

binom.ci<-function(x,n,alpha = 0.05,link="logit"){
z<-qnorm(1-alpha/2)
family<-binomial(link=link)
fit<-summary(glm(cbind(x,n-x)~1,family=family))
est<-fit$coef[,"Estimate"]
se<-fit$coef[,"Std. Error"]
family$linkinv(est+c(-z,z)*se)
}

binom.ci(x=2,n=10,link="identity")
# [1] -0.04791801  0.44791801

binomial可以有一个“身份”链接函数,但在这里没有多大意义。 如果我们使用示例中的参数复制glm调用,我们可以看到函数内部发生了什么。

fit <- summary(glm(cbind(2, 8) ~ 1,family = binomial("identity")))
fit
#> 
#> Call:
#> glm(formula = cbind(2, 8) ~ 1, family = binomial("identity"))
#> 
#> Deviance Residuals: 
#> [1]  0
#> 
#> Coefficients:
#>             Estimate Std. Error z value Pr(>|z|)
#> (Intercept)   0.2000     0.1265   1.581    0.114
#> 
#> (Dispersion parameter for binomial family taken to be 1)
#> 
#>     Null deviance: 0  on 0  degrees of freedom
#> Residual deviance: 0  on 0  degrees of freedom
#> AIC: 4.3947
#> 
#> Number of Fisher Scoring iterations: 2

“身份”链接意味着截距将直接解释为概率,但问题是从字面上看,这意味着我们的 95% 置信区间包括负概率,这没有任何意义。 我们真的需要在这里使用 logit 链接来获得正确的答案。

所以是的,我们可以在这里使用binomial(link = "identity")而不会抛出错误,但它不会为我们提供二项式比例的经典 95% 置信区间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM