From ripley at stats.ox.ac.uk  Tue Mar 25 12:49:51 2003
From: ripley at stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Tue Mar 25 13:50:22 2003
Subject: [Rd] BUG report : 'rnorm' (LINUX, R 1.6.2) (PR#2682)
In-Reply-To: <200303251239.h2PCdwn9019842@pubhealth.ku.dk>
Message-ID: <Pine.LNX.4.44.0303251246570.3595-100000@gannet.stats>

Try R-devel, as this has already been changed (after several related 
reports).

Be aware though that *all* pseudo-random number generators have some 
deficiencies, and R does provide you with many other choices.

On Tue, 25 Mar 2003 tirler@statistik.wu-wien.ac.at wrote:

> Dear colleague,
> 
> unfortunately 'rnorm' does not create normal distributed numbers as
> you can see with following histogramm:
> 
> > hist(rnorm(1000000),breaks=100)
> 
> and 
> 
> > hist(pnorm(rnorm(1000000)),breaks=100)
> 
> I have done several chi^2-tests which have all failed:
> 
> > chi2unif<- function(x,N)
> >   {
> >    anz=length(x)
> >    f0<-rep(anz/N,times=N)
> >    fi<-(hist(x,g<-seq(length(N+1),from=0, by=1/N), plot=FALSE)[2])
> >    fin<-fi[[1]][1:N]
> >    chi2=sum( ((f0-fin)^2)/f0 )
> >    pchisq(chi2,N-1)
> >  } 
> 
> > chi2unif(x<-pnorm(rnorm(1000000)),100)
> 
> The result is the p-value of a goodness of fit test (chisquare test).
> It should be a uniform random number in [0,1].
> However, if this test is repeated, one almost every time gets an
> number near one (0.99...)
> 
> This problems happens only by using normal.kind="Kindermann-Ramage"
> (the default). This bug also appears in all random variate generation
> that depend on 'rnorm', like 'rgamma'.
> 
> With regards,
> G?nter Tirler
> 
> 
> 

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] BUG report : 'rnorm' (LINUX, R 1.6.2) (PR#2682)
ripley@stats.ox.ac.uk