Hi!
I have a database with variables that characterize two groups (a control group and a treatment group). With the exception of the variable that distinguishes these two groups, all other variables are of the numeric type.
Considering this scenario, when I try to use the "tbl_summary ()" function of the "gtsummary" package, I am facing problems that, apparently, are related to the recognition of the variable type of some of the numerical variables. The basic statistics that, by default of the "gtsummary" package, should be shown in the summary table are "median (Q1, Q3)", since all variables are numeric. However, even when I force these metrics into the "statistic" argument of the "tbl_summary" function (an argument that defines the basic statistics to be presented for each variable) this does not happen. For part of the numerical variables the statistics shown in the table are the statistics that, by default of the "gtsummary" package, would be shown for categorical variables, that is, "n (%)".
This same problem occurs for the "test" argument of the "add_p ()" function of the same "gtsummary" package (argument that defines the test to be performed for each bank variable). Instead of running the declared test for all numeric variables ("wilcox.test"), for part of the numerical variables another test ends up being executed, a specific test for categorical variables ("fisher.test").
Among the countless tests that I performed to try to understand the problem, I was able to solve the problem only for the "test" argument. Since this argument accepts the use of "everything ()", by replacing "all_continuous () ~ 'wilcox.test'" with "everything () ~ 'wilcox.test'", the wilcoxon test was correctly applied to all numeric variables. However, since the "statistic" argument does not accept "everything ()" and apparently only accepts "all_continuous ()" or "all_cathegoric ()", this did not solve the problem of the basic statistics that are presented in the summary table (median (Q1, Q3) vs. n (%)).
data %>%
gtsummary::tbl_summary(data = .,
by = group) %>%
gtsummary::add_p(x = .,
test = list(everything() ~ "wilcox.test"))
OR
data %>%
gtsummary::tbl_summary(data = .,
by = group,
statistic =
list(all_continuous() ~ "{median} ({p25}, {p75})")) %>%
gtsummary::add_p(x = .,
test = list(everything() ~ "wilcox.test"))