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_add_4(x, n, conf.level = 0.95)
A vector with the lower and upper limits of the confidence interval.
The Add-4 Wald-t confidence interval improves the performance of the Wald interval by adding 2 successes and 2 failures to the observed data, effectively modifying the estimated proportion:
$$\hat{p}=\frac{x + 2}{n + 4}.$$
The variance \(V(\hat{p}, n+4)\) is given by:
$$V(\hat{p}, n+4)=\frac{\hat{p}(1 - \hat{p})}{n + 4}.$$
The degrees of freedom \(\nu\) are calculated using equation (2.9):
$$\nu=\frac{2 V(\hat{p}, n+4)^2}{\Omega(\hat{p}, n+4)},$$
where \(\Omega(\hat{p}, n+4)\) is defined as:
$$\Omega(p, n)=\frac{p - p^2}{n^3} + \frac{p + (6n - 7)p^2 + 4(n - 1)(n - 3)p^3 - 2(n - 1)(2n - 3)p^4}{n^5} - \frac{2(p + (2n - 3)p^2 - 2(n - 1)p^3)}{n^4}.$$
The confidence interval is then calculated as:
$$\text{Lower}=\hat{p} - t \cdot \sqrt{\frac{\tilde{\pi}(1 - \hat{p})}{n+4}},$$ $$\text{Upper}=\hat{p} + t \cdot \sqrt{\frac{\tilde{\pi}(1 - \hat{p})}{n+4}},$$
where \(t\) is the critical value from the t-distribution with \(\nu\) degrees of freedom.
Pan, W. (2002). Approximate confidence intervals for one proportion and difference of two proportions. Computational Statistics and Data Analysis, 40(1), 143–157
ci_p.
ci_p_add_4(x=15, n=50, conf.level=0.95)
#> [,1]
#> [1,] 0.1900327
#> [2,] 0.4395970
ci_p_add_4(x=0, n=50, conf.level=0.95)
#> [,1]
#> [1,] 0.0000000
#> [2,] 0.1045923
ci_p_add_4(x=50, n=50, conf.level=0.95)
#> [,1]
#> [1,] 0.8954077
#> [2,] 1.0000000