View source: R/add_difference.R
add_difference.tbl_summary | 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_summary'
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()),
...
)
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 |
( |
include |
( |
pvalue_fun |
( |
estimate_fun |
( |
... |
These dots are for future extensions and must be empty. |
a gtsummary table of class "tbl_summary"
# Example 1 ----------------------------------
trial |>
select(trt, age, marker, response, death) %>%
tbl_summary(
by = trt,
statistic =
list(
all_continuous() ~ "{mean} ({sd})",
all_dichotomous() ~ "{p}%"
),
missing = "no"
) |>
add_n() |>
add_difference()
# Example 2 ----------------------------------
# ANCOVA adjusted for grade and stage
trial |>
select(trt, age, marker, grade, stage) %>%
tbl_summary(
by = trt,
statistic = list(all_continuous() ~ "{mean} ({sd})"),
missing = "no",
include = c(age, marker, trt)
) |>
add_n() |>
add_difference(adj.vars = c(grade, stage))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.