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

Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
27 Feb 1998 18:46:37 +0100


To: Bill Simpson <wsimpson@uwinnipeg.ca>
Subject: Re: R-beta: is there a way to get rid of loop?
From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
Date: 27 Feb 1998 18:46:37 +0100
In-Reply-To: Bill Simpson's message of Fri, 27 Feb 1998 11:14:11 -0600 (CST)

Bill Simpson <wsimpson@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@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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._