【问题标题】:Set specified factor level as reference in GT regression?在 GT 回归中设置指定的因子水平作为参考?
【发布时间】:2020-09-18 17:12:49
【问题描述】:

我正在使用 gtsummary 包从逻辑回归生成表格。

例如,我想使用试验数据中的阶段级别“T3”作为参考级别,而不是默认的“T1”。我怎样才能在这个示例代码中做到这一点?

我的目标是对单变量和多变量逻辑回归执行此操作,因此我假设答案适用于这两种情况。

library(gtsummary)
library(dplyr)

trial %>%
  dplyr::select(age, trt, marker, stage, response, death, ttdeath) %>%
  tbl_uvregression(
    method = glm,
    y = death,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    pvalue_fun = function(x) style_pvalue(x, digits = 2)) %>%
  # overrides the default that shows p-values for each level
  add_global_p() %>%
  # adjusts global p-values for multiple testing (default method: FDR)
  add_q() %>%
  # bold p-values under a given threshold (default 0.05)
  bold_p() %>%
  # now bold q-values under the threshold of 0.10
  bold_p(t = 0.10, q = TRUE) %>%
  bold_labels() %>% as_gt()

真诚地, 耐莉

【问题讨论】:

    标签: gtsummary


    【解决方案1】:

    我设法解决了我自己的问题,方法是使用 forcats 函数“fct_relevel”将分类变量的所需级别设置为参考。

    trial$stage <- forcats::fct_relevel(trial$stage, "T3")
    

    【讨论】:

    • 感谢@Margaret Hannum 让代码更清晰!
    • 当然!很高兴你能够让代码按照你想要的方式工作;并感谢您发布自己的答案! ^_^
    猜你喜欢
    • 2011-04-21
    • 1970-01-01
    • 2014-06-10
    • 2015-12-22
    • 2018-10-21
    • 2020-03-02
    • 2022-06-15
    相关资源
    最近更新 更多