Hello, I already sent such an email before Christmas, but nobody answered, so here is my problem: I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito
runif and sample with reproducibility
6 messages · Eric ESPOSITO, Roger D. Peng, Brian Ripley +3 more
When I use set.seed() in R 1.8.1, I get the following: > set.seed(1) > sample(1:100, 10) [1] 27 37 57 89 20 86 97 62 58 6 > set.seed(1) > sample(1:100, 10) [1] 27 37 57 89 20 86 97 62 58 6 > set.seed(1) > sample(1:100, 10) [1] 27 37 57 89 20 86 97 62 58 6 > set.seed(2) > runif(10) [1] 0.1848823 0.7023740 0.5733263 0.1680519 0.9438393 0.9434750 0.1291590 [8] 0.8334488 0.4680185 0.5499837 > set.seed(2) > runif(10) [1] 0.1848823 0.7023740 0.5733263 0.1680519 0.9438393 0.9434750 0.1291590 [8] 0.8334488 0.4680185 0.5499837 What output do you get? Also, keep in mind that the default random number generator changed in (I believe) R 1.7.0 so you may need to use RNGversion() to reproduce results from earlier versions of R. -roger
Eric ESPOSITO wrote:
Hello, I already sent such an email before Christmas, but nobody answered, so here is my problem: I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Mon, 5 Jan 2004, Eric ESPOSITO wrote:
Hello, I already sent such an email before Christmas, but nobody answered, so here
There *was* an answer posted, see the archives here: https://www.stat.math.ethz.ch/pipermail/r-help/2003-December/042422.html and none of the rest of us has any idea why this does not work for you (if indeed it does not).
is my problem: I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito
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
Hi Eric, How about:
set.seed(1234567) sample(1:100,10)
[1] 57 72 90 3 74 46 9 81 95 78
set.seed(1234567) sample(1:100,10)
[1] 57 72 90 3 74 46 9 81 95 78
Cheers, Anders.
On Mon, 5 Jan 2004, Eric ESPOSITO wrote:
Hello, I already sent such an email before Christmas, but nobody answered, so here is my problem: I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On Mon, Jan 05, 2004 at 01:07:08PM +0100, Eric ESPOSITO wrote:
I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that?
help(set.seed) Hth, Dirk
The relationship between the computed price and reality is as yet unknown.
-- From the pac(8) manual page
Hallo I think I have seen an answer to it but did not search for it. set.seed() with sample() is perfectly reprodicble for me (well, I tried it only three times :-)
set.seed(111) sample(1:100,10)
[1] 8 93 38 14 23 51 86 31 75 34
set.seed(111) sample(1:100,10)
[1] 8 93 38 14 23 51 86 31 75 34
set.seed(111) sample(1:100,10)
[1] 8 93 38 14 23 51 86 31 75 34 I suspect you called "set seed" only once. Cheers Petr
On 5 Jan 2004 at 13:07, Eric ESPOSITO wrote:
Hello, I already sent such an email before Christmas, but nobody answered, so here is my problem: I would like to sample a population but the result needs to be reproducible, using 'runif' or 'sample' is the good way to do it but I can't manage to make the results reproducible even with the 'set.seed' function. My aim is that th call to 'sample(1:100,10)' gives always the same result, how can I do that? Thanks! Eric Esposito
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Petr Pikal petr.pikal at precheza.cz