Skip to contents

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, ...).

Value

A tbl_continuous table with a p.value column.

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 with tbl_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 is label_style_pvalue(digits = 1).

  • include (selector)
    Variables to compute a p-value for. Default is everything().

  • 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 with group; the tests that use it are not mirrored (see decisions/0012 of the ltsummary repository).

  • ... Not used.

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()