R-beta: is there a way to get rid of loop?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Feb 27 18:46:37 CET 1998


Bill Simpson <wsimpson at uwinnipeg.ca> writes:

> associated binomial variate with p=phit.  Is there a better way to do this
> than by looping?
> 
> Gsens.ci.mc<-function(nhit,nmiss,nfa,ncr)
> {
> #monte carlo simulated 95% CI
> nsignal<-nhit+nmiss
> nnoise<-nfa+ncr
> phit<-nhit/nsignal
> pfa<-nfa/nnoise
> ns<-rbinom(2000,nsignal,.5)
> nn<-nsignal+nnoise-ns
> nh<-NULL
> nf<-NULL
> for(i in 1:2000)
> 	{
> 	nh<-c(nh,rbinom(1,ns[i],phit))
> 	nf<-c(nf,rbinom(1,nn[i],pfa))
> 	}
> g<-Gsens(nh,ns-nh,nf,nn-nf)
> quantile(g,c(.025,.975), na.rm=TRUE)
> }

Yes. 

[prepare to slap forehead...]

nh<-rbinom(2000,ns,phit)
nf<-rbinom(2000,nn,pfa)

This will generate NA's whereever ns==0, but you had that problem anyway.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list