我正在使用 R 包“gtsummary”创建汇总表。这实际上非常好。add_stat 函数为您提供了很大的自由来包含附加组件。例如,在我所在的地区,我们想用置信区间 (ES [90% CI]) 告知效应大小。所以,我想帮助包括 CI 范围。我实现的代码可以正常工作,但没有数字控制,也没有 CI 范围。
# Packages ----------------------------------------------------------------
library(gtsummary)
library(gt)
library(dplyr)
library(purrr)
# Example 1 ---------------------------------------------------------------
# fn returns ES value
my_EStest <- function(data, variable, by, ...) {
effsize::cohen.d(data[[variable]] ~ as.factor(data[[by]]),
conf.level=.90, pooled=TRUE, paired=FALSE,
hedges.correction=TRUE)$estimate
}
add_ES <-
trial %>%
select(trt, age) %>%
tbl_summary(by = trt, missing = "no",
statistic = list(all_continuous() ~ "{mean} ({sd})"),
digits = list(all_continuous() ~ c(1,1))) %>%
add_p(test = everything() ~ t.test) %>%
add_stat(
fns = everything() ~ my_EStest,
fmt_fun = style_pvalue,
header = "**ES**"
)
add_ES
# counterproof
effsize::cohen.d(age ~ trt, data = trial, conf.level=.90, return.dm=TRUE, pooled=TRUE, paired=FALSE, hedges.correction=TRUE)