Calculate confidence intervals for prevalences and other proportions

Share:

Description

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

Usage

1
propCI(x, n, method = "all", level = 0.95, sortby = "level")

Arguments

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 "level" or "method"

Details

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}}

Value

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

Note

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.

Author(s)

Brecht Devleesschauwer <brechtdv@gmail.com>

Examples

1
2
3
4
5
## 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))