Produces 1-alpha confidence intervals for binomial probabilities.

binconf(x, n, alpha=0.05,
        method=c("wilson","exact","asymptotic","all"),
        include.x=FALSE, include.n=FALSE, return.df=FALSE)

Arguments

x

vector containing the number of "successes" for binomial variates

n

vector containing the numbers of corresponding observations

alpha

probability of a type I error, so confidence coefficient = 1-alpha

method

character string specifing which method to use. The "all" method only works when x and n are length 1. The "exact" method uses the F distribution to compute exact (based on the binomial cdf) intervals; the "wilson" interval is score-test-based; and the "asymptotic" is the text-book, asymptotic normal interval. Following Agresti and Coull, the Wilson interval is to be preferred and so is the default.

include.x

logical flag to indicate whether x should be included in the returned matrix or data frame

include.n

logical flag to indicate whether n should be included in the returned matrix or data frame

return.df

logical flag to indicate that a data frame rather than a matrix be returned

Value

a matrix or data.frame containing the computed intervals and, optionally, x and n.

Author

Rollin Brant, Modified by Frank Harrell and
Brad Biggerstaff
Centers for Disease Control and Prevention
National Center for Infectious Diseases
Division of Vector-Borne Infectious Diseases
P.O. Box 2087, Fort Collins, CO, 80522-2087, USA
bkb5@cdc.gov

References

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

R.G. Newcombe, Logit confidence intervals and the inverse sinh transformation, American Statistician, 55:200–202, 2001.

L.D. Brown, T.T. Cai and A. DasGupta, Interval estimation for a binomial proportion (with discussion), Statistical Science, 16:101–133, 2001.

Examples

binconf(0:10,10,include.x=TRUE,include.n=TRUE)
#>   X  N PointEst       Lower     Upper
#>   0 10      0.0 0.000000000 0.2775328
#>   1 10      0.1 0.005129329 0.4041500
#>   2 10      0.2 0.056682151 0.5098375
#>   3 10      0.3 0.107791267 0.6032219
#>   4 10      0.4 0.168180330 0.6873262
#>   5 10      0.5 0.236593091 0.7634069
#>   6 10      0.6 0.312673770 0.8318197
#>   7 10      0.7 0.396778147 0.8922087
#>   8 10      0.8 0.490162472 0.9433178
#>   9 10      0.9 0.595849973 0.9948707
#>  10 10      1.0 0.722467200 1.0000000
binconf(46,50,method="all")
#>            PointEst     Lower     Upper
#> Exact          0.92 0.8076572 0.9777720
#> Wilson         0.92 0.8116175 0.9684505
#> Asymptotic     0.92 0.8448027 0.9951973