Re: [R] Random seed

2018-12-23 Thread Jeff Newmiller
For the record, low bitcount RNGs are relatively sensitive to initialization [1] such that rules like the one you reference might make sense for specific designs, but the default RNG used in R is much much more sophisticated than that [2]. [1] http://daviddeley.com/random/random4.htm [2] ?Rando

Re: [R] Random seed

2018-12-22 Thread Jeff Newmiller
It doesn't matter. The whole point is to make the pseudo-random sequence repeatable... unless you have a specific reason to avoid repeatability. On December 22, 2018 5:33:39 PM PST, Steven Yen wrote: >I have known from the old days to set a random seed of a LARGE ODD >NUMBER. Now I read instruc

[R] Random seed

2018-12-22 Thread Steven Yen
I have known from the old days to set a random seed of a LARGE ODD NUMBER. Now I read instructions of set.seed and it requires ANY INTEGER. Any idea? Or, does it matter. Thanks. -- st...@ntu.edu.tw (S.T. Yen) [[alternative HTML version deleted]] __

Re: [R] Random Seed Location

2018-03-05 Thread Paul Gilbert
On 03/04/2018 07:14 PM, Henrik Bengtsson wrote: On Sun, Mar 4, 2018 at 3:23 PM, Duncan Murdoch wrote: ... An issue is that .Random.seed doesn't contain the full state of the RNG system, so restoring it doesn't necessarily lead to an identical sequence of output. The only way to guarantee th

Re: [R] Random Seed Location

2018-03-04 Thread Henrik Bengtsson
On Sun, Mar 4, 2018 at 3:23 PM, Duncan Murdoch wrote: > On 04/03/2018 5:54 PM, Henrik Bengtsson wrote: >> >> The following helps identify when .GlobalEnv$.Random.seed has changed: >> >> rng_tracker <- local({ >>last <- .GlobalEnv$.Random.seed >>function(...) { >> curr <- .GlobalEnv$.R

Re: [R] Random Seed Location

2018-03-04 Thread Henrik Bengtsson
On Sun, Mar 4, 2018 at 10:18 AM, Paul Gilbert wrote: > On Mon, Feb 26, 2018 at 3:25 PM, Gary Black > wrote: > > (Sorry to be a bit slow responding.) > > You have not supplied a complete example, which would be good in this case > because what you are suggesting could be a serious bug in R or a pa

Re: [R] Random Seed Location

2018-03-04 Thread Duncan Murdoch
On 04/03/2018 5:54 PM, Henrik Bengtsson wrote: The following helps identify when .GlobalEnv$.Random.seed has changed: rng_tracker <- local({ last <- .GlobalEnv$.Random.seed function(...) { curr <- .GlobalEnv$.Random.seed if (!identical(curr, last)) { warning(".Random.seed

Re: [R] Random Seed Location

2018-03-04 Thread Henrik Bengtsson
The following helps identify when .GlobalEnv$.Random.seed has changed: rng_tracker <- local({ last <- .GlobalEnv$.Random.seed function(...) { curr <- .GlobalEnv$.Random.seed if (!identical(curr, last)) { warning(".Random.seed changed") last <<- curr } TRUE } }) a

Re: [R] Random Seed Location

2018-03-04 Thread Gary Black
Thank you, everybody, who replied! I appreciate your valuable advise! I will move the location of the set.seed() command to after all packages have been installed and loaded. Best regards, Gary Sent from my iPad > On Mar 4, 2018, at 12:18 PM, Paul Gilbert wrote: > > On Mon, Feb 26, 2018 at

Re: [R] Random Seed Location

2018-03-04 Thread Paul Gilbert
On Mon, Feb 26, 2018 at 3:25 PM, Gary Black wrote: (Sorry to be a bit slow responding.) You have not supplied a complete example, which would be good in this case because what you are suggesting could be a serious bug in R or a package. Serious journals require reproducibility these days. For

Re: [R] Random Seed Location

2018-02-26 Thread Jeff Newmiller
I am willing to go out on that limb and say the answer to the OP question is yes, the RN sequence in R should be reproducible. I agree though that it doesn't look like he is actually taking care not to run code that would disturb the generator. -- Sent from my phone. Please excuse my brevity.

Re: [R] Random Seed Location

2018-02-26 Thread William Dunlap via R-help
If your computations involve the parallel package then set.seed(seed) may not produce repeatable results. E.g., > cl <- parallel::makeCluster(3) # Create cluster with 3 nodes on local host > set.seed(100); runif(2) [1] 0.3077661 0.2576725 > parallel::parSapply(cl, 101:103, function(i)runif(2, i,

Re: [R] Random Seed Location

2018-02-26 Thread Bert Gunter
In case you don't get an answer from someone more knowledgeable: 1. I don't know. 2. But it is possible that other packages that are loaded after set.seed() fool with the RNG. 3. So I would call set.seed just before you invoke each random number generation to be safe. Cheers, Bert Bert Gunte

[R] Random Seed Location

2018-02-26 Thread Gary Black
Hi all, For some odd reason when running naïve bayes, k-NN, etc., I get slightly different results (e.g., error rates, classification probabilities) from run to run even though I am using the same random seed. Nothing else (input-wise) is changing, but my results are somewhat different from run