简体   繁体   中英

Plotting multiple random effects in single plot mixed models

library("lme4")
data(sleepstudy)             

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

To visualise the random effect,

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

In my orginal data, I have three random groups. However, if I want to plot the random effects, they all come in three separate plots. How can I put them in all single plot in 1 X 3 panel or 3 X 1 panel.

You could use 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]])

Produces:

在此处输入图片说明

You also could consider lattice::qqmath() .

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

Produces:

在此处输入图片说明

Note: To specify the columns use the ncol option. Compare eg grid.arrange(p2[[1]], p2[[2]], ncol=2) vs. grid.arrange(p2[[1]], p2[[2]], ncol=1) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM