Skip to content
Prev 391098 / 398506 Next

How important is set.seed

I would also disagree with your rephrasing. What is the point in characterizing if there is no understanding? What one wants is to understand the variability in outcome caused by including a random element in the model if the focus is on the random numbers. It may also be that one wants to understand the variability in outcome if one were to repeat an experiment. One approach is to split a dataset into testing and training sets, and use the RNG to decide which observation goes into which set. However, every run will give a slightly different answer.
The random number generator is then used in place of a permutation test where the number of permutations is too large for current computational effort.

I assume what the OP was asking is whether the conclusion(s) of two (or more) models were the same given the range in outcomes produced by the random number generator(s). The only way to address this is to characterize the distribution of model outcomes from different runs with different random seeds. Examine that characterization and hope for understanding.

Tim

From: Bert Gunter <bgunter.4567 at gmail.com>
Sent: Tuesday, March 22, 2022 2:03 PM
To: Ebert,Timothy Aaron <tebert at ufl.edu>
Cc: Neha gupta <neha.bologna90 at gmail.com>; r-help at r-project.org
Subject: Re: [R] How important is set.seed

[External Email]
"rather to understand how the choice of seed influences final model output."

No! Different seeds just produce different streams of (pseudo)-random numbers.  Hence there cannot be any "understanding" of how "choice of seed" influences results.  Presumably, what you meant is to characterize the variability in results from the procedure due to its incorporation of randomness in what it does. Re-read Jeff's last post.  This does *not* require set.seed() at all.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Mar 22, 2022 at 9:55 AM Ebert,Timothy Aaron <tebert at ufl.edu<mailto:tebert at ufl.edu>> wrote:
So step 1 is not to compare models, rather to understand how the choice of seed influences final model output. Once you have a handle on this issue, then work at comparing models.
Tim

From: Neha gupta <neha.bologna90 at gmail.com<mailto:neha.bologna90 at gmail.com>>
Sent: Tuesday, March 22, 2022 12:19 PM
To: Bert Gunter <bgunter.4567 at gmail.com<mailto:bgunter.4567 at gmail.com>>
Cc: Ebert,Timothy Aaron <tebert at ufl.edu<mailto:tebert at ufl.edu>>; r-help at r-project.org<mailto:r-help at r-project.org>
Subject: Re: [R] How important is set.seed

[External Email]
I read a paper two days ago (and that's why I then posted here about set.seed) which used interpretable machine learning.

According to the authors, different explanations (of the black-box models) will be produced by the ML models if different seeds are used or never used.
On Tue, Mar 22, 2022 at 5:12 PM Bert Gunter <bgunter.4567 at gmail.com<mailto:bgunter.4567 at gmail.com>> wrote:
OK, I'm somewhat puzzled by this discussion. Maybe I'm just clueless. But...

1. set.seed() is used to make any procedure that uses R's
pseudo-random number generator -- including, for example, sampling
from a distribution, random data splitting, etc. -- "reproducible".
That is, if the procedure is repeated *exactly,* by invoking
set.seed() with its original argument values (once!) *before* the
procedure begins, exactly the same results should be produced by the
procedure. Full stop. It does not matter how many times random number
generation occurs within the procedure thereafter -- R preserves the
state of the rng between invocations (but see the notes in ?set.seed
for subtle qualifications of this claim).

2. Hence, if no (pseudo-) random number generation is used, set.seed()
is irrelevant. Full stop.

3. Hence, if you don't care about reproducibility (you should! -- if
for no other reason than debugging), you don't need set.seed()

4. The "randomness" of any sequence of results from any particular
set.seed() arguments (including further calls to the rng) is a complex
issue. ?set.seed has some discussion of this, but one needs
considerable expertise to make informed choices here. As usual, we
untutored users should be guided by the expert recommendations of the
Help file.

*** If anything I have said above is wrong, I would greatly appreciate
a public response here showing my error.***

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Mar 22, 2022 at 7:48 AM Neha gupta <neha.bologna90 at gmail.com<mailto:neha.bologna90 at gmail.com>> wrote:

  
  
Message-ID: <BN6PR2201MB155308A07F577E2E8784D47ECF179@BN6PR2201MB1553.namprd22.prod.outlook.com>
In-Reply-To: <CAGxFJbQOsjcYkn563DvrpZLGTmX4XUn8ttOgzuvUe5CKcv5i+A@mail.gmail.com>