[R] , Exact Confidence Interval

David Winsemius dwinsemius at comcast.net
Wed Mar 7 22:51:09 CET 2012


On Mar 7, 2012, at 3:35 PM, Anamika Chaudhuri wrote:

>>
>> Hi All:
>>
>> I am using R to calculate exact 95% confidence interval using Clopper
>> Pearson method. I am using the following code but it seems to get  
>> into a
>> loop and not get out of it, it goes on forever although I am  
>> looping it
>> only 10 times across 63 sites with 10 observations per site. I was  
>> hoping
>> to get some help.

?binom.test  #  returns Clopper-Pearson intervals

Laura A. Thompson's excellent "S-PLUS (and R) Manual to Accompany  
Agresti’s Categorical Data Analysis (2002) , 2nd edition"  2007© cites  
several other methods. It's easy to access this resource with a web  
search since Agresti cites it and Google searches generaly bring it up  
as the first hit.

-- 
David.
>>
>> Thanks
>>
> Anamika
>
>> set.seed(111)  #so that you can regenerate the same values
>> # another time if you need to
>> k<-63
>> n<-10
>> x<-NULL
>> eta<-rnorm(63,-0.085,.990)  # generating data using Binomial Logit  
>> Normal
>> p<-exp(eta)/(1+exp(eta))
>> for(i in 1:k)
>> x<-cbind(x,rbinom(10,n,p[i]))
>>
>> rate<-t(t(x)/n)
>>
>> # Exact Confidence Interval
>>
>> for (i in 1:10){
>>
>> for (j in 1:63)
>> {
>>
>> if (x==0)
>> {
>> l_cl_exact<-0
>> u_cl_exact<-qbeta(.975,x+1,n-x)
>> }
>> else if (x==n)
>> {
>> l_cl_exact<-qbeta(.025,x,n-x+1)
>> u_cl_exact<-1
>> }
>> else
>> l_cl_exact<-qbeta(.025,x,n-x+1)
>> u_cl_exact<-qbeta(.975,x+1,n-x)
>>
>> }
>> }_____________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html 
>> >
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list