calculation resutls vs. actual R

Ulrich Poetter ulrich.poetter at ruhr-uni-bochum.de
Sat Mar 20 02:18:53 CET 2004


Fred J. writes:
 > maybe I should have explained a bit more.
 > I do understand that the numbers generated by rnorm
 > are random, but the mean and sd being the same for
 > both ess and R, should be the same on inspection, or I
 > am missing somthing?

Yes. R and many other statistics packages initialize their pseudo
random number generation algorithms from current clock time of the
computer, presumably because someone in ancient time thought this
would emulate surprise. The surprise persists obviously. Thus,
starting rnorm at different (local processor) times will give
different results. See the help on 'set.seed':

"Initially, there is no seed; a new one is created from the current
time when one is required. Hence, different sessions will give
different simulation results, by default."

To get comparable results, you should set the seed of rnorm in both
sessions by calling "set.seed(i)" where i is an integer. I.e.,
pre-pending "set.seed(0)" to your code in the ess and Rterm session
should give exactly the same results. 

If you plan to communicate your simulation results in a way that is
reproducible by others you have to fix a seed so that others can
reproduce your results.

Best regards,
Uli Poetter




More information about the ESS-help mailing list