2

我正在使用 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()

真诚的,耐莉

4

1 回答 1

2

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

trial$stage <- forcats::fct_relevel(trial$stage, "T3")
于 2020-05-31T12:06:04.473 回答