Tried to follow a previous post (How to add the effect size in the summary table using R package “gtsummary”?) to include the eta squared effect size in a summary table but column kept coming up blank.
Created effect size function:
my_ES_test <- function(data, variable, by, ...) {
aovmod = aov(variable ~ by, data = data)
lsr::etaSquared(aovmod)[1,1]
}
Then tried to add it to our (admittedly, a little complex) summary table:
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
Would also love to change the Missing counts to %s if possible!

