繁体   English   中英

在 gt_summary 中使用 add_difference 时仅显示差异列 function

[英]Show only the difference column when using add_difference function in gt_summary

像这样使用 add_difference function 创建表时

  trial %>%
  select(trt, age, marker, response, death) %>%
  tbl_summary(
    by = trt,
    missing = "no"
  ) %>%
  add_difference()

您将获得一个包含差异列以及 p_value 和 CI 列的表。 在此处输入图像描述

我想删除这些列,因为我想为连续变量的非参数测试添加 p_values,据我从本文档中理解,使用 add_difference 无法完成。

如果我使用 modify_column_hide(columns = c(p.value, ci)) 而不是 add_p 我会得到一个错误:

trial %>%
  select(trt, age, marker, response, death) %>% tbl_summary(
    by = trt,
    missing = "no" ) %>%
  add_difference() %>% 
  modify_column_hide(columns = c(p.value, ci)) %>% 
  add_p()

#Error: `add_p()` cannot be run after `add_difference()` or `add_p()` when a #'p.value' column is already present.

这样做的正确方法是什么?

这是我会怎么做...

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.7.0'

trial %>%
  select(trt, age, marker, response, death) %>% tbl_summary(
    by = trt,
    missing = "no" ) %>%
  add_difference() %>% 
  modify_column_hide(columns = c(p.value, ci)) %>% # hide the CI and p-value
  modify_table_body(~.x %>% select(-p.value)) %>% # remove the p-value from the table 
  modify_footnote(estimate = NA) %>% # remove difference footnote
  add_p() %>% # add new p-values
  as_kable() # convert to kable so it will display on stackoverflow
特征 药物 A , N = 98 药物 B , N = 102 区别 p值
年龄 46 (37, 59) 48 (39, 56) -0.44 0.7
标记水平 (ng/mL) 0.84 (0.24, 1.57) 0.52 (0.19, 1.20) 0.20 0.085
肿瘤反应 28 (29%) 33 (34%) -4.2% 0.5
病人死亡 52 (53%) 60 (59%) -5.8% 0.4

创建于 2023-01-26,使用reprex v2.0.2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM