Adds p-values to the output comparing values across groups

add_comparison(x, test = NULL, pvalue_fun = fmt_pvalue,
  id = x$inputs$id)

Arguments

x

object with class fmt_table1 from the fmt_table1 function

test

user defined list of statistical tests provided as a named character vector with variables as names and test functions as values., e.g. list(age = "t.test", ptstage = "fisher.test"). Options include "t.test" for a T-test, "wilcox.test" for a Wilcoxon rank sum test, "kruskal.test" for a Kruskal-Wallis rank sum test, "chisq.test" for a Chi-squared test, "fisher.test" for a Fisher's exact test, and "re" for a random intercept model to account for clustered data. For "re" to be used "id" must also be specified in the function call.

pvalue_fun

function for rounding/formatting p-values. Default is fmt_pvalue. The function must have a single input (the numeric, exact p-value), and return a string that is the rounded/formatted p-value (e.g. pvalue_fun = function(x) fmt_pvalue(x, digits = 2) or equivalently, purrr::partial(fmt_pvalue, digits = 2)).

id

Character vector of an ID or grouping variable. Summary statistics will not be printed for this column, but they may be used in subsequent functions. For example, the ID column may be used in add_comparison() to include p-values with correlated data. Default is the id = input from fmt_table1

Examples

trial %>% fmt_table1(by = "trt") %>% add_comparison()
#> #> Variable Drug Placebo p-value #> N = 107 N = 93 #> Age, yrs 47 (39, 58) 46 (36, 54) 0.3 #> Unknown 3 5 #> Marker Level, ng/mL 0.61 (0.22, 1.20) 0.72 (0.22, 1.63) 0.4 #> Unknown 4 4 #> T Stage 0.13 #> T1 25 (23%) 26 (28%) #> T2 26 (24%) 23 (25%) #> T3 29 (27%) 13 (14%) #> T4 27 (25%) 31 (33%) #> Grade 0.3 #> I 38 (36%) 29 (31%) #> II 34 (32%) 24 (26%) #> III 35 (33%) 40 (43%) #> Tumor Response 52 (51%) 30 (33%) 0.017 #> Unknown 6 3