tirler@statistik.wu-wien.ac.at
2003-Mar-25 13:40 UTC
[Rd] BUG report : 'rnorm' (LINUX, R 1.6.2) (PR#2682)
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 -- ----------------------------------------------------------------------------- Günter Tirler | University of Economics and Business Administration | Department for Applied Statistics and Data Processing ----------------------------------------------------------------------------- Augasse 2-6 | Tel. *43/1/31336-4840 A-1090 Vienna | FAX *43/1/31336-738 Austria | email tirler@statistik.wu-wien.ac.at -----------------------------------------------------------------------------
ripley@stats.ox.ac.uk
2003-Mar-25 13:50 UTC
[Rd] BUG report : 'rnorm' (LINUX, R 1.6.2) (PR#2682)
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