在单图混合模型中绘制多个随机效应

Plotting multiple random effects in single plot mixed models

library("lme4")
data(sleepstudy)             

fit1 <- lmer(Reaction ~ Days + (1|Subject), sleepstudy) 

为了可视化随机效应,

library(sjPlot)
plot_model(fit1,type = "re",facet.grid = FALSE) 

在我的原始数据中,我有三个随机组。但是,如果我想绘制随机效应,它们都会出现在三个单独的图中。我怎样才能将它们放在 1 X 3 面板或 3 X 1 面板的所有单个图中。

你可以使用 gridExtra::grid.arrange()

fit1 <- lmer(Reaction ~ (1|Days) + (1|Subject), sleepstudy) 

library(sjPlot)
p <- plot_model(fit1, type = "re", facet.grid=FALSE) 

library(gridExtra)
grid.arrange(p[[1]], p[[2]])

产生:

你也可以考虑lattice::qqmath()

library(lattice)
p2 <- qqmath(ranef(fit1, condVar=TRUE))
grid.arrange(p2[[1]], p2[[2]])

产生:

注意: 要指定列,请使用 ncol 选项。比较例如grid.arrange(p2[[1]], p2[[2]], ncol=2) 对比 grid.arrange(p2[[1]], p2[[2]], ncol=1).