【发布时间】:2021-09-17 05:33:36
【问题描述】:
我已成功计算出一个表中的置信区间,但无法将这两个表合并为一个。它似乎不起作用。期望的输出是有 有趣的是没有错误。
library(gtsummary)
library(tidyverse)
tbl2 <-
trial %>%
mutate(trt = as.factor(trt)) %>%
select(grade, response, trt) %>%
tbl_summary(missing = "no", type = everything() ~ "categorical")
myci2 <- tbl2$meta_data %>%
filter(summary_type %in% c("categorical", "dichotomous")) %>%
select(summary_type, var_label, df_stats) %>%
unnest(df_stats) %>%
mutate(
conf.low = (p - qnorm(0.975) * sqrt(p * (1 - p) / N)) %>%
style_percent(symbol = TRUE),
conf.high =( p + qnorm(0.975) * sqrt(p * (1 - p) / N)) %>%
style_percent(symbol = TRUE),
ci = str_glue("{conf.low}, {conf.high}"),
label = coalesce(variable_levels, var_label),
row_type = ifelse(summary_type == "dichotomous", "label", "level")
) %>%
select(variable, row_type, label, ci)
finaltbl <- tbl2 %>%
modify_table_body(
left_join,
myci2,
by = c("variable", "row_type", "label")
)
【问题讨论】:
-
请提供您的数据(样本)。
-
试用数据在gtsummary包中
-
加载包时,数据集将可用。谢谢