[R] difference between rnorm(1000, 0, 1) and running rnorm(500, 0, 1) twice

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Feb 8 16:25:39 CET 2006


Duncan Murdoch <murdoch at stats.uwo.ca> writes:

> This isn't really something that can be proved by a test.  Perhaps the 
> current implementation makes those equal only because 500 is even, or 
> divisible by 5, or whatever...
> 
> I think the intention is that those should be equal, but in a quick 
> search I've been unable to find a documented guarantee of that.  So I 
> would take a defensive stance and assume that there may be conditions 
> where c(rnorm(m), rnorm(n)) is not equal to rnorm(m+n).
> 
> If someone can point out the document I missed, I'd appreciate it.

I think it's a fair assumption that *uniform* random numbers have the
property, since these are engines that produce a continuous stream of
values, of which we select the next n and m values. 

As long as the normal.kind (see ?RNGkind) is "Inversion", we can be
sure that the property carries to rnorm, but it might not be the case
for other methods. In particular the ones that generate normal
variates in batches are suspect. However, empirically, I can't seem to
provoke the effect with any of R's built-in generators. One *could* of
course check the source code and see whether there is state
information being kept between invokations...

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list