二项式GLMM输出显著效应,为何预测图CI误差棒重叠?
二项式GLMM预测图CI重叠问题排查
模型与代码信息
拟合的二项式GLMM代码
m17 <- glmer(Attendance ~ Day + Sex + (1|AgeClass) + (1|Year) + (1|Plastic), data = test2, family = binomial(link = "logit"))
预测图绘制代码
plot_model(m17, type = "pred" , terms = c("Day [all]", "Sex"), colors = c("blue", "red"), ci.lvl = .95, legend.title = NA, line.size = 1, show.legend = FALSE) + labs(x = "Days Relative to Clutch Initiation", y = "P(Attend at night)", title = NULL) + scale_x_continuous(expand = c(0, 0), breaks = breaks, labels = labels) + scale_y_continuous(limit = c(0, 1), expand = c(0, 0)) + theme_classic() + guides(fill=guide_legend(nrow=2,byrow=TRUE)) + theme(axis.text=element_text(size=22, color = "black", family = "serif"), axis.title=element_text(size=22, color = "black", family = "serif"), axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust=2.5), axis.ticks.length=unit(0.1,"inch"), legend.key.size = unit(1, 'cm'), legend.position = c(0.15, 0.92), legend.text = element_text(colour="black", size=20, family = "serif"), plot.margin = margin(1,.5,1,1, "cm"))
模型摘要输出
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) [glmerMod] Family: binomial ( logit ) Formula: Attendance ~ Day + Sex + (1 | AgeClass) + (1 | Year) + (1 | Plastic) Data: test2 AIC BIC logLik deviance df.resid 16138.4 16182.7 -8063.2 16126.4 11868 Scaled residuals: Min 1Q Median 3Q Max -1.5394 -0.9688 -0.5740 0.9656 1.8762 Random effects: Groups Name Variance Std.Dev. Plastic (Intercept) 0.1374817 0.3708 Year (Intercept) 0.0531973 0.2306 AgeClass (Intercept) 0.0009734 0.0312 Number of obs: 11874, groups: Plastic, 237; Year, 4; AgeClass, 3 Fixed effects: Estimate Std. Error z value Pr(>|z|) (Intercept) 0.135928 0.137669 0.987 0.32347 Day -0.005972 0.002061 -2.897 0.00377 ** SexFemales -0.248756 0.063937 -3.891 1e-04 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Correlation of Fixed Effects: (Intr) Day Day -0.378 SexFemales -0.240 0.004
核心问题
模型摘要显示Day和Sex对Attendance均有显著效应,但用plot_model绘制预测图时,不同性别的预测概率CI误差棒几乎重叠,想确认是log-odds系数转换为预测概率导致的问题,还是绘图代码有误。
问题解答
绘图代码无错误:你的绘图逻辑完全合理,
plot_model(type="pred")会基于模型固定效应计算预测概率,正确完成log-odds到概率尺度的转换,CI计算也符合规范。核心原因:log-odds到概率的非线性转换:
- Sex的log-odds系数为-0.2488,对应的概率差异需通过logit逆函数计算:截距0.1359对应的概率为
plogis(0.1359) ≈ 0.534,女性的概率为plogis(0.1359 - 0.2488) ≈ 0.472,两者概率差仅约0.06,数值差异本身很小。 - 概率尺度的CI由log-odds尺度的CI转换而来,非线性转换会让概率接近0.5时的CI更窄,进一步压缩视觉差异,导致误差棒看起来重叠。
- Sex的log-odds系数为-0.2488,对应的概率差异需通过logit逆函数计算:截距0.1359对应的概率为
验证方法:
- 手动计算预测概率及其CI:提取固定效应估计值和协方差矩阵,计算log-odds的CI后转换为概率尺度,与
plot_model结果对比,确认一致性。 - 绘制log-odds尺度的预测图(
type="pred", transform=NULL),此时能看到Sex的效应和CI在log-odds尺度上有明显区分,证明模型的显著效应真实存在,只是概率尺度下差异被压缩。
- 手动计算预测概率及其CI:提取固定效应估计值和协方差矩阵,计算log-odds的CI后转换为概率尺度,与
呈现建议:
- 若需突出Sex的效应,可在图中标注两组平均概率差异,或在文本中明确说明数值差异与统计显著性,不要仅依赖视觉呈现。
- 也可调整y轴范围聚焦在概率差异区间(如0.45-0.55),放大视觉差异,但需注意避免误导读者。
内容的提问来源于stack exchange,提问作者NeedHelpWithR
相关产品推荐
相关产品推荐

