Skip to contents

Calculates and adds a p-value comparing the two variables of a table created with tbl_cross(). When the missing-value level is shown in the table, it is included in the calculation. Called as add_p() on a tbl_cross object.

Value

A tbl_cross table with a p.value column, or with a source note when source_note = TRUE.

Arguments

  • x (tbl_cross)
    A table created with tbl_cross().

  • test (string)
    The test to perform. Default is "chisq.test.no.correct" when every expected cell count is 5 or more and "fisher.test" otherwise; see tests for the available tests.

  • pvalue_fun (function)
    Function that rounds and formats the p-value. Default is label_style_pvalue(digits = 1), or label_style_pvalue(digits = 1, prepend_p = TRUE) when source_note = TRUE.

  • source_note (scalar logical)
    Whether to show the p-value as a source note below the table rather than in a column. Default is FALSE.

  • test.args (named list)
    Additional arguments passed to the test, e.g. test.args = list(correct = TRUE) for a chi-squared test with a continuity correction.

  • ... Not used.

See also

Other cross tables: tbl_cross()

Examples

# Example 1 ----------------------------------
trial |>
  tbl_cross(row = stage, col = trt) |>
  add_p()
# Example 2 ---------------------------------- trial |> tbl_cross(row = stage, col = trt) |> add_p(source_note = TRUE)