Re: [R] Can simulation involving random number generation be segmented?

From: A.J. Rossini <blindglobe_at_gmail.com>
Date: Thu 26 May 2005 - 06:22:53 EST

You might consider the rlecuyer package, which provides parallel streams and avoids the potential worst case scenario from arbitrary seed setting.

On 5/25/05, Dr L. Y Hin <lyhin@netvigator.com> wrote:
> Dear all,
> Apologies for this pedantic question that only arise when there is hardware
> limitation.
> Setting: R 2.1.0 for windows xp sp2.
> Scenario:
> To generate 1000 samples using rnorm for a simulation activity.
> Background:
> The simulation activity requires so much memory resources that generating
> 200 samples
> clogs up the PF usage as indicated in the Windows Task Manager.
> Therefore, short of implementing the simulation on a computer with more
> resources,
> the alternative is to generate the 1000 samples in 5 separate runs,
> each generating 200 samples, closing the R window and re-opening between
> runs.
> Question to be addressed:
> To maintain consistency and ensure reproducibility of the simulation
> results, the 1000 samples
> generated in one single run should be indentical to the 5x200 samples
> generated on 5 separate
> runs.
> While such consistency can be ensured using set.seed() in the case of one
> single run, in the case
> where 5 separate runs are performed, can we do the following to ensure
> identical samples being
> generated?
> 1. In the first run, specify the seed by, say, set.seed(1)
>
> 2. At the end of the first run, store the .Random.seed by the following
> manner:
> saved.seed.1<-.Random.seed
>
> 3. At the beginning of the second run, assign the saved.seed.1 to
> .Random.seed as follows:
> .Random.seed<-saved.seed.1
>
> 4. At the end of the first run, store the new .Random.seed by the following
> manner:
> saved.seed.2<-.Random.seed
>
> 5. At the beginning of the second run, assign the saved.seed.2 to
> .Random.seed as follows:
> .Random.seed<-saved.seed.2
>
> This is repeated until 5 runs are completed.
>
> Will the paths of random number generation be identical in these two
> approaches? If not, is there
> a way to ensure this?
>
> Apologies again for this long-winded inquiry.
>
> Thank you.
> Best
> Lin
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
best,
-tony

"Commit early,commit often, and commit in a repository from which we can easily
roll-back your mistakes" (AJR, 4Jan05).

A.J. Rossini
blindglobe@gmail.com

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu May 26 06:28:41 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:05 EST