【问题标题】:order.terms does not reorder terms in sjPlot's plot_modelorder.terms 不会重新排序 sjPlot 的 plot_model 中的术语
【发布时间】:2021-02-15 17:10:39
【问题描述】:

我有代码来绘制一个简单的三级单因素回归图,我无法说服 sjPlot 重新排列 X 轴上的项,我想知道是否有人可以帮助我弄清楚发生了什么。

我的代码:

m0 <- lmer(ans ~ type + (1|subject/target), data=behavioral_data)
summary(m0)

p1 <- plot_model(m0, 
                 type = "pred", 
                 terms = c("type"),
                 order.terms = c(2, 1),
                 auto.label = F,
                 title = "Model Estimates of Answer (Marginal Effects)",
                 axis.title = c("Target Type", "Answer")
)

模型摘要产生的输出:

Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: ans ~ type + (1 | subject/target)
   Data: behavioral_data

REML criterion at convergence: 15354

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.8944 -0.7136 -0.1561  0.6646  3.2381 

Random effects:
 Groups         Name        Variance Std.Dev.
 target:subject (Intercept) 0.1434   0.3787  
 subject        (Intercept) 0.3051   0.5524  
 Residual                   1.7003   1.3040  
Number of obs: 4447, groups:  target:subject, 444; subject, 37

Fixed effects:
             Estimate Std. Error        df t value Pr(>|t|)    
(Intercept)   2.74088    0.10181  48.14515  26.922   <2e-16 ***
typeN        -0.03277    0.06509 404.96582  -0.503   0.6149    
typeY        -0.14263    0.06506 404.00056  -2.193   0.0289 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

我得到的图表:

我希望 order.terms = c(2, 1) 重新排序 Y 和 N。我错过了什么?

【问题讨论】:

    标签: r sjplot


    【解决方案1】:

    由于 plot_model() 返回的是一个 ggplot 对象,您可以添加其他与 ggplot 相关的函数来后期修改绘图。例如,试试这个:

    p1 <- plot_model(m0, 
                     type = "pred", 
                     terms = c("type"),
                     order.terms = c(2, 1),
                     auto.label = F,
                     title = "Model Estimates of     Answer (Marginal Effects)",
                     axis.title = c("Target Type", "Answer")
    ) + scale_x_discrete(limits=c("S", "Y", "N"))
    

    discrete-series 中的 limits=() 参数可以接受一个字符向量来指示 x 轴的顺序。

    【讨论】:

      猜你喜欢
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多