Calculates and adds p-values to a table created with tbl_continuous(),
comparing the continuous variable across the levels of each include
variable. Called as add_p() on a tbl_continuous object:
add_p(x, test = NULL, pvalue_fun = label_style_pvalue(digits = 1), include = everything(), test.args = NULL, group = NULL, ...).
Details
The default test is "anova_2way" when the table has a by variable.
Without one, the defaults are those of tbl_summary() |> add_p() with the
roles swapped, the include variable playing by: "wilcox.test" when the
include variable takes two values and "kruskal.test" otherwise (a missing
value counts as one of the values, as in gtsummary). There is no default
when group is specified. See ?tests for the available tests;
the swapped tests cannot be used when the table has a by variable.
Arguments
x(tbl_continuous)
A table created withtbl_continuous().test(formula-list)
The test for each include variable, e.g.list(grade = "anova_2way").pvalue_fun(function)
Function that rounds and formats the p-values. Default islabel_style_pvalue(digits = 1).include(selector)
Variables to compute a p-value for. Default iseverything().test.args(formula-list)
Additional arguments passed to the tests, as a named list per variable.group(selector)
Column identifying the pairs or groups of correlated observations. There is no default test withgroup; the tests that use it are not mirrored (seedecisions/0012of the ltsummary repository)....Not used.
See also
Other add statistics:
add_ci(),
add_difference(),
add_difference_row(),
add_n(),
add_overall(),
add_p(),
add_q(),
add_stat(),
add_stat_label(),
tests
Examples
# Example 1 ----------------------------------
# two-way ANOVA: age by grade, adjusted for treatment
trial |>
tbl_continuous(variable = age, by = trt, include = grade) |>
add_p()
# Example 2 ----------------------------------
# without `by`: Kruskal-Wallis test of age across grades
trial |>
tbl_continuous(variable = age, include = grade) |>
add_p()