【问题标题】:Plotting multiple random effects in single plot mixed models在单区混合模型中绘制多个随机效应
【发布时间】:2018-06-19 11:02:08
【问题描述】:
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 面板中的所有单个图中。

【问题讨论】:

    标签: r lme4 sjplot


    【解决方案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).

    【讨论】:

    • sjPlot 中grid.arrange() 周围还有一个小包装:plot_grid()。所以,plot_model(fit1,type = "re") %&gt;% plot_grid() 会产生相同的输出。
    猜你喜欢
    • 2015-09-13
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 2018-05-10
    相关资源
    最近更新 更多