[R] proportions confidence intervals

Marc Schwartz MSchwartz at MedAnalytics.com
Mon Jul 12 20:58:25 CEST 2004


FWIW, if the exact intervals are what is desired here, as another poster
has already suggested, binom.test() will get you there:

> binom.test(1, 10)$conf.int
[1] 0.002528579 0.445016117
attr(,"conf.level")
[1] 0.95

> binom.test(10, 100)$conf.int
[1] 0.04900469 0.17622260
attr(,"conf.level")
[1] 0.95

HTH,

Marc Schwartz

On Mon, 2004-07-12 at 13:19, Chuck Cleland wrote:
>    Darren also might consider binconf() in library(Hmisc).
> 
>  > library(Hmisc)
> 
>  > binconf(1, 10, method="all")
>             PointEst        Lower     Upper
> Exact           0.1  0.002528579 0.4450161
> Wilson          0.1  0.005129329 0.4041500
> Asymptotic      0.1 -0.085938510 0.2859385
> 
>  > binconf(10, 100, method="all")
>             PointEst      Lower     Upper
> Exact           0.1 0.04900469 0.1762226
> Wilson          0.1 0.05522914 0.1743657
> Asymptotic      0.1 0.04120108 0.1587989
> 
> Spencer Graves wrote:
> >      Please see:
> >      Brown, Cai and DasGupta (2001) Statistical Science, 16:  101-133 
> > and (2002) Annals of Statistics, 30:  160-2001
> >      They show that the actual coverage probability of the standard 
> > approximate confidence intervals for a binomial proportion are quite 
> > poor, while the standard asymptotic theory applied to logits produces 
> > rather better answers.
> >      I would expect "confint.glm" in library(MASS) to give decent 
> > results, possibly the best available without a very careful study of 
> > this particular question.  Consider the following:
> >  library(MASS)# needed for confint.glm
> >  library(boot)# needed for inv.logit
> >  DF10 <- data.frame(y=.1, size=10)
> >  DF100 <- data.frame(y=.1, size=100)
> >  fit10 <- glm(y~1, family=binomial, data=DF10, weights=size)
> >  fit100 <- glm(y~1, family=binomial, data=DF100, weights=size)
> >  inv.logit(coef(fit10))
> > 
> >  (CI10 <- confint(fit10))
> >  (CI100 <- confint(fit100))
> > 
> >  inv.logit(CI10)
> >  inv.logit(CI100)
> > 
> >      In R 1.9.1, Windows 2000, I got the following:
> > 
> >>   inv.logit(coef(fit10))
> > 
> > (Intercept)
> >        0.1
> > 
> >>  
> >>   (CI10 <- confint(fit10))
> > 
> > Waiting for profiling to be done...
> >     2.5 %     97.5 %
> > -5.1122123 -0.5258854
> > 
> >>   (CI100 <- confint(fit100))
> > 
> > Waiting for profiling to be done...
> >    2.5 %    97.5 %
> > -2.915193 -1.594401
> > 
> >>  
> >>   inv.logit(CI10)
> > 
> >      2.5 %      97.5 %
> > 0.005986688 0.371477058
> > 
> >>   inv.logit(CI100)
> > 
> >    2.5 %    97.5 %
> > 0.0514076 0.1687655
> > 
> >>
> >>   (naiveCI10 <- .1+c(-2, 2)*sqrt(.1*.9/10))
> > 
> > [1] -0.08973666  0.28973666
> > 
> >>   (naiveCI100 <- .1+c(-2, 2)*sqrt(.1*.9/100))
> > 
> > [1] 0.04 0.16




More information about the R-help mailing list