R/add_difference.tbl_svysummary.R
add_difference.tbl_svysummary.Rd
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,
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()),
...
)
(tbl_summary
)
table created with tbl_summary()
(formula-list-selector
)
Specifies the tests/methods to perform for each variable, e.g.
list(all_continuous() ~ "t.test", all_dichotomous() ~ "prop.test", all_categorical(FALSE) ~ "smd")
.
See below for details on default tests and ?tests for details on available tests and creating custom tests.
(tidy-select
)
Variable name of an ID or grouping variable. The column can be used to
calculate p-values with correlated data.
Default is NULL
. See tests for methods that utilize the group
argument.
(tidy-select
)
Variables to include in adjusted calculations (e.g. in ANCOVA models).
Default is NULL
.
(formula-list-selector
)
Containing additional arguments to pass to tests that accept arguments.
For example, add an argument for all t-tests, use
test.args = all_tests("t.test") ~ list(var.equal = TRUE)
.
(numeric
)
a scalar in the interval (0, 1)
indicating the confidence level. Default is 0.95
(tidy-select
)
Variables to include in output. Default is everything()
.
(function
)
Function to round and format p-values. Default is label_style_pvalue()
.
The function must have a numeric vector input, and return a string that is
the rounded/formatted p-value (e.g. pvalue_fun = label_style_pvalue(digits = 2)
).
(formula-list-selector
)
List of formulas specifying the functions
to round and format differences and confidence limits.
Default is
list(c(all_continuous(), all_categorical(FALSE)) ~ label_style_sigfig(), all_categorical() ~ \(x) paste0(style_sigfig(x, scale = 100), "%"))
These dots are for future extensions and must be empty.
a gtsummary table of class "tbl_summary"