ci_p_clopper_pearson: Clopper-Pearson confidence interval for Binomial proportion

View source: R/ci_p_xxx.R

ci_p_clopper_pearsonR Documentation

Clopper-Pearson confidence interval for Binomial proportion

Description

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

Usage

ci_p_clopper_pearson(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, it is 0.95.

Details

The Clopper-Pearson interval is an exact confidence interval for the Binomial proportion p. The limits of the interval are derived based on the Beta distribution. For the special cases where x=0 or x=n, the limits are calculated directly.

The mathematical definitions are as follows:

- If x=0, the lower limit is 0, and the upper limit is 1 - (\alpha / 2)^{1/n}.

- If x=n, the lower limit is (\alpha / 2)^{1/n}, and the upper limit is 1.

Otherwise, the limits are given by:

\text{Lower Limit}=B_{1-\alpha/2, x, n-x+1}

\text{Upper Limit}=B_{\alpha/2, x+1, n-x}

where B_{\omega, a, b} is the 100\%(1-\omega) percentile of the Beta distribution with parameters a and b.

Due to the relationship between Beta and F distributions, the limits can be written as:

\text{Lower Limit}=\frac{1}{1+\frac{n-x+1}{x}F_{\alpha/2, \, 2(n-x+1), \, 2x}}

\text{Upper Limit}=\frac{\frac{x+1}{n-x} F_{\alpha/2, \, 2(x+1), \, 2(n-x)}}{1+\frac{x+1}{n-x} F_{\alpha/2, \, 2(x+1), \, 2(n-x)}}

where F_{\omega, a, b} is the 100\%(1-\omega) percentile of the F distribution with parameters a and b.

Value

A vector with the lower and upper limits.

Author(s)

Omar David Mercado Turizo, omercado@unal.edu.co

References

Clopper, C. J., & Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26(4), 404-413.

See Also

ci_p.

Examples

ci_p_clopper_pearson(x=15, n=50, conf.level=0.95)


fhernanb/stests documentation built on March 29, 2025, 10:36 a.m.