View source: R/add_p.tbl_svysummary.R
add_p.tbl_svysummary | R Documentation |
Adds p-values to tables created by tbl_svysummary()
by comparing values across groups.
## S3 method for class 'tbl_svysummary'
add_p(
x,
test = list(all_continuous() ~ "svy.wilcox.test", all_categorical() ~ "svy.chisq.test"),
pvalue_fun = label_style_pvalue(digits = 1),
include = everything(),
test.args = NULL,
...
)
x |
( |
test |
( See below for details on default tests and ?tests for details on available tests and creating custom tests. |
pvalue_fun |
( |
include |
( |
test.args |
( |
... |
These dots are for future extensions and must be empty. |
a gtsummary table of class "tbl_svysummary"
# Example 1 ----------------------------------
# A simple weighted dataset
survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |>
tbl_svysummary(by = Survived, include = c(Sex, Age)) |>
add_p()
# A dataset with a complex design
data(api, package = "survey")
d_clust <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc)
# Example 2 ----------------------------------
tbl_svysummary(d_clust, by = both, include = c(api00, api99)) |>
add_p()
# Example 3 ----------------------------------
# change tests to svy t-test and Wald test
tbl_svysummary(d_clust, by = both, include = c(api00, api99, stype)) |>
add_p(
test = list(
all_continuous() ~ "svy.t.test",
all_categorical() ~ "svy.wald.test"
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.