Skip to contents

[Experimental]
Calculate confidence intervals for proportions.

Usage

ard_categorical_ci(data, ...)

# S3 method for data.frame
ard_categorical_ci(
  data,
  variables,
  by = dplyr::group_vars(data),
  method = c("waldcc", "wald", "clopper-pearson", "wilson", "wilsoncc", "strat_wilson",
    "strat_wilsoncc", "agresti-coull", "jeffreys"),
  conf.level = 0.95,
  value = list(where(is_binary) ~ 1L, where(is.logical) ~ TRUE),
  strata = NULL,
  weights = NULL,
  max.iterations = 10,
  ...
)

Arguments

data

(data.frame)
a data frame

...

Arguments passed to methods.

variables

(tidy-select)
columns to include in summaries. Columns must be class <logical> or <numeric> values coded as c(0, 1).

by

(tidy-select)
columns to stratify calculations by

method

(string)
string indicating the type of confidence interval to calculate. Must be one of . See ?proportion_ci for details.

conf.level

(numeric)
a scalar in (0, 1) indicating the confidence level. Default is 0.95

value

(formula-list-selector)
function will calculate the CIs for all levels of the variables specified. Use this argument to instead request only a single level by summarized. Default is list(where(is_binary) ~ 1L, where(is.logical) ~ TRUE), where columns coded as 0/1 and TRUE/FALSE will summarize the 1 and TRUE levels.

strata, weights, max.iterations

arguments passed to proportion_ci_strat_wilson(), when method='strat_wilson'

Value

an ARD data frame

Examples

# compute CI for binary variables
ard_categorical_ci(mtcars, variables = c(vs, am), method = "wilson")
#> {cards} data frame: 20 x 9
#>    variable variable_level   context   stat_name stat_label      stat
#> 1        vs              1 proporti…           N          N        32
#> 2        vs              1 proporti…  conf.level  conf.lev…      0.95
#> 3        vs              1 proporti…    estimate   estimate     0.438
#> 4        vs              1 proporti…   statistic  statistic       0.5
#> 5        vs              1 proporti…     p.value    p.value      0.48
#> 6        vs              1 proporti…   parameter  parameter         1
#> 7        vs              1 proporti…    conf.low   conf.low     0.282
#> 8        vs              1 proporti…   conf.high  conf.high     0.607
#> 9        vs              1 proporti…      method     method Wilson C…
#> 10       vs              1 proporti… alternative  alternat… two.sided
#> 11       am              1 proporti…           N          N        32
#> 12       am              1 proporti…  conf.level  conf.lev…      0.95
#> 13       am              1 proporti…    estimate   estimate     0.406
#> 14       am              1 proporti…   statistic  statistic     1.125
#> 15       am              1 proporti…     p.value    p.value     0.289
#> 16       am              1 proporti…   parameter  parameter         1
#> 17       am              1 proporti…    conf.low   conf.low     0.255
#> 18       am              1 proporti…   conf.high  conf.high     0.577
#> 19       am              1 proporti…      method     method Wilson C…
#> 20       am              1 proporti… alternative  alternat… two.sided
#>  3 more variables: fmt_fn, warning, error

# compute CIs for each level of a categorical variable
ard_categorical_ci(mtcars, variables = cyl, method = "jeffreys")
#> {cards} data frame: 18 x 9
#>    variable variable_level   context  stat_name stat_label      stat
#> 1       cyl              4 proporti…          N          N        32
#> 2       cyl              4 proporti…   estimate   estimate     0.344
#> 3       cyl              4 proporti…   conf.low   conf.low     0.198
#> 4       cyl              4 proporti…  conf.high  conf.high     0.516
#> 5       cyl              4 proporti… conf.level  conf.lev…      0.95
#> 6       cyl              4 proporti…     method     method Jeffreys…
#> 7       cyl              6 proporti…          N          N        32
#> 8       cyl              6 proporti…   estimate   estimate     0.219
#> 9       cyl              6 proporti…   conf.low   conf.low     0.104
#> 10      cyl              6 proporti…  conf.high  conf.high     0.382
#> 11      cyl              6 proporti… conf.level  conf.lev…      0.95
#> 12      cyl              6 proporti…     method     method Jeffreys…
#> 13      cyl              8 proporti…          N          N        32
#> 14      cyl              8 proporti…   estimate   estimate     0.438
#> 15      cyl              8 proporti…   conf.low   conf.low     0.277
#> 16      cyl              8 proporti…  conf.high  conf.high     0.609
#> 17      cyl              8 proporti… conf.level  conf.lev…      0.95
#> 18      cyl              8 proporti…     method     method Jeffreys…
#>  3 more variables: fmt_fn, warning, error