Re: [R] Why R simulation gives same random results?

2013-02-21 Thread Greg Snow
Look at the harvestr package for one way to control multiple parallel
simulations and make sure that they have different seeds.


On Wed, Feb 20, 2013 at 4:24 PM, C W tmrs...@gmail.com wrote:

 Thanks, Greg.  I think you are right.  I did simulation one right after
 the other, less than 2 seconds.

 But still, it was shocking to see identical samples, which I had to throw
 away.

 As a rule of thumb, should I do simulation in one R console, rather than
 splitting the work into 2 consoles.  I just thought it would take less time
 for me, but it seems risky.

 Thanks,
  Mike



 On Wed, Feb 20, 2013 at 6:13 PM, Greg Snow 538...@gmail.com 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.

 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.


 On Tue, Feb 19, 2013 at 6:31 PM, C W tmrs...@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.

 I did not use any set.seed().  What is going on here?

 Thanks,
 Mike

 [[alternative HTML version deleted]]


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Gregory (Greg) L. Snow Ph.D.
 538...@gmail.com





-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Why R simulation gives same random results?

2013-02-20 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Why R simulation gives same random results?

2013-02-20 Thread Greg Snow
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.

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.


On Tue, Feb 19, 2013 at 6:31 PM, C W tmrs...@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.

 I did not use any set.seed().  What is going on here?

 Thanks,
 Mike

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Why R simulation gives same random results?

2013-02-20 Thread C W
Thanks, Greg.  I think you are right.  I did simulation one right after the
other, less than 2 seconds.

But still, it was shocking to see identical samples, which I had to throw
away.

As a rule of thumb, should I do simulation in one R console, rather than
splitting the work into 2 consoles.  I just thought it would take less time
for me, but it seems risky.

Thanks,
Mike


On Wed, Feb 20, 2013 at 6:13 PM, Greg Snow 538...@gmail.com 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.

 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.


 On Tue, Feb 19, 2013 at 6:31 PM, C W tmrs...@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.

 I did not use any set.seed().  What is going on here?

 Thanks,
 Mike

 [[alternative HTML version deleted]]


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Gregory (Greg) L. Snow Ph.D.
 538...@gmail.com


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Why R simulation gives same random results?

2013-02-20 Thread Prof Brian Ripley

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 tmrs...@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,  rip...@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, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Why R simulation gives same random results?

2013-02-19 Thread C W
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

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.