[R] set.seed

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon Aug 12 21:48:54 CEST 2002


You either need to

1) set set.seed before the first run, then set it  again to the first
value.

or

2) save .Random.seed and reset it by

.Random.seed <- temp.seed

Beware that the second approach is not sufficient with the Box-Muller
method.

Your problem is that you have mixed the two approaches.

Hope this helps.


On Mon, 12 Aug 2002 Jim_Garrett at bd.com wrote:

>
> I'm running into problems with set.seed--maybe I'm misunderstanding
> something.
>
> I'm running R 1.5.1 on Windows 2000.
>
> I'm basically trying to capture the random seed so that I can reproduce a
> simulation if it's necessary later.  Using set.seed, I can certainly get
> reproducible results, but not the results I get on the first pass.  Here's
> an example:
>
> # Generate a random number to initialize
> > runif(1)
> [1] 0.965875
> > RNGkind()
> [1] "Marsaglia-Multicarry" "Kinderman-Ramage"
> >
> > # Save random seed
> > temp.seed <- .Random.seed
> >
> > # Proceed to generate random uniforms
> > runif(5)
> [1] 0.18734034 0.02723140 0.46396251 0.10602243 0.64362777
> >
> > # try to reproduce this sequence
> > set.seed(temp.seed, "default")
> > runif(5)
> [1] 0.006153224 0.553233950 0.091852441 0.643058504 0.009685173
> >
> > # just to see, try again
> > set.seed(temp.seed, "default")
> > runif(5)
> [1] 0.006153224 0.553233950 0.091852441 0.643058504 0.009685173
>
> So you can see that I can reproduce the latter sequence, but not the first
> sequence.  As a workaround, I guess I can call set.seed prior to generating
> the first sequence.  But it puzzles me why capturing the random seed
> appears not to be sufficient.  Am I overlooking something?
>
> Thanks for any guidance.
>
> Jim Garrett
> Becton Dickinson Diagnostic Systems
> Baltimore, Maryland, USA
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list