Skip to contents

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,
  missing_text = NULL,
  overall_string = NULL,
  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,
  missing_text = NULL,
  overall_string = NULL,
  set_theme = TRUE
)

theme_gtsummary_bold_labels(set_theme = TRUE)

Arguments

prop_stat

(character)
Statistics to display for categorical variables (see gtsummary::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 in gtsummary::tbl_summary(). Default is FALSE.

cont_digits

(non-negative integer)
Define the number of decimals to display for continuous variables.

missing_text

(character)
String indicating text shown on missing row.

overall_string

(character)
Optional string to name the overall column.

set_theme

(scalar logical)
Logical indicating whether to set the theme. Default is TRUE. When FALSE the 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.

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 = 98
1
Drug B
N = 102
1
p-value2
Grade

0.9
    I 35 (36%) 33 (32%)
    II 32 (33%) 36 (35%)
    III 31 (32%) 33 (32%)
Age 46 (37, 60) 48 (39, 56) 0.7
    Unknown 7 4
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 = 98
1
Drug B
N = 102
1
p-value2
Grade

>0.9
    I 35.7% (35) 32.4% (33)
    II 32.7% (32) 35.3% (36)
    III 31.6% (31) 32.4% (33)
Age 47.0 (14.7) 47.4 (14.0) 0.8
    Unknown 7 4
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(awards, target), by = stype) |> add_overall() |> add_p()
Characteristic Overall
N = 6,194
1
E
N = 4,421
1
H
N = 755
1
M
N = 1,018
1
p-value2
awards 63.9% (3,958) 73.0% (3,227) 32.0% (242) 48.0% (489) <0.001
target 10.0 (5.4) 9.9 (5.6) 9.9 (5.1) 10.3 (5.2) 0.9
    Unknown 725 619 45 61
1 % (n); Mean (SD)
2 Pearson’s X^2: Rao & Scott adjustment; Design-based KruskalWallis test
theme_gtsummary_unweighted_n() apistrat |> srvyr::as_survey(strata = stype, weights = pw) |> tbl_svysummary(include = c(awards, target), by = stype) |> add_overall() |> add_p()
Characteristic Overall (200 obs.)1 E (100 obs.)1 H (50 obs.)1 M (50 obs.)1 p-value2
awards 63.9% (113 obs.) 73.0% (73 obs.) 32.0% (16 obs.) 48.0% (24 obs.) <0.001
target 10.0 (6.0, 14.0) 10.0 (6.0, 14.0) 9.0 (6.0, 14.0) 10.0 (6.0, 15.0) 0.9
    Unknown 20 obs. 14 obs. 3 obs. 3 obs.
1 % (n (unweighted) obs.); Median (Q1, Q3)
2 Pearson’s X^2: Rao & Scott adjustment; Design-based KruskalWallis test
theme_gtsummary_unweighted_n(mean_sd = TRUE) apistrat |> srvyr::as_survey(strata = stype, weights = pw) |> tbl_svysummary(include = c(awards, target), by = stype) |> add_overall() |> add_p()
Characteristic Overall (200 obs.)1 E (100 obs.)1 H (50 obs.)1 M (50 obs.)1 p-value2
awards 63.9% (113 obs.) 73.0% (73 obs.) 32.0% (16 obs.) 48.0% (24 obs.) <0.001
target 10.0 (5.4) 9.9 (5.6) 9.9 (5.1) 10.3 (5.2) >0.9
    Unknown 20 obs. 14 obs. 3 obs. 3 obs.
1 % (n (unweighted) obs.); Mean (SD)
2 Pearson’s X^2: Rao & Scott adjustment; Design-based one-way analysis of means
# } gtsummary::reset_gtsummary_theme()