Package 'binomCI'

Title: Confidence Intervals for a Binomial Proportion
Description: Twelve confidence intervals for one binomial proportion or a vector of binomial proportions are computed. The confidence intervals are: Jeffreys, Wald, Wald corrected, Wald, Blyth and Still, Agresti and Coull, Wilson, Score, Score corrected, Wald logit, Wald logit corrected, Arcsine and Exact binomial. References include, among others: Vollset, S. E. (1993). "Confidence intervals for a binomial proportion". Statistics in Medicine, 12(9): 809-824. <doi:10.1002/sim.4780120902>.
Authors: Michail Tsagris [aut, cre]
Maintainer: Michail Tsagris <[email protected]>
License: GPL (>= 2)
Version: 1.2
Built: 2024-12-25 07:13:16 UTC
Source: CRAN

Help Index


Confidence Intervals for a Binomial Proportion.

Description

Functions to compute 12 confidence intervals for a binomial proportion.

Details

Package: binomCI
Type: Package
Version: 1.2
Date: 2024-11-25
License: GPL-2

Maintainers

Michail Tsagris [email protected].

Note

I would like to express my acknowledgements to Marc Girondot for spotting an error in the "Wilson" method in two extreme cases, when x=1x=1 and when nx=1n-x=1. He also proposed a modification that exists in the package "Hmisc" and the relevant paper to cite is Agresti & Coull (1998).

Author(s)

Michail Tsagris [email protected].

References

Agresti, A. & Caffo, B. (2000). Simple and effective confidence intervals for proportions and differences of proportions result from adding two successes and two failures. The American Statistician, 54(4), 280–288.

Agresti, A. & Coull, B. A. (1998). Approximate is better than "exact" for interval estimation of binomial proportions. The American Statistician, 52(2): 119–126.

Brown, L. D., Cai, T. T. & DasGupta, A. (2001). Interval estimation for a binomial proportion. Statistical Science, 16(2): 101-133.

Brown, L. D., Cai, T. T. & DasGupta, A. (2002). Confidence intervals for a binomial proportion and asymptotic expansions. The Annals of Statistics, 30(1): 160-201.

Cameron, E. (2011). On the estimation of confidence intervals for binomial population proportions in astronomy: the simplicity and superiority of the Bayesian approach. Publications of the Astronomical Society of Australia, 28(2): 128–139.

Newcombe, R. G. (1998). Two-sided confidence intervals for the single proportion: comparison of seven methods. Statistics in Medicine, 17(8): 857–872.

Pan, W. (2002). Approximate confidence intervals for one proportion and difference of two proportions. Computational statistics & Data Analysis, 40(1): 143-157.

Pires, A. M. & Amado, C. (2008). Interval estimators for a binomial proportion: Comparison of twenty methods. REVSTAT-Statistical Journal, 6(2): 165-197.

Ranucci, G. (2009). Binomial and ratio-of-Poisson-means frequentist confidence intervals applied to the error evaluation of cut efficiencies. arXiv preprint arXiv:0901.4845.

Sauro, J. & Lewis, J. R. (2005, September). Estimating completion rates from small samples using binomial confidence intervals: comparisons and recommendations. In Proceedings of the Human Factors and Ergonomics Society Annual Meeting (Vol. 49, No. 24, pp. 2100-2103). Sage CA: Los Angeles, CA: SAGE Publications.

Somerville, M. C. & Brown, R. S. (2013). Exact likelihood ratio and score confidence intervals for the binomial proportion. Pharmaceutical Statistics, 12(3): 120-128.

Thulin, Mans. The cost of using exact confidence intervals for a binomial proportion. (2014): 817-840. Electronic Journal of Statistics 8(1): 817-840.

Vollset, S. E. (1993). Confidence intervals for a binomial proportion. Statistics in Medicine, 12(9): 809-824.


Confidence Intervals for a Binomial Proportion.

Description

Confidence Intervals for a Binomial Proportion.

Usage

binomCI(x, n, a = 0.05)

Arguments

x

The number of successes.

n

The number of trials.

a

The significance level to compute the (1α)%(1-\alpha)\% confidence intervals.

Details

The confidence intervals are:

Jeffreys:

[F(α/2;x+0.5,nx+0.5),F(1α/2;x+0.5,nx+0.5)],\left[ F(\alpha/2; x+0.5, n-x+0.5), F(1-\alpha/2; x+0.5, n-x+0.5) \right],

where F(α,a,b)F(\alpha, a, b) denotes the α\alpha quantile of the Beta distribution with parameters aa and bb, Be(a,b)Be(a, b).

Wald:

[p^Z1α/2×p^(1p^)n,p^Z1α/2×p^(1p^)n],\left[ \hat{p} - Z_{1-\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}, \hat{p} - Z_{1-\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n}} \right],

where p^=xn\hat{p}=\frac{x}{n} and Z1α/2Z_{1-\alpha/2} denotes the 1α/21-\alpha/2 quantile of the standard normal distribution. If p^=0\hat{p}=0 the interval becomes (0,1e1nlog(α2))(0 , 1 - e^{\frac{1}{n}\log({\alpha}{2})}) and if p^=1\hat{p}=1 the interval becomes (e1nlog(α2),1)(e^{\frac{1}{n}\log({\alpha}{2})}, 1).

Wald corrected:

[p^Z1α/2×p^(1p^)n0.5n,p^Z1α/2×p^(1p^)n+0.5n],\left[ \hat{p} - Z_{1-\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n}} - \frac{0.5}{n}, \hat{p} - Z_{1-\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n}} + \frac{0.5}{n} \right],

and if p^=0\hat{p}=0 or p^=1\hat{p}=1 the previous (Wald) adjustment applies.

Wald BS:

[p^Z1α/2×p^(1p^)nZ1α/22Z1α/2/n1/n0.5n,p^Z1α/2×p^(1p^)nZ1α/22Z1α/2/n1/n+0.5n],\left[ \hat{p} - Z_{1-\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n-Z_{1-\alpha/2}-2Z_{1-\alpha/2}/n-1/n}} - \frac{0.5}{n}, \hat{p} - Z_{1-\alpha/2} \times \sqrt{\frac{\hat{p}(1-\hat{p})}{n-Z_{1-\alpha/2}-2Z_{1-\alpha/2}/n-1/n}} + \frac{0.5}{n} \right],

and if p^=0\hat{p}=0 or p^=1\hat{p}=1 the previous (Wald) adjustment applies.

Agresti and Coull:

[θ^Z1α/2×θ^(1θ^)n+4,p^Z1α/2×θ^(1θ^)n+4],\left[ \hat{\theta} - Z_{1-\alpha/2} \times \sqrt{\frac{\hat{\theta}(1-\hat{\theta})}{n+4}}, \hat{p} - Z_{1-\alpha/2} \times \sqrt{\frac{\hat{\theta}(1-\hat{\theta})}{n+4}} \right],

where θ^=x+2n+4\hat{\theta}=\frac{x+2}{n+4}.

Wilson:

[xbnbZ1α/2nnb×p^(1p^)+Z1α/2/4,xbnb+Z1α/2nnb×p^(1p^)+Z1α/2/4],\left[ \frac{x_b}{n_b} - \frac{Z_{1-\alpha/2}\sqrt{n}}{n_b} \times \sqrt{\hat{p}(1-\hat{p})+Z_{1-\alpha/2}/4}, \frac{x_b}{n_b} + \frac{Z_{1-\alpha/2}\sqrt{n}}{n_b} \times \sqrt{\hat{p}(1-\hat{p})+Z_{1-\alpha/2}/4} \right],

where xb=x+Z1α/22/2x_b=x+Z_{1-\alpha/2}^2/2 and nb=n+Z1α/22n_b=n+Z_{1-\alpha/2}^2.

Score:

[x+Z1α/22cn+Z1α/22,x+Z1α/22+cn+Z1α/22],\left[ \frac{x+Z_{1-\alpha/2}^2-c}{n+Z_{1-\alpha/2}^2} , \frac{x+Z_{1-\alpha/2}^2+c}{n+Z_{1-\alpha/2}^2} \right],

where c=Z1α/2xx2/n+Z1α/22/4c=Z_{1-\alpha/2}\sqrt{x-x^2/n+Z_{1-\alpha/2}^2/4}.

Score corrected:

[1n+Z1α/2,2n+Z1α/2],\left[ \frac{\ell_1}{n+Z_{1-\alpha/2}} , \frac{\ell_2}{n+Z_{1-\alpha/2}} \right],

where 1=b1+0.5Z1α/22Z1α/2b1b12/n+0.25Z1α/22\ell_1=b_1+0.5Z_{1-\alpha/2}^2-Z_{1-\alpha/2}\sqrt{b_1-b_1^2/n+0.25Z_{1-\alpha/2}^2}, 2=b2+0.5Z1α/22+Z1α/2b2b22/n+0.25Z1α/22\ell_2=b_2+0.5Z_{1-\alpha/2}^2+Z_{1-\alpha/2}\sqrt{b_2-b_2^2/n+0.25Z_{1-\alpha/2}^2} and b1=x0.5b_1=x-0.5, b2=x+0.5b_2=x+0.5.

Wald-logit:

[1(1+ebc)1,1(1+eb+c)1],\left[ 1-(1+e^{b-c})^{-1}, 1-(1+e^{b+c})^{-1} \right],

where b=log(xnx)b=\log(\frac{x}{n-x}) and c=Z1α/2np^(1p^)c=\frac{Z_{1-\alpha/2}}{\sqrt{n\hat{p}(1-\hat{p})}}. If p^=0\hat{p}=0 or p^=1\hat{p}=1 the previous (Wald) adjustment applies.

Wald-logit corrected:

[1(1+ebc)1,1(1+eb+c)1],\left[ 1-(1+e^{b-c})^{-1}, 1-(1+e^{b+c})^{-1} \right],

where b=log(p^bq^b)b=\log(\frac{\hat{p}_b}{\hat{q}_b}), p^b=x+0.5\hat{p}_b=x+0.5, q^b=nx+0.5\hat{q}_b=n-x+0.5 and c=Z1α/2(n+1)p^bn+1(1p^bn+1)c=\frac{Z_{1-\alpha/2}}{\sqrt{(n+1)\frac{\hat{p}_b}{n+1}(1-\frac{\hat{p}_b}{n+1})}}.

Arcsine:

{sin2[sin1(p^)0.5Z1α/2n],sin2[sin1(p^)+0.5Z1α/2n]}.\left\lbrace \sin^2\left[sin^{-1}(\sqrt{\hat{p}})-0.5\frac{Z_{1-\alpha/2}}{\sqrt{n}}\right], \sin^2\left[sin^{-1}(\sqrt{\hat{p}})+0.5\frac{Z_{1-\alpha/2}}{\sqrt{n}}\right] \right\rbrace.

If p^=0\hat{p}=0 or p^=1\hat{p}=1 the previous (Wald) adjustment applies.

Exact binomial:

[(1+a1d1)1,(1+a2d2)1],\left[ (1+\frac{a_1}{d_1})^{-1}, (1+\frac{a_2}{d_2})^{-1} \right],

where a1=nx+1a_1=n-x+1, a2=a11a_2=a_1-1, d1=xF(α/2,2x,2a1)d_1=x-F(\alpha/2,2x,2a_1), d2=(x+1)F(1α/2,2(x+1),2a2)d_2=(x+1)F(1-\alpha/2,2(x+1),2a_2) and F(α,a,b)F(\alpha,a,b) denotes the α\alpha quantile of the F distribution with degrees of freedom aa and bb, F(a,b)F(a, b).

Value

A list including:

prop

The proportion.

ci

A matrix with 12 rows containing the 12 different (1α)%(1-\alpha)\% confidence intervals.

Author(s)

Michail Tsagris.

R implementation and documentation: Michail Tsagris [email protected].

See Also

binomCIs

Examples

binomCI(45, 100)

Confidence Intervals for many Binomial Proportions.

Description

Confidence Intervals for many Binomial Proportions.

Usage

binomCIs(x, n, a = 0.05)

Arguments

x

A vector with the number of successes.

n

A vector with the number of trials.

a

The significance level to compute the (1α)%(1-\alpha)\% confidence intervals.

Value

A list with the the first element being the vector with the proportions and the rest 12 items contain the (1α)%(1-\alpha)\% confidence intervals.

Author(s)

Michail Tsagris.

R implementation and documentation: Michail Tsagris [email protected].

See Also

binomCI

Examples

x <- sample(40, 10)
n <- rep(40, 10)
binomCIs(x, n)