I want to compare baseline characteristics between more than two studygroups and I prefer to use gt-summary to make the table.How can I add pvalues, corrected for multiple testing, to the table for comparisons between groups?
I tried the approach as mentioned here:
Gtsummary columns for all post hoc pairwise comparisons
The approach for continuous variables works fine but for categorical values all the mentioned appoaches do not work.
add_stat_pairwise_chisq <- function(data, variable, by, ...) {
# Calculate pairwise p-values
pw <- chisq.multcomp(to_test = data[[variable]], factor = data[[by]], p.method = "none")
# convert p-values to list
index <- 0L
p.value.list <- list()
for(i in seq_len(nrow(pw$p.value))) {
for(j in seq_len(nrow(pw$p.value))) {
index <- index + 1L
p.value.list[[index]] <- c(pw$p.value[i, j]) %>%
setNames(glue::glue("**{colnames(pw$p.value)[j]} vs. {rownames(pw$p.value)[i]}**"))
}
}
# convert list to data frame
p.value.list %>%
unlist() %>%
purrr::discard(is.na) %>%
t() %>%
as.data.frame() %>%
# formatting/rounding p-values
dplyr::mutate(dplyr::across(everything(), style_pvalue))
}
table1 <- df %>%
tbl_summary(
by= Studiegroep,
digits = list(age_yrs ~ 0),
missing="no",
statistic = list(all_categorical() ~ "{n} ({p})")) %>%
add_stat(list(all_continuous() ~ add_stat_pairwise, all_categorical() ~ add_stat_pairwise_chisq))
for every categorical variable R gives this error:
There was an error for variable 'Sex':
Error in `[.default`(x, I): invalid subscript type 'closure'
user25268315 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.