This function replaces the counts in the default header of
gtsummary::tbl_svysummary() tables to counts representing the
Effective Sample Size (ESS). See ess() for details.
Arguments
- x
(
tbl_svysummary)
Object of class'tbl_svysummary'typically created withgtsummary::tbl_svysummary().- header
(
string)
String specifying updated header. Reviewgtsummary::modify_header()for details on use.
Details
The header statistics available to header are the ESS of the column (n),
the total the columns are a share of (N), and that share (p). ESS is not
additive, so the ESS of the whole sample is not the total that the group ESS
values divide up. For a table with a
gtsummary::tbl_svysummary(by =) variable, N is therefore the sum of the
group ESS values and p is each group's share of that sum, whether or not
the table also has an overall column from gtsummary::add_overall(). The
overall column reports the ESS of the whole sample as both n and N, so
its p is 1.
Examples
svy <- survey::svydesign(~1, data = nhefs_weights, weights = ~ w_ate)
gtsummary::tbl_svysummary(svy, include = c(age, sex, smokeyrs)) |>
add_ess_header()
Characteristic
Overall
ESS = 1013.31
1 Median (Q1, Q3); n (%)
Abbreviation: ESS = Effective Sample Size
hdr <- paste0(
"**{level}** \n",
"N = {n_unweighted}; ESS = {format(n, digits = 1, nsmall = 1)}"
)
gtsummary::tbl_svysummary(svy, by = qsmk, include = c(age, sex, smokeyrs)) |>
add_ess_header(header = hdr)
Characteristic
0
N = 1163; ESS = 1128.61
1
N = 403; ESS = 326.01
1 Median (Q1, Q3); n (%)
Abbreviation: ESS = Effective Sample Size
