Bug in rnorm. (PR#1664)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
13 Jun 2002 23:59:43 +0200

rolf@math.unb.ca writes:

> There appears to be a mild bug, or at least a deficiency, in
> rnorm.  The bug becomes apparent when one looks at extremes
> of the squares of the values generated by rnorm; rnorm is not
> generating quite enough extreme values.
> The R version that I am using is 1.4.1; I never got around to installing
> 1.5.0, and now since 1.5.1 is about to come out ....  However, checking
> the 1.5.0 release notes revealed no mention of fixing a bug in rnorm.

...and I see the effect too with an r-patched from a few days back.

> After some discussion with colleagues, I replaced the calls to rnorm()
> by calls to myrnorm() defined by
> 	myrnorm <- function(n,mu=0,sigma=1){
> 		mu + sigma*cos(2*pi*runif(n))*sqrt(-2*log(runif(n)))
> 	}
> which uses the ``(r,theta)'' method of generating random normals.
> When I did so, the resulting values were indeed all ``close to'' 0.05,
> as they should be.
> I also tried the experiment using rchisq(n,1) instead of rnorm(n) (and
> then of course taking m = max of x --- rather than max of x^2).  Again
> all the resulting values were close to 0.05 as ought to be the case.
> (So rchisq() appears to be OK in this regard.)

Also qnorm(runif(n)) seems to be closer to the target.

   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