Additional themes for tables generated with gtsummary.
Usage
theme_gtsummary_prop_n(
prop_stat = "{p}% ({n})",
prop_digits = 1,
mean_sd = FALSE,
cont_digits = 1,
set_theme = TRUE
)
theme_gtsummary_fisher_simulate_p(set_theme = TRUE)
theme_gtsummary_unweighted_n(
n_unweighted_prefix = "",
n_unweighted_suffix = " obs.",
prop_digits = 1,
mean_sd = FALSE,
cont_digits = 1,
overall_string = NULL,
set_theme = TRUE
)
theme_gtsummary_bold_labels(set_theme = TRUE)Arguments
- prop_stat
(
character)
Statistics to display for categorical variables (seegtsummary::tbl_summary()).- prop_digits
(non-negative
integer)
Define the number of decimals to display for proportions.- mean_sd
(scalar
logical)
Also, set default summary statistics to mean and standard deviation ingtsummary::tbl_summary(). Default isFALSE.- cont_digits
(non-negative
integer)
Define the number of decimals to display for continuous variables.- set_theme
(scalar
logical)
Logical indicating whether to set the theme. Default isTRUE. WhenFALSEthe named list of theme elements is returned invisibly- n_unweighted_prefix, n_unweighted_suffix
(
character)
Prefix and suffix displayed before and after the unweighted number of observations.- overall_string
(
character)
Optional string to name the overall column.
Details
theme_gtsummary_prop_n() displays, by default, proportions before the
number of observations (between brackets). This function cannot be used
simultaneously with gtsummary::theme_gtsummary_mean_sd(), but you can use
the mean_sd = TRUE option of theme_gtsummary_prop_n().
theme_gtsummary_prop_n() also modifies default method for
gtsummary::add_ci.tbl_summary() ("wilson" for categorical variables,
"t.test", i.e. mean confidence interval, for continuous variables if
mean_sd = TRUE, "wilcox.test", i.e. confidence interval of the
pseudomedian, for continuous variables if mean_sd = FALSE).
Finally, theme_gtsummary_prop_n() also modifies default tests for
gtsummary::add_p.tbl_summary() for continuous variables if
mean_sd = TRUE ("t.test" for comparing 2 groups, or "oneway.test" for
3 groups or more). If mean_sd = FALSE, the default tests for continuous
variables remain "wilcox.test" (2 groups) or "kruskal.test" (3 groups
or more). For categorical variables, "chisq.test.no.correct" and
"fisher.test" are used by default.
See theme_gtsummary_fisher_simulate_p() to change the default test for
categorical variables.
theme_gtsummary_fisher_simulate_p() modify the default test used for
categorical variables by Fisher test, with computation of p-values by
Monte Carlo simulation in larger than 2×2 tables.
theme_gtsummary_unweighted_n() modifies default values of tables returned
by gtsummary::tbl_svysummary() and displays the unweighted number of
observations instead of the weighted n.
theme_gtsummary_unweighted_n() also modifies default method for
gtsummary::add_ci.tbl_svysummary() ("svyprop.logit" for categorical
variables, "svymean", i.e. mean confidence interval, for continuous
variables if mean_sd = TRUE, "svymedian.mean", i.e. confidence interval
of the median, for continuous variables if mean_sd = FALSE).
Finally, theme_gtsummary_unweighted_n() also modifies default tests for
gtsummary::add_p.tbl_svysummary() for continuous variables if
mean_sd = TRUE (svyttest_oneway which calls survey::svyttest() for
comparing 2 means and svyoneway() for comparing 3 means or more).
If mean_sd = FALSE, the default tests for continuous
variables remain "svy.wilcox.test" which used a designed-based Wilcoxon
test (2 groups) or Kruskal-Wallis test (3 groups or more). For categorical
variables, "svy.chisq.test"is used by default.
theme_gtsummary_bold_labels() applies automatically
gtsummary::bold_labels() to all tables generated with gtsummary.
Examples
# \donttest{
library(gtsummary)
trial |>
tbl_summary(include = c(grade, age), by = trt) |>
add_p()
Characteristic
Drug A
N = 981
Drug B
N = 1021
p-value2
1 n (%); Median (Q1, Q3)
2 Pearson’s Chi-squared test; Wilcoxon rank sum test
theme_gtsummary_prop_n(mean_sd = TRUE)
theme_gtsummary_fisher_simulate_p()
theme_gtsummary_bold_labels()
trial |>
tbl_summary(include = c(grade, age), by = trt) |>
add_p()
Characteristic
Drug A
N = 981
Drug B
N = 1021
p-value2
1 % (n); Mean (SD)
2 Fisher’s Exact Test for Count Data with simulated p-value
(based on 2000 replicates); Welch Two Sample t-test
# }
# \donttest{
data("api", package = "survey")
apistrat$both[1:5] <- NA
apistrat |>
srvyr::as_survey(strata = stype, weights = pw) |>
tbl_svysummary(include = c(stype, both), by = awards) |>
add_overall()
Characteristic
Overall
N = 6,1941
No
N = 2,2361
Yes
N = 3,9581
1 % (n)
theme_gtsummary_unweighted_n()
apistrat |>
srvyr::as_survey(strata = stype, weights = pw) |>
tbl_svysummary(include = c(stype, both), by = awards) |>
add_overall()
Characteristic
Overall
(200 obs.)1
No
(87 obs.)1
Yes
(113 obs.)1
1 % (n (unweighted) obs.)
# }
gtsummary::reset_gtsummary_theme()