问题:在gtsummary
函数tbl_summary
中计算总非缺失观测值的列百分比。我想gtsummary
从缺失和非缺失观察的总数中计算百分比。
来自http://www.danieldsjoberg.com/gtsummary/articles/gallery.htmlgtsummary
的Table Gallery 的示例
trial[c("trt", "age", "grade")] %>%
tbl_summary(
by = trt,
missing = "no",
statistic = all_continuous() ~ "{median} ({p25}, {p75}) [N = {N_nonmiss}]"
) %>%
modify_header(stat_by = md("**{level}**<br>N = {n} ({style_percent(p)}%)")) %>%
add_n() %>%
bold_labels() %>%
modify_spanning_header(starts_with("stat_") ~ "**Chemotherapy Treatment**")
等级没有缺失的观察结果,因此药物 A 组中 35 名患有 1 级疾病的人为 35/98 (36%)。
现在,将 3 级重新编码为缺失:
trial$grade[trial$grade %in% "III"] <- NA
trial$grade <- droplevels(trial$grade)
重新运行tbl_summary
:
trial[c("trt", "age", "grade")] %>%
tbl_summary(
by = trt,
missing = "no",
statistic = all_continuous() ~ "{median} ({p25}, {p75}) [N = {N_nonmiss}]"
) %>%
modify_header(stat_by = md("**{level}**<br>N = {n} ({style_percent(p)}%)")) %>%
add_n() %>%
bold_labels() %>%
modify_spanning_header(starts_with("stat_") ~ "**Chemotherapy Treatment**")
1 级现在表示为 67 个 (52%) 非缺失 obs 中的 n = 35 个。在药物 A 组。我仍然希望将百分比表示为 98 人的 36%。有没有办法做到这一点gtsummary
?