【发布时间】:2022-01-07 00:02:27
【问题描述】:
尝试按照之前的帖子 (How to add the effect size in the summary table using R package “gtsummary”?) 将 eta 平方效应大小包含在汇总表中,但列始终为空白。
创建的效果大小函数:
my_ES_test <- function(data, variable, by, ...) {
aovmod = aov(variable ~ by, data = data)
lsr::etaSquared(aovmod)[1,1]
}
然后尝试将其添加到我们的(诚然,有点复杂)汇总表:
factor_table2 <- data_comp%>%
select(Group, F1, F2, F3, F4, H1, H2, H3, E1, E2, E3, K1, K2, Global, eqMMSE)%>%
tbl_summary(by = Group ,missing="always",missing_text = "Missing",
type = all_continuous() ~ "continuous2",
statistic = all_continuous() ~ c("{mean} ({sd})","{median} ({p25}-{p75})"))%>%
add_p(test = list(all_continuous() ~ "aov", all_categorical() ~ "kruskal.test"),pvalue_fun = ~style_pvalue(.x,digits =2))%>%
add_n() %>%
modify_header(update = list(
label ~ "",
n ~ "*N*",
stat_1 ~ "**CDR = 0** <br> *({n})*",
stat_2 ~ "**CDR = 0.5** <br> *({n})*",
stat_3 ~ "**CDR > 0.5** <br> *({n})*"
))%>%
bold_labels()%>%
italicize_levels()%>%
modify_spanning_header(all_stat_cols()~"**Clinical Dementia Rating**")%>%
add_stat(fns = all_continuous() ~ my_ES_test) %>%
modify_header(add_stat_1 ~ "**Eta squared**") %>%
as_gt()
factor_table2
如果可能,也希望将缺失计数更改为 %s!
【问题讨论】:
标签: gtsummary