ci_proportion {confintr} | R Documentation |
This function calculates confidence intervals for a population proportion. By default, "Clopper-Pearson" confidence intervals are calculated (via stats::binom.test
). Further possibilities are "Wilson", "Agresti-Coull", and "bootstrap" (mainly added for consistency and didactic purposes).
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 = 9999, seed = NULL, ... )
x |
A numeric vector of 0 and 1 or the number of successes. |
n |
The sample size. Only needed if |
probs |
Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confidence interval. |
type |
Type of confidence interval. One of "Clopper-Pearson" (the default), "Agrestiâ€“Coull", "Wilson", "bootstrap". |
boot_type |
Type of bootstrap confidence interval ("bca", "perc", "stud", "norm", "basic"). Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
Bootstrap confidence intervals are calculated by the package "boot", see references. The default bootstrap type for the proportion is "bca" (bias-corrected accelerated) as it enjoys the property of being second order accurate as well as transformation respecting (see Efron, p. 188). Note that we use the formula in https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval which does not simplify the 0.975 quantile of the normal by 2 as sometimes in other references.
A list with class cint
containing these components:
parameter
: The parameter in question.
interval
: The confidence interval for the parameter.
estimate
: The estimate for the parameter.
probs
: A vector of error probabilities.
type
: The type of the interval.
info
: An additional description text for the interval.
Clopper, C. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika. 26 (4).
Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, 22 (158).
Agresti, A. and Coull, B. A. (1998). Approximate is better than 'exact' for interval estimation of binomial proportions. The American Statistician, 52 (2).
Efron, B. and Tibshirani R. J. (1994). An Introduction to the Bootstrap. Chapman & Hall/CRC.
Canty, A and Ripley B. (2019). boot: Bootstrap R (S-Plus) Functions.
x <- rep(0:1, times = c(50, 100)) ci_proportion(x) ci_proportion(x, type = "Wilson") ci_proportion(x, type = "Agresti-Coull") ci_proportion(x, type = "bootstrap", R = 999)