Skip to contents

Wilson confidence interval of a proportion

Usage

wilson_interval(x, n, conf = 0.95)

Arguments

x

Integer. Number of successes (correct items, matches...).

n

Integer. Number of trials.

conf

Number. Confidence level.

Value

A data.table with x, n, estimate, lower, upper.

Details

The Wilson interval behaves well for small samples and proportions close to 0 or 1, where the usual normal interval goes below 0 or above 1. With \(\hat p = x/n\) and \(z\) the normal quantile, $$\frac{\hat p + \frac{z^2}{2n} \pm z\sqrt{\frac{\hat p(1-\hat p)}{n} + \frac{z^2}{4n^2}}}{1 + \frac{z^2}{n}}.$$

References

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

Examples

wilson_interval(c(45, 98), c(50, 100))
#>        x     n estimate     lower     upper
#>    <num> <num>    <num>     <num>     <num>
#> 1:    45    50     0.90 0.7863977 0.9565242
#> 2:    98   100     0.98 0.9299882 0.9944980