繁体   English   中英

如何从对数模型(glmer)中获得两组成功概率差异的轮廓置信区间?

[英]How to obtain profile confidence intervals of the difference in probability of success between two groups from a logit model (glmer)?

我正在努力将从对数模型中获得的对数比比率分布置信区间转换为概率。 我想知道如何计算两组之间差异的置信区间。

如果p值> 0.05,则差异的95%CI应该从零以下到零以上。 但是,我不知道当对数比必须取幂时如何获得负值。 因此,我尝试计算(B)组之一的CI,并查看CI的上下限与A组的估算值之间的差异。 我相信这不是计算差异CI的正确方法,因为A的估计值也不确定。

如果有人可以帮助我,我将很高兴。

library(lme4)    
# Example data: 
set.seed(11)
treatment = c(rep("A",30), rep("B", 40))
site = rep(1:14, each = 5)
presence = c(rbinom(30, 1, 0.6),rbinom(40, 1, 0.8))
df = data.frame(presence, treatment, site)

# Likelihood ratio test 
M0 = glmer(presence ~ 1 + (1|site), family = "binomial", data = df)
M1 = glmer(presence ~ treatment + (1|site), family = "binomial", data = df)
anova(M1, M0)

# Calculating confidence intervals
cc <- confint(M1, parm = "beta_")
ctab <- cbind(est = fixef(M1), cc)
cdat = as.data.frame(ctab)

# Function to back-transform to probability (0-1)
unlogit = function(y){
    y_retransfromed = exp(y)/(1+exp(y))
    y_retransfromed
}

# Getting estimates
A_est = unlogit(cdat$est[1]) 
B_est = unlogit(cdat$est[1] + cdat$est[2])
B_lwr = unlogit(cdat$est[1] + cdat[2,2])
B_upr = unlogit(cdat$est[1] + cdat[2,3])

Difference_est = B_est - A_est

# This is how I tried to calculate the CI of the difference
Difference_lwr = B_lwr - A_est
Difference_upr = B_upr - A_est

# However, I believe this is wrong because A_est is also “uncertain” 

如何获得存在概率差异的置信区间?

我们可以通过以下方式计算平均治疗效果。 根据原始数据,创建两个新的数据集,一个新数据集,其中所有单位都接受治疗A,一个新数据集,其中所有单位都接受治疗B。现在,根据您的模型估算值(在您的情况下为M1 ),我们计算出单位的预测结果在这两个数据集中的每个数据集中。 然后,我们计算两个数据集之间结果的平均差异,以获得估计的平均治疗效果。 在这里,我们可以编写一个带有glmer对象并计算平均处理效果的函数:

ate <- function(.) {
  treat_A <- treat_B <- df
  treat_A$treatment <- "A"
  treat_B$treatment <- "B"
  c("ate" = mean(predict(., newdata = treat_B, type = "response") -
    predict(., newdata = treat_A, type = "response")))
}
ate(M1)
#        ate 
# 0.09478276 

我们如何获得不确定区间? 我们可以使用引导程序,即使用从原始数据中随机生成的样本对模型进行多次重新评估,每次都计算平均治疗效果。 然后,我们可以使用自举平均处理效果的分布来计算不确定性间隔。 在这里,我们使用bootMer函数生成了100个仿真

out <- bootMer(M1, ate, seed = 1234, nsim = 100)

并检查效果的分布:

quantile(out$t, c(0.025, 0.5, 0.975))
#        2.5%         50%       97.5% 
# -0.06761338  0.10508751  0.26907504 

暂无
暂无

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

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