add_p.tbl_cross: Adds p-value to crosstab table

Description Usage Arguments Example Output Author(s) See Also Examples

View source: R/add_p.R

Description

Calculate and add a p-value comparing the two variables in the cross table. Missing values are included in p-value calculations.

Usage

1
2
## S3 method for class 'tbl_cross'
add_p(x, test = NULL, pvalue_fun = NULL, source_note = NULL, ...)

Arguments

x

Object with class tbl_cross from the tbl_cross function

test

A string specifying statistical test to perform. Default is "chisq.test" when expected cell counts >=5 and "fisher.test" when expected cell counts <5.

pvalue_fun

Function to round and format p-value. Default is style_pvalue, except when source_note = TRUE when the default is style_pvalue(x, prepend_p = TRUE)

source_note

Logical value indicating whether to show p-value in the {gt} table source notes rather than a column.

...

Not used

Example Output

Example 1

Example 2

Author(s)

Karissa Whiting

See Also

Other tbl_cross tools: inline_text.tbl_cross(), tbl_cross()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Example 1 ----------------------------------
add_p_cross_ex1 <-
  trial %>%
  tbl_cross(row = stage, col = trt) %>%
  add_p()

# Example 2 ----------------------------------
add_p_cross_ex2 <-
  trial %>%
  tbl_cross(row = stage, col = trt) %>%
  add_p(source_note = TRUE)

ddsjoberg/gtsummary documentation built on April 8, 2021, 5:48 a.m.