How to obtain profile confidence intervals of the difference in probability of success between two groups from a logit model (glmer)?
我正在努力将从 logit 模型获得的对数优势比配置文件置信区间转换为概率。我想知道如何计算两组之间差异的置信区间。
如果 p 值 > 0.05,则差值的 95% CI 应介于零以下到零以上。但是,我不知道当对数比率必须取幂时如何获得负值。因此,我尝试计算其中一组 (B) 的 CI,并查看 CI 的下端和上端与 A 组估计值的差异是多少。我认为这不是计算差异 CI 的正确方法,因为 A 的估计也是不确定的。
如果有人可以帮助我,我会很高兴。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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 # Calculating confidence intervals # Function to back-transform to probability (0-1) # Getting estimates Difference_est = B_est – A_est # This is how I tried to calculate the CI of the difference # However, I believe this is wrong because A_est is also a€?uncertaina€? |
如何得到存在概率之差的置信区间?
我们可以通过以下方式计算平均治疗效果。根据原始数据,创建两个新数据集,其中一个所有单位都接受治疗 A,另一个所有单位都接受治疗 B。现在,根据您的模型估计(在您的情况下为 M1),我们计算预测结果对于这两个数据集中的单位。然后,我们计算两个数据集之间结果的平均差异,以获得我们估计的平均治疗效果。在这里,我们可以编写一个接受 glmer 对象并计算平均治疗效果的函数:
1
2 3 4 5 6 7 8 9 10 |
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 |
我们如何得到不确定区间?我们可以使用 bootstrap,即使用从原始数据中随机生成的样本多次重新估计模型,每次计算平均处理效果。然后,我们可以使用自举平均治疗效果的分布来计算我们的不确定区间。这里我们使用 bootMer 函数
生成 100 个模拟
1
|
out <- bootMer(M1, ate, seed = 1234, nsim = 100)
|
并检查效果的分布:
1
2 3 |
quantile(out$t, c(0.025, 0.5, 0.975))
# 2.5% 50% 97.5% # -0.06761338 0.10508751 0.26907504 |
- 首先,感谢您的出色回答。我对此仍有一些疑问:a)我是否必须担心警告,或者这仅仅是因为无法仅通过样本数据中的一种治疗来评估治疗效果?我特别关注模型未能收敛的说法。
- warnings() (i)\\\\t1: In checkConv(attr(opt, “derivs”), opt$par, ctrl = control$checkConv, … : (ii)\\\\t 无法评估缩放梯度 ( iii)\\\\t2: In checkConv(attr(opt, “derivs”), opt$par, ctrl = control$checkConv, … : (iv)\\\\t Hessian 在数值上是奇异的:参数不是唯一确定的(v)\\\\tIn checkConv(attr(opt, “derivs”), opt$par, ctrl = control$checkConv, … : (vi)\\\\t 模型未能收敛到 max|grad| = 0.0157858 (tol = 0.001,组件 1)
- b) 这个过程是否称为参数引导程序?a€? c) 我可以按如下方式计算 p 值:p_value = mean(abs(out$t – mean(out$t))>= abs(out$t0)) d) 是否无法获得关于治疗对存在概率的影响的配置文件置信区间(即基于似然比检验的 CI)?
- (a) 如果收敛警告只发生在少数运行中,我不会太担心它们。您还可以参考关于 SO 和 Web 其他地方的 lmer/glmer\\’s 收敛警告的更深入讨论。 (b) 是的。 (c) 我认为你的方法是有道理的,但我不 (d) 对不起,我不熟悉 profile 方法。
- 谢谢黄伟煌!我会接受这个答案,但我仍然会很高兴听到其他人的…
来源:https://www.codenong.com/42345799/