add_ci | R Documentation |
Add a new column with the confidence intervals for proportions, means, etc.
add_ci(x, ...)
## S3 method for class 'tbl_summary'
add_ci(
x,
method = NULL,
include = everything(),
statistic = NULL,
conf.level = 0.95,
style_fun = NULL,
pattern = NULL,
df = NULL,
...
)
## S3 method for class 'tbl_svysummary'
add_ci(
x,
method = NULL,
include = everything(),
statistic = NULL,
conf.level = 0.95,
style_fun = NULL,
pattern = NULL,
df = NULL,
...
)
x |
A |
... |
Not used |
method |
Confidence interval method. Default is
|
include |
variables to include in the summary table. Default is |
statistic |
Formula indicating how the confidence interval will be displayed.
Default is |
conf.level |
Confidence level. Default is |
style_fun |
Function to style upper and lower bound of confidence
interval. Default is
|
pattern |
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 |
df |
For |
gtsummary table
for tbl_summary
tables
Must be one of
c("wilson", "wilson.no.correct", "exact", "asymptotic")
for categorical
variables, and c("t.test", "wilcox.test")
for continuous variables.
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.
for tbl_svysummary
tables
Must be one of
c("svyprop", "svyprop.logit", "svyprop.likelihood", "svyprop.asin", "svyprop.beta", "svyprop.mean", "svyprop.xlogit")
for categorical variables, and
c("svymean", "svymedian", "svymedian.mean", "svymedian.beta", "svymedian.xlogit", "svymedian.asin", "svymedian.score")
for continuous variables.
Confidence intervals for proportions are computed with survey::svyciprop()
.
See the help file of this function for details on the different methods
available to compute CIs. The default method "svyprop"
is equivalent
to "svyprop.logit"
, corresponding to a call to survey::svyciprop()
with
method = "logit"
.
Confidence intervals for means (method "svymean"
) are computed using
confint(svymean())
.
Confidence intervals for medians are computed with survey::svyquantile()
.
See the help file of this function for details on the different methods
available to compute CIs. The default method "svymedian"
is equivalent
to "svymedian.mean"
, corresponding to a call to surevy::svyquantile()
with method = "mean"
.
Example 1
Example 2
Example 3
Review list, formula, and selector syntax used throughout gtsummary
# 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)
# Example 3 ----------------------------------
data(api, package = "survey")
add_ci_ex3 <-
survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) %>%
tbl_svysummary(
include = c(api00, hsg, stype),
statistic = hsg ~ "{mean} ({sd})"
) %>%
add_ci(
method = api00 ~ "svymedian"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.