使用sjPlot从glmer模型绘制随机斜率 [英] Plotting random slopes from glmer model using sjPlot
问题描述
过去,我使用了sjp.glmer > sjPlot 可以可视化广义混合效应模型中的不同斜率.但是,使用新程序包,我无法弄清楚如何绘制各个斜率,如上图所示,该图显示的是(随机)组级别的固定效果的概率,位于
In the past, I had used the sjp.glmer
from the package sjPlot to visualize the different slopes from a generalized mixed effects model. However, with the new package, I can't figure out how to plot the individual slopes, as in the figure for the probabilities of fixed effects by (random) group level, located here
我认为,这里是应允许生成图形的代码.我只是无法在新版本的sjPlot
中得到它.
Here is the code that, I think, should allow for the production of the figure. I just can't seem to get it in the new version of 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"))
我尝试使用以下代码来绘制模型图.
I have tried to graph the model using the following code.
plot_model(fit2,type="re")
plot_model(fit2,type="prob")
plot_model(fit2,type="eff")
我认为我可能会丢失一个标志,但是在阅读了文档之后,我找不到该标志可能是什么.
I think that I may be missing a flag, but after reading through the documentation, I can't find out what that flag may be.
推荐答案
如下所示,您可能想要做的事:
Looks like this might do what you want:
(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"
:随机效果 type="pred"
: plot predicted valuesterms=c("c12hour", "grp")
: includec12hour
(as the x-axis variable) andgrp
in the predictionspred.type="re"
: random effects
我还无法获得置信区间的彩带(尝试了ci.lvl=0.9
,但没有运气...)
I haven't been able to get confidence-interval ribbons yet (tried ci.lvl=0.9
, but no luck ...)
pp+facet_wrap(~group)
更接近链接的博客文章中显示的情节(每个随机效应级别都有其自己的特征……)
pp+facet_wrap(~group)
comes closer to the plot shown in the linked blog post (each random-effects level gets its own facet ...)
这篇关于使用sjPlot从glmer模型绘制随机斜率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!