the prevalence package
tools for prevalence assessment studies.

## Calculate confidence intervals for prevalences and other proportions

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

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.

"agresti.coull", "agresti-coull", "ac"

$\tilde{n} = n + z_{1-\frac{\alpha}{2}}^2$ $\tilde{p} = \frac{1}{\tilde{n}}(x + \frac{1}{2} z_{1-\frac{\alpha}{2}}^2)$ $\tilde{p} \pm z_{1-\frac{\alpha}{2}} \sqrt{\frac{\tilde{p}(1-\tilde{p})}{\tilde{n}}}$

"exact", "clopper-pearson", "cp"

$(Beta(\frac{\alpha}{2}; x, n - x + 1), Beta(1 - \frac{\alpha}{2}; x + 1, n - x))$

"jeffreys", "bayes"

$(Beta(\frac{\alpha}{2}; x + 0.5, n - x + 0.5), Beta(1 - \frac{\alpha}{2}; x + 0.5, n - x + 0.5))$

"wald", "asymptotic", "normal"

$p \pm z_{1-\frac{\alpha}{2}} \sqrt{\frac{p(1-p)}{n}}$

"wilson"

$\frac{p + \frac{z_{1-\frac{\alpha}{2}}^2}{2n} \pm z_{1-\frac{\alpha}{2}} \sqrt{\frac{p(1-p)}{n} + \frac{z_{1-\frac{\alpha}{2}}^2}{4n^2}}}{1 + \frac{z_{1-\frac{\alpha}{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.

### Examples

## All methods, 95% confidence intervals
propCI(x = 142, n = 742)
#>     x   n         p        method level     lower     upper
#> 1 142 742 0.1913747 agresti.coull  0.95 0.1646432 0.2212853
#> 2 142 742 0.1913747         exact  0.95 0.1636684 0.2215588
#> 3 142 742 0.1913747      jeffreys  0.95 0.1643017 0.2208498
#> 4 142 742 0.1913747          wald  0.95 0.1630697 0.2196796
#> 5 142 742 0.1913747        wilson  0.95 0.1646876 0.2212409
## Wald-type 90%, 95% and 99% confidence intervals
propCI(x = 142, n = 742, method = "wald", level = c(0.90, 0.95, 0.99))
#>     x   n         p method level     lower     upper
#> 1 142 742 0.1913747   wald  0.90 0.1676204 0.2151289
#> 2 142 742 0.1913747   wald  0.95 0.1630697 0.2196796
#> 3 142 742 0.1913747   wald  0.99 0.1541757 0.2285736