[R] Normal deviate generation - Marsaglia's ziggurat method

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri May 30 16:53:20 CEST 2003


Accuracy and reliability are more important than speed.

As you say, it is available elsewhere, but who actually needs a faster
method?  1 million normals take 0.55s on my machine (an Athlon 2600): 1
million uniforms take 0.16s, so there is not I think scope to be `6 to 7
times faster' at R level.  rziggurat takes 0.51s on the same machine,
despite saying

     This implementation running in R is approximately three times as
     fast as rnorm().

So I checked some other machines
		runif	rnorm	rziggurat
2.4Ghz P4	0.33	1.30	0.37
1GHz PIII	0.40	1.47	0.94
Athlon 2600	0.16	0.55	0.51

There's something rather strange about the P4 results relative to the
others, possibly due to cache sizes.  (Linux RH7.3 for the first two,
RH8.0 for the last, and the same compiled code running on each.)

My point remains: who wants 1 million random uniforms and wants to save 
fractions of a second?


Also, I was wondering why some people expect R to provide exactly what
they fancy, free of charge?


On Fri, 30 May 2003, Ravi Varadhan wrote:

> I was wondering why Marsaglia's new ziggurat method for generating 
> deviates from the standard normal distribution has not been implemented 
> in the R base package. I know that it is available in SuppDists 
> pacakage of Bob Wheeler, as "rziggurat". According my timing tests, it 
> is about 6 to 7 times faster (on a Pentium 2.4 MHz) machine than the 
> default Inversion method used in R base package. 

-- 
Brian D. Ripley,                  ripley at 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




More information about the R-help mailing list