An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130219/37df8a3c/attachment.pl>
Why R simulation gives same random results?
6 messages · C W, Nordlund, Dan (DSHS/RDA), Brian Ripley +1 more
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of C W Sent: Tuesday, February 19, 2013 5:32 PM To: r-help Subject: [R] Why R simulation gives same random results? Hi, list I am doing 100,000 iterations of Bayesian simulations. What I did is I split it into 4 different R sessions, each one runs 25,000 iteration. But two of the sessions gave the simulation result. I did not use any set.seed(). What is going on here? Thanks, Mike
I may have missed it, but I haven't seen a response to this question yet. If no one has responded, it is probably because you haven't provided the code you used to run the simulation, or a reproducible example which demonstrates the problem. You say you didn't use set.seed(), but you didn't show what you did do, so there is insufficient information for anyone to be able to comment what went wrong. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130220/7726f660/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130220/f6688c5e/attachment.pl>
On 20/02/2013 23:13, Greg Snow wrote:
To know for sure we need to know how you are running these different R sessions, but here are some possibilities: The help page for "set.seed" says that if no seed exists then the seed is set based on the current time (and since 2.14.0 the process ID). So one possibility is that 2 of the sessions are started close enough together that they get the same seed. Or the difference in time and process ID cancel each other out.
That is exceedingly unlikely. We are not told the platform, but AFAIK on all common R platforms and current versions of R: - the time is measured to at least msec accuracy. - times which might cancel out pid differences are many hours apart. A while ago it was possible on some platforms to get the same seed by starting two R processes on the same clock tick (within 1/60 or 1/100 s of each other). But now you are talking about generating a pretty random unsigned integer with 32 bits to set the seed, so the probability of coincidence is very small.
Another possibility (also mentioned in the help page) is that if the seed was saved in a previous session then it will be restored in the new session, if all the sessions are reading in the same stored session (or just the 2 that are the same) then they would start from the same seed.
Much more likely.
On Tue, Feb 19, 2013 at 6:31 PM, C W <tmrsg11 at gmail.com> wrote:
Hi, list I am doing 100,000 iterations of Bayesian simulations.
What I did is I split it into 4 different R sessions, each one runs 25,000 iteration. But two of the sessions gave the simulation result.
This falls within the class of parallel simulations. You would do better to set carefully selected seeds: see the vignette for package 'parallel'.
I did not use any set.seed(). What is going on here? Thanks, Mike
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130221/70a3282c/attachment.pl>