proportion_summary {gtsummary} | R Documentation |
Summarize a proportion
Description
This helper, to be used with tbl_custom_summary()
, creates a function
computing a proportion and its confidence interval.
Usage
proportion_summary(
variable,
value,
weights = NULL,
na.rm = TRUE,
conf.level = 0.95,
method = c("wilson", "wilson.no.correct", "wald", "wald.no.correct", "exact",
"agresti.coull", "jeffreys")
)
Arguments
variable |
( |
value |
( |
weights |
( |
na.rm |
(scalar |
conf.level |
(scalar |
method |
( |
Details
Computed statistics:
-
{n}
numerator, number of observations equal tovalues
-
{N}
denominator, number of observations -
{prop}
proportion, i.e.n/N
-
{conf.low}
lower confidence interval -
{conf.high}
upper confidence interval
Methods c("wilson", "wilson.no.correct")
are calculated with
stats::prop.test()
(with correct = c(TRUE, FALSE)
). The default method,
"wilson"
, includes the Yates continuity correction.
Methods c("exact", "asymptotic")
are calculated with Hmisc::binconf()
and the corresponding method.
Author(s)
Joseph Larmarange
Examples
# Example 1 ----------------------------------
Titanic |>
as.data.frame() |>
tbl_custom_summary(
include = c("Age", "Class"),
by = "Sex",
stat_fns = ~ proportion_summary("Survived", "Yes", weights = "Freq"),
statistic = ~ "{prop}% ({n}/{N}) [{conf.low}-{conf.high}]",
digits = ~ list(
prop = label_style_percent(digits = 1),
n = 0,
N = 0,
conf.low = label_style_percent(),
conf.high = label_style_percent()
),
overall_row = TRUE,
overall_row_last = TRUE
) |>
bold_labels() |>
modify_footnote(all_stat_cols() ~ "Proportion (%) of survivors (n/N) [95% CI]")