如何在 table 摘要中显示 eta 平方
How to show eta squared in a table summary
试图按照之前的 post () 将 eta 平方效应大小包含在摘要中 table 但该列一直空白。
创建的效果大小函数:
my_ES_test <- function(data, variable, by, ...) {
aovmod = aov(variable ~ by, data = data)
lsr::etaSquared(aovmod)[1,1]
}
然后尝试将其添加到我们的(不可否认,有点复杂)摘要中 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
结果 table:
如果可能,也希望将缺失计数更改为 %s!
您对 eta 函数的定义似乎有误。我已经更新了它,并将它添加到一个简单的 tbl_summary()
.
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.5.0'
my_ES_test <- function(data, variable, by, ...) {
aovmod = aov(data[[variable]] ~ data[[by]])
lsr::etaSquared(aovmod)[1,1]
}
# test eta function
my_ES_test(trial, "age", "grade")
#> [1] 0.003380277
tbl <-
trial %>%
select(grade, age, marker) %>%
tbl_summary(
by = grade,
missing = "no",
type = all_continuous() ~ "continuous2",
statistic =
all_continuous() ~ c("{mean} ({sd})",
"{median} ({p25}, {p75})",
"{N_miss} ({p_miss}%)")
) %>%
add_stat_label(label = all_continuous() ~ c("Mean (SD)", "Median (IQR)", "Missing")) %>%
add_stat(fns = all_continuous() ~ my_ES_test) %>%
modify_header(add_stat_1 ~ "**\U03B7\U00B2**")
由 reprex package (v2.0.1)
创建于 2022-01-06
PS 你创造了一个美丽的table!
试图按照之前的 post (
创建的效果大小函数:
my_ES_test <- function(data, variable, by, ...) {
aovmod = aov(variable ~ by, data = data)
lsr::etaSquared(aovmod)[1,1]
}
然后尝试将其添加到我们的(不可否认,有点复杂)摘要中 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
结果 table:
如果可能,也希望将缺失计数更改为 %s!
您对 eta 函数的定义似乎有误。我已经更新了它,并将它添加到一个简单的 tbl_summary()
.
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.5.0'
my_ES_test <- function(data, variable, by, ...) {
aovmod = aov(data[[variable]] ~ data[[by]])
lsr::etaSquared(aovmod)[1,1]
}
# test eta function
my_ES_test(trial, "age", "grade")
#> [1] 0.003380277
tbl <-
trial %>%
select(grade, age, marker) %>%
tbl_summary(
by = grade,
missing = "no",
type = all_continuous() ~ "continuous2",
statistic =
all_continuous() ~ c("{mean} ({sd})",
"{median} ({p25}, {p75})",
"{N_miss} ({p_miss}%)")
) %>%
add_stat_label(label = all_continuous() ~ c("Mean (SD)", "Median (IQR)", "Missing")) %>%
add_stat(fns = all_continuous() ~ my_ES_test) %>%
modify_header(add_stat_1 ~ "**\U03B7\U00B2**")
PS 你创造了一个美丽的table!