propCI | R Documentation |
The propCI
function calculates five types of confidence intervals for proportions:
Wald interval (= Normal approximation interval, asymptotic interval)
Agresti-Coull interval (= adjusted Wald interval)
Exact interval (= Clopper-Pearson interval)
Jeffreys interval (= Bayesian interval)
Wilson score interval
propCI(x, n, method = "all", level = 0.95, sortby = "level")
x |
Number of successes (positive samples) |
n |
Number of trials (sample size) |
method |
Confidence interval calculation method; see details |
level |
Confidence level for confidence intervals |
sortby |
Sort results by |
Five methods are available for calculating confidence intervals. For convenience, synonyms are allowed. Please refer to the PDF version of the manual for proper formatting of the below formulas.
"agresti.coull", "agresti-coull", "ac"
\tilde{n} = n + z_{1-\frac{α}{2}}^2
\tilde{p} = \frac{1}{\tilde{n}}(x + \frac{1}{2} z_{1-\frac{α}{2}}^2)
\tilde{p} \pm z_{1-\frac{α}{2}} √{\frac{\tilde{p}(1-\tilde{p})}{\tilde{n}}}
"exact", "clopper-pearson", "cp"
(Beta(\frac{α}{2}; x, n - x + 1), Beta(1 - \frac{α}{2}; x + 1, n - x))
"jeffreys", "bayes"
(Beta(\frac{α}{2}; x + 0.5, n - x + 0.5), Beta(1 - \frac{α}{2}; x + 0.5, n - x + 0.5))
"wald", "asymptotic", "normal"
p \pm z_{1-\frac{α}{2}} √{\frac{p(1-p)}{n}}
"wilson"
\frac{p + \frac{z_{1-\frac{α}{2}}^2}{2n} \pm z_{1-\frac{α}{2}} √{\frac{p(1-p)}{n} + \frac{z_{1-\frac{α}{2}}^2}{4n^2}}} {1 + \frac{z_{1-\frac{α}{2}}^2}{n}}
Data frame with seven columns:
x |
Number of successes (positive samples) |
n |
Number of trials (sample size) |
p |
Proportion of successes (prevalence) |
method |
Confidence interval calculation method |
level |
Confidence level |
lower |
Lower confidence limit |
upper |
Upper confidence limit |
In case the observed prevalence equals 0% (ie, x == 0
), an upper one-sided confidence interval is returned.
In case the observed prevalence equals 100% (ie, x == n
), a lower one-sided confidence interval is returned.
In all other cases, two-sided confidence intervals are returned.
Brecht Devleesschauwer <brechtdv@gmail.com>
## All methods, 95% confidence intervals propCI(x = 142, n = 742) ## Wald-type 90%, 95% and 99% confidence intervals propCI(x = 142, n = 742, method = "wald", level = c(0.90, 0.95, 0.99))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.