[Rd] bug in rbinom? (PR#1190)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
02 Dec 2001 19:04:45 +0100


Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

> Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
> 
> > viele@ms.uky.edu writes:
> > 
> > > I was simulating the central limit theorem in class,
> > > but found that repeated use of
> > > 
> > > mean(rbinom(100000,500,0.4))
> > > 
> > > resulted in values less than 200 (the expected mean), for example
> > > 
> > > > mean(rbinom(100000,500,0.4))
> > > [1] 199.0294
> > > > mean(rbinom(100000,500,0.4))
> > > [1] 199.1077
> > > > mean(rbinom(100000,500,0.4))
> > > [1] 199.0668
> > > and so on.
> > > 
> > > I did this 1000 times and found the results to be distributed
> > > approximately N(199.0787,s=0.036). The standard deviation
> > > is pretty accurate, but the mean is significantly off from 200.
> > 
> > I see the same thing on Linux. Looks like it needs checking against
> > the original CACM algorithm.
> 
> This seems not to be present in the original Fortran (once I got it to
> compile properly -- it requires -fno-automatic) so there has to be a
> transcription error somewhere. I'll be darned if I can find it, though. 

Got it!  

log(w * p / (x1 * q))

had lost the parentheses in the denominator... Will fix for 1.4


-- 
   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-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._