Last chance! 50% off unlimited learning
Sale ends in
maturing Build a stratified gtsummary table. Any gtsummary table that accepts a data frame as its first argument can be stratified.
In tbl_strata()
, the stratified or subset data frame is passed to the
function in .tbl_fun=
, e.g. purrr::map(data, .tbl_fun)
.
In tbl_strata2()
, both the stratified data frame and the strata level
are passed to .tbl_fun=
, e.g. purrr::map2(data, strata, .tbl_fun)
tbl_strata(
data,
strata,
.tbl_fun,
...,
.sep = ", ",
.combine_with = c("tbl_merge", "tbl_stack"),
.combine_args = NULL,
.header = ifelse(.combine_with == "tbl_merge", "**{strata}**", "{strata}"),
.stack_group_header = NULL,
.quiet = NULL
)tbl_strata2(
data,
strata,
.tbl_fun,
...,
.sep = ", ",
.combine_with = c("tbl_merge", "tbl_stack"),
.combine_args = NULL,
.header = ifelse(.combine_with == "tbl_merge", "**{strata}**", "{strata}"),
.stack_group_header = NULL,
.quiet = NULL
)
a data frame or survey object
character vector or tidy-selector of columns in data to stratify results by
A function or formula. If a function, it is used as is.
If a formula, e.g. ~ .x %>% tbl_summary() %>% add_p()
, it is converted to a function.
The stratified data frame is passed to this function.
Additional arguments passed on to the .tbl_fun
function.
when more than one stratifying variable is passed, this string is
used to separate the levels in the spanning header. Default is ", "
One of c("tbl_merge", "tbl_stack")
. Names the function
used to combine the stratified tables.
named list of arguments that are passed to function
specified in .combine_with=
String indicating the headers that will be placed.
Default is "**{strata}**"
when .combine_with = "tbl_merge"
and
"{strata}"
when .combine_with = "tbl_stack"
. Items placed in
curly brackets will be evaluated according to glue::glue()
syntax.
strata
stratum levels
n
N within stratum
N
Overall N
The evaluated value of .header=
is also available within tbl_strata2(.tbl_fun=)
DEPRECATED.
Logical indicating whether to print messages in console.
Default is FALSE
tbl_summary()
The number of digits continuous variables are rounded to is determined
separately within each stratum of the data frame. Set the digits=
argument to ensure continuous variables are rounded to the same number
of decimal places.
If some levels of a categorical variable are unobserved within a stratum, convert the variable to a factor to ensure all levels appear in each stratum's summary table.
Example 1
Example 2
Other tbl_regression tools:
add_global_p()
,
add_q()
,
bold_italicize_labels_levels
,
combine_terms()
,
inline_text.tbl_regression()
,
modify
,
tbl_merge()
,
tbl_regression()
,
tbl_split()
,
tbl_stack()
Other tbl_uvregression tools:
add_global_p()
,
add_q()
,
bold_italicize_labels_levels
,
inline_text.tbl_uvregression()
,
modify
,
tbl_merge()
,
tbl_split()
,
tbl_stack()
,
tbl_uvregression()
Other tbl_summary tools:
add_ci()
,
add_n.tbl_summary()
,
add_overall()
,
add_p.tbl_summary()
,
add_q()
,
add_stat_label()
,
bold_italicize_labels_levels
,
inline_text.tbl_summary()
,
inline_text.tbl_survfit()
,
modify
,
separate_p_footnotes()
,
tbl_custom_summary()
,
tbl_merge()
,
tbl_split()
,
tbl_stack()
,
tbl_summary()
Other tbl_survfit tools:
add_n.tbl_survfit()
,
add_nevent.tbl_survfit()
,
add_p.tbl_survfit()
,
modify
,
tbl_merge()
,
tbl_split()
,
tbl_stack()
,
tbl_survfit()
Other tbl_svysummary tools:
add_n.tbl_summary()
,
add_overall()
,
add_p.tbl_svysummary()
,
add_q()
,
add_stat_label()
,
modify
,
separate_p_footnotes()
,
tbl_merge()
,
tbl_split()
,
tbl_stack()
,
tbl_svysummary()
# NOT RUN {
# Example 1 ----------------------------------
tbl_strata_ex1 <-
trial %>%
select(age, grade, stage, trt) %>%
mutate(grade = paste("Grade", grade)) %>%
tbl_strata(
strata = grade,
.tbl_fun =
~ .x %>%
tbl_summary(by = trt, missing = "no") %>%
add_n(),
.header = "**{strata}**, N = {n}"
)
# Example 2 ----------------------------------
tbl_strata_ex2 <-
trial %>%
select(grade, response) %>%
mutate(grade = paste("Grade", grade)) %>%
tbl_strata2(
strata = grade,
.tbl_fun =
~.x %>%
tbl_summary(
label = list(response = .y),
missing = "no",
statistic = response ~ "{p}%"
) %>%
add_ci(pattern = "{stat} ({ci})") %>%
modify_header(stat_0 = "**Rate (95% CI)**") %>%
modify_footnote(stat_0 = NA),
.combine_with = "tbl_stack",
.combine_args = list(group_header = NULL),
.quiet = TRUE
) %>%
modify_caption("**Response Rate by Grade**")
# }
Run the code above in your browser using DataLab