【问题标题】:specific manipulation of axis limits and scales in sjplot::plot_model of logistic glmer that generally preserves plot_model output逻辑 glmer 的 sjplot::plot_model 中轴限制和比例的特定操作,通常保留 plot_model 输出
【发布时间】:2020-06-24 14:26:05
【问题描述】:

对不起,如果这是一个重复的帖子,我看过一些类似的帖子,但没有找到我正在寻找的确切解决方案。

我将 glmer 模型拟合到表单的一些反应时间数据:

m19 <- glmer(response ~ trial_z*stim + cond  + (1 + stim | subj_idx), 
             na.action = na.exclude,  
             data = gng, family = "binomial", 
             control = glmerControl(optCtrl = list(maxfun = 50000)))

其中:response 是标准 go/no-go 任务上的二进制(正确响应,不正确响应)。

我想使用 sjplot::plot_model 函数绘制固定效应的优势比,但似乎无法让事情看起来很正确。

我想为我的模型中的固定效应绘制这些优势比:

library(broom.mixed)
tidy(m19,conf.int=TRUE,exponentiate=TRUE,effects="fixed")

看起来像:

# A tibble: 7 x 8
  effect term              estimate std.error statistic  p.value  conf.low conf.high
  <chr>  <chr>                <dbl>     <dbl>     <dbl>    <dbl>     <dbl>     <dbl>
1 fixed  (Intercept)      414.      123.          20.2  6.98e-91 231.       742.    
2 fixed  trial_z            0.697     0.0751      -3.35 7.97e- 4   0.564      0.860 
3 fixed  stimNoGo           0.00925   0.00257    -16.9  6.80e-64   0.00537    0.0159
4 fixed  condThreeGo        1.48      0.151        3.82 1.32e- 4   1.21       1.80  
5 fixed  condFiveGo         1.69      0.174        5.07 4.08e- 7   1.38       2.06  
6 fixed  condSevenGo        1.51      0.151        4.07 4.73e- 5   1.24       1.83  
7 fixed  trial_z:stimNoGo   1.30      0.149        2.28 2.25e- 2   1.04       1.63  

以下 sjplot 调用产生以下绘图对象:

gg <- plot_model(m19, type="std", show.p=TRUE, ci.lvl=.95, dot.size=5, 
                 line.size=2, vline.color = "black", axis.lim=c(.001, 2.25)) + 
  theme_bw(base_size=24) +
  theme(panel.grid.major.y=element_blank()) +
  ggtitle("") + 
  ylab("Odds Ratio")
plot(gg)

所以我尝试在调用中编辑axis.limits:

gg2 <- plot_model(m19, type="std", show.p=TRUE, ci.lvl=.95, dot.size=5, 
                  line.size=2, vline.color = "black", axis.lim=c(.001, 11)) + 
  theme_bw(base_size=24) +
  theme(panel.grid.major.y=element_blank()) +
  ggtitle("") + 
  ylab("Odds Ratio")

plot(gg2)

有点烦人,将第二个连接的axis.lim 元素碰撞到1 到10 之间的任何值产生了我的尝试1,但是任何高于10 的值都将情节中的限制设置为100(不知道为什么会这样......)

所以我尝试根据其他帖子事后编辑轴:

gg + ylim(.001, 2.25)

我的问题:

我想要一个结合了尝试 2 和尝试 3 的情节。

在 2 中,我喜欢低于和高于 1 的缩放比例不同,并且 1(相等几率)有一个特殊的含义,表明与 1 重叠的 CI 表示无效效应。如果我想要在plot_model() 的能力范围内,我会被困在如何使该 1 标记右侧的轴看起来更像尝试 3 中的刻度,这消除了对赔率的良好描述将所有 y 值的比例设置为统一(此外,考虑到我正在寻找管理用户在 x 轴上看到的内容,这肯定令人困惑。我假设函数中某处有一个 coord_flip 调用。 ..)。

如果我能进一步澄清 lmk.感谢您的意见!

【问题讨论】:

    标签: r ggplot2 sjplot


    【解决方案1】:

    我认为这可能有效:

    gg + scale_y_log10(limits = c(0.001, 2.25))
    

    例子:

    library(sjPlot)
    library(ggplot2)
    model <- glm(vs ~ mpg + cyl, data = mtcars, family = "binomial")
    p <- plot_model(model)
    p + scale_y_log10(limits = c(0.001, 2.5))
    #> Scale for 'y' is already present. Adding another scale for 'y', which will
    #> replace the existing scale.
    

    reprex package (v0.3.0) 于 2020 年 6 月 27 日创建

    【讨论】:

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