This function calculates the confidence interval for a proportion. It is vectorized, allowing users to evaluate it using either single values or vectors.

ci_p_wilson(x, n, conf.level = 0.95)

Arguments

x

a number or a vector with the number of successes.

n

a number or a vector with the number of trials.

conf.level

confidence level for the returned confidence interval. By default is 0.95.

Value

A matrix with the lower and upper limits.

Details

The expression to obtain the confidence interval is given below:

\(\frac{\hat{p}+ \frac{z_{\alpha/2}^2}{2n}}{\widetilde{n}} \pm \frac{z_{\alpha/2}^2}{\widetilde{n}} \sqrt{ (\hat{p}(1 - \hat{p}) + \frac{z_{\alpha/2}^2}{4n} )/n}\),

where \(\hat{p}=\frac{x}{n}\) is the sample proportion, \(\widetilde{n}=1 + \frac{ z_{\alpha/2}^2}{n}\), \(x\) the number of observed successes in the sample with size \(n\). The value \(z_{\alpha/2}\) is the \(1-\alpha/2\) percentile of the standard normal distribution (e.g., \(z_{0.025}=1.96\) for a 95% confidence interval).

References

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

See also

Author

Victor David Usuga, vusuga@unal.edu.co

Examples

ci_p_wilson(x= 0, n=50, conf.level=0.95)
#>              [,1]
#> [1,] 6.938894e-18
#> [2,] 7.134760e-02
ci_p_wilson(x=15, n=50, conf.level=0.95)
#>           [,1]
#> [1,] 0.1910355
#> [2,] 0.4375035
ci_p_wilson(x=50, n=50, conf.level=0.95)
#>           [,1]
#> [1,] 0.9286524
#> [2,] 1.0000000