【问题标题】:Plotting random slopes from glmer model using sjPlot使用 sjPlot 从 glmer 模型中绘制随机斜率
【发布时间】:2018-12-19 16:49:10
【问题描述】:

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

这是我认为应该允许生成图形的代码。我只是在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"))

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

plot_model(fit2,type="re")
plot_model(fit2,type="prob")
plot_model(fit2,type="eff") 

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

【问题讨论】:

  • 只是澄清一下:您是在谈论链接博客文章中的type = "ri.prob"?您能具体说明您尝试过的方法和无效的方法吗?
  • 我说的是情节类型=“ri.prob”。我将编辑我的问题以显示我尝试过的内容。

标签: r graphics sjplot


【解决方案1】:

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

(pp <- plot_model(fit2,type="pred",
       terms=c("c12hour","grp"),pred.type="re"))
  • type="pred":绘制预测值
  • terms=c("c12hour", "grp"):在预测中包含 c12hour(作为 x 轴变量)和 grp
  • pred.type="re": 随机效果

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

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

【讨论】:

  • 我在这里使用你的代码:bbolker.github.io/mixedmodels-misc/… 来计算 conf。诠释。或预测。诠释。但是,对于混合模型,我不确定在绘制特定级别的随机效应时这会如何工作,以获得随机效应的 CI / PI。
【解决方案2】:

Ben 已经发布了正确答案。 sjPlot 使用ggeffects-package 来绘制边际效应图,因此另一种方法是直接使用 ggeffects:

ggpredict(fit2, terms = c("c12hour", "grp"), type="re") %>% plot()

a new vignette 描述了如何获得混合模型/随机效应的边际效应。但是,此绘图类型目前不提供置信区间。

链接的博客文章中的 type = "ri.prob" 选项没有针对协变量进行调整,这就是为什么我首先删除了该选项,然后在 ggeffects / sjPlot 中(正确地)重新实现了它。链接的博客文章中显示的置信区间也不正确。一旦我想出了如何获得 CI 或预测区间的方法,我也会添加这个选项。

【讨论】:

  • 是否可以 exp() 预测值和置信区间,而不是获取直线,而是获取曲线?我一直在尝试在 ggpredict 中使用变换,但我一直有非平行线
  • 不,只能在响应尺度上绘制预测。但是,您可以尝试modelbased::estimate_link() 在链接尺度上绘制预测。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多