add_p.tbl_summary | R Documentation |
Adds p-values to tables created by tbl_summary()
by comparing values across groups.
## S3 method for class 'tbl_summary'
add_p(
x,
test = NULL,
pvalue_fun = label_style_pvalue(digits = 1),
group = NULL,
include = everything(),
test.args = NULL,
adj.vars = NULL,
...
)
x |
( |
test |
( See below for details on default tests and ?tests for details on available tests and creating custom tests. |
pvalue_fun |
( |
group |
( |
include |
( |
test.args |
( |
adj.vars |
( |
... |
These dots are for future extensions and must be empty. |
a gtsummary table of class "tbl_summary"
See the ?tests help file for details on available tests and creating custom tests. The ?tests help file also includes pseudo-code for each test to be clear precisely how the calculation is performed.
The default test used in add_p()
primarily depends on these factors:
whether the variable is categorical/dichotomous vs continuous
number of levels in the tbl_summary(by)
variable
whether the add_p(group)
argument is specified
whether the add_p(adj.vars)
argument is specified
add_p(group)
nor add_p(adj.vars)
"wilcox.test"
when by
variable has two levels and variable is continuous.
"krustkal.test"
when by
variable has more than two levels and variable is continuous.
"chisq.test.no.correct"
for categorical variables with all expected cell counts >=5,
and "fisher.test"
for categorical variables with any expected cell count <5.
add_p(group)
and not add_p(adj.vars)
"lme4"
when by
variable has two levels for all summary types.
There is no default for grouped data when by
variable has more than two levels.
Users must create custom tests for this scenario.
add_p(adj.vars)
and not add_p(group)
"ancova"
when variable is continuous and by
variable has two levels.
# Example 1 ----------------------------------
trial |>
tbl_summary(by = trt, include = c(age, grade)) |>
add_p()
# Example 2 ----------------------------------
trial |>
select(trt, age, marker) |>
tbl_summary(by = trt, missing = "no") |>
add_p(
# perform t-test for all variables
test = everything() ~ "t.test",
# assume equal variance in the t-test
test.args = all_tests("t.test") ~ list(var.equal = TRUE)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.