View source: R/add_difference.tbl_svysummary.R
| add_difference.tbl_svysummary | R Documentation |
Adds difference to tables created by tbl_summary().
The difference between two groups (typically mean or rate difference) is added
to the table along with the difference's confidence interval and a p-value (when applicable).
## S3 method for class 'tbl_svysummary'
add_difference(
x,
test = NULL,
group = NULL,
adj.vars = NULL,
test.args = NULL,
conf.level = 0.95,
levels = NULL,
include = everything(),
pvalue_fun = label_style_pvalue(digits = 1),
estimate_fun = list(c(all_continuous(), all_categorical(FALSE)) ~ label_style_sigfig(),
all_dichotomous() ~ label_style_sigfig(scale = 100, suffix = "%"), all_tests("smd")
~ label_style_sigfig()),
...
)
x |
( |
test |
( See below for details on default tests and ?tests for details on available tests and creating custom tests. |
group |
( |
adj.vars |
( |
test.args |
( |
conf.level |
( |
levels |
( |
include |
( |
pvalue_fun |
( |
estimate_fun |
( |
... |
These dots are for future extensions and must be empty. |
a gtsummary table of class "tbl_summary"
# Example 1 ----------------------------------
survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |>
tbl_svysummary(
by = Survived,
value = list(Class ~ "1st", Age = "Child"),
include = c(Class, Age)
) |>
add_difference()
# Example 2 ----------------------------------
# Select two groups to compare when `by=` has 3+ levels
survey::svydesign(~1, data = trial, weights = ~1) |>
tbl_svysummary(by = grade, include = c(age, marker), missing = "no") |>
add_difference(levels = c("I", "III"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.