ci_proportion: CI for a Population Proportion

View source: R/ci_proportion.R

ci_proportionR Documentation

CI for a Population Proportion

Description

This function calculates CIs for a population proportion. By default, "Clopper-Pearson" CIs are calculated (via stats::binom.test()). Further possibilities are "Wilson" (without continuity correction), "Agresti-Coull" (using normal quantile instead of +2 correction), and "bootstrap" (by default "bca").

Usage

ci_proportion(
  x,
  n = NULL,
  probs = c(0.025, 0.975),
  type = c("Clopper-Pearson", "Agresti-Coull", "Wilson", "bootstrap"),
  boot_type = c("bca", "perc", "stud", "norm", "basic"),
  R = 9999L,
  seed = NULL,
  ...
)

Arguments

x

A numeric vector with one value (0/1) per observation, or the number of successes.

n

The sample size. Only needed if x is a vector of length 1.

probs

Lower and upper probabilities, by default c(0.025, 0.975).

type

Type of CI. One of "Clopper-Pearson" (the default), "Agresti–Coull", "Wilson", "bootstrap".

boot_type

Type of bootstrap CI. Only used for type = "bootstrap".

R

The number of bootstrap resamples. Only used for type = "bootstrap".

seed

An integer random seed. Only used for type = "bootstrap".

...

Further arguments passed to boot::boot().

Details

Note that we use the formulas for the Wilson and Agresti-Coull intervals in https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval. They agree with binom::binom.confint(x, n, method = "ac"/"wilson").

Value

An object of class "cint", see ci_mean() for details.

References

  1. Clopper, C. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika. 26 (4).

  2. Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, 22 (158).

  3. Agresti, A. and Coull, B. A. (1998). Approximate is better than 'exact' for interval estimation of binomial proportions. The American Statistician, 52 (2).

Examples

x <- rep(0:1, times = c(50, 100))
ci_proportion(x)
ci_proportion(x, type = "Wilson")
ci_proportion(x, type = "Agresti-Coull")

confintr documentation built on June 7, 2023, 6:24 p.m.