Add a new column with the confidence intervals for proportions, means, etc.
add_ci(x, ...)# S3 method for tbl_summary
add_ci(
x,
method = NULL,
include = everything(),
statistic = NULL,
conf.level = 0.95,
style_fun = NULL,
pattern = NULL,
...
)
gtsummary table
A tbl_summary
object
Not used
Confidence interval method. Default is
list(all_categorical() ~ "wilson", all_continuous() ~ "t.test")
.
Must be one of
c("wilson", "wilson.no.correct", "exact", "asymptotic")
for categorical
variables, and c("t.test", "wilcox.test")
for continuous variables.
See details below.
variables to include in the summary table. Default is everything()
Formula indicating how the confidence interval will be displayed.
Default is list(all_categorical() ~ "{conf.low}%, {conf.high}%", all_continuous() ~ "{conf.low}, {conf.high}")
Confidence level. Default is 0.95
Function to style upper and lower bound of confidence
interval. Default is
list(all_categorical() ~ purrr::partial(style_sigfig, scale = 100), all_continuous() ~ style_sigfig)
.
string indicating the pattern to use to merge the CI with
the statistics cell. The default is NULL, where no columns are merged.
The two columns that will be merged are the statistics column,
represented by "{stat}"
and the CI column represented by "{ci}"
,
e.g. pattern = "{stat} ({ci})"
will merge the two columns with the CI
in parentheses.
Methods c("wilson", "wilson.no.correct")
are calculated with
prop.test(correct = c(TRUE, FALSE))
.
The default method, "wilson"
, includes the Yates continuity correction.
Methods c("exact", "asymptotic")
are calculated with Hmisc::binconf(method=)
.
Confidence intervals for means are calculated using t.test()
and
wilcox.test()
for pseudo-medians.
Example 1
Example 2
Review list, formula, and selector syntax used throughout gtsummary
Other tbl_summary tools:
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_strata()
,
tbl_summary()
# \donttest{
# Example 1 ----------------------------------
add_ci_ex1 <-
trial %>%
select(marker, response, trt) %>%
tbl_summary(missing = "no",
statistic = all_continuous() ~ "{mean} ({sd})") %>%
add_ci()
# Example 2 ----------------------------------
add_ci_ex2 <-
trial %>%
select(response, grade) %>%
tbl_summary(statistic = all_categorical() ~ "{p}%",
missing = "no") %>%
add_ci(pattern = "{stat} ({ci})") %>%
modify_footnote(everything() ~ NA)
# }
Run the code above in your browser using DataLab