如何修改"gtsummary"中"all_categorical()"定义的默认变量类型?什么时候需要序数变量的平均值?

How to modify the default variable type defined by "all_categorical()" in "gtsummary"? when mean of ordinal variable were wanted?

变量"Var2"默认设置为分类变量,有时需要均值(sd)。所以我对如何修改这个很感兴趣。

data_table_1 = 
  data %>% 
  dplyr::select(group, var1, var2)


data_table_1 %>%
  tbl_summary(by = group, missing = "no",
              statistic = list(all_continuous() ~ "{mean} ± {sd}",
                               all_categorical() ~ "{n} ({p}%)"),
              digits = list(all_continuous() ~ c(2, 2))) %>%
  add_p(test = list(all_continuous() ~ "pttest2", all_categorical() ~ "pttest2"),
        pvalue_fun = function(x) sprintf(x, fmt='%#.3f')) 

函数 tbl_summary() 会尽力猜测最适合数据的摘要类型...但这并不总是您想要的数据摘要类型。要更新默认摘要类型,请使用 type= 参数。在这种情况下,您希望包含 type = list(Var2 ~ "continuous") 以连续汇总数据。

希望对您有所帮助!