ci_p_add_4 | R Documentation |
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)
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, it is 0.95. |
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.
A vector with the lower and upper limits of the confidence interval.
David Esteban Cartagena Mejía, dcartagena@unal.edu.co
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)
ci_p_add_4(x=0, n=50, conf.level=0.95)
ci_p_add_4(x=50, n=50, conf.level=0.95)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.