使用 sjPlot 从 glmer 模型中绘制随机斜率

use*_*796 3 graphics r sjplot

过去,我曾使用sjPlotsjp.glmer包中的将广义混合效应模型的不同斜率可视化。但是,使用新包,我无法弄清楚如何绘制各个斜率,如图中(随机)组级别的固定效应概率,位于此处

这是我认为应该允许生成图形的代码。我似乎无法在新版本的sjPlot.

library(lme4)
library(sjPlot)
data(efc)
# create binary response
efc$hi_qol = 0
efc$hi_qol[efc$quol_5 > mean(efc$quol_5,na.rm=T)] = 1
# prepare group variable
efc$grp = as.factor(efc$e15relat)
# data frame for 2nd fitted model
mydf <- na.omit(data.frame(hi_qol = as.factor(efc$hi_qol),
                           sex = as.factor(efc$c161sex),
                           c12hour = as.numeric(efc$c12hour),
                           neg_c_7 = as.numeric(efc$neg_c_7),
                           grp = efc$grp))
# fit 2nd model
fit2 <- glmer(hi_qol ~ sex + c12hour + neg_c_7 + (1|grp),
              data = mydf,
              family = binomial("logit"))
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下代码绘制模型。

plot_model(fit2,type="re")
plot_model(fit2,type="prob")
plot_model(fit2,type="eff") 
Run Code Online (Sandbox Code Playgroud)

我想我可能缺少一个标志,但是在阅读了文档后,我无法找出那个标志可能是什么。

Ben*_*ker 5

看起来这可能会做你想要的:

(pp <- plot_model(fit2,type="pred",
       terms=c("c12hour","grp"),pred.type="re"))
Run Code Online (Sandbox Code Playgroud)
  • type="pred": 绘制预测值
  • terms=c("c12hour", "grp"):包括c12hour(作为 x 轴变量)和grp预测
  • pred.type="re": 随机效应

我还没有能够获得置信区间色带(尝试过ci.lvl=0.9,但没有运气......)

pp+facet_wrap(~group) 更接近链接博客文章中显示的情节(每个随机效应级别都有自己的方面......)

在此处输入图片说明