Problem with set.seed()

Being an Undergrad in Statistics, we require the daily usage of R as a Statistical Software for simulations. But unfortunately I am facing some issues with the set.seed() command for generating the pseudo random numbers.

The problem is, running a particular (say set.seed(987654321)) seed and then drawing random numbers from let's say specific distributions like normal (using rnorm()) and Chi Squared ( using rchisq()) is giving me different results on two different machines whereas I am using the same and the most latest versions of both R-studio and the base R (Gui). Why this is happening?

Any help in this regard, will be highly appreciated.

Hi, and welcome. For reference see the FAQ: How to do a minimal reproducible example reprex for beginners. Even on this simple a question, it helps to have the specific function and arguments being used.

First, just as a check. Are you invoking the seed for each run?

Not exactly, the setting of seed is being invoked only once before we enter the simulation loop and start drawing repeated samples.

1 Like

Then try invoking it each time.

you and I have different computers, what results do you get on rchisq with this set up ?

rchisq(5, df = 0, ncp = 2.)
# 7.920865 3.955410 0.904365 1.988855 0.000000

Same here. However, running a second time without reseeding yields a different result. That was the motivation for my question above.
rchisq(5, df = 0, ncp = 2.)
#> [1] 7.920865 3.955410 0.904365 1.988855 0.000000
rchisq(5, df = 0, ncp = 2.)
#> [1] 4.407804 0.000000 1.226219 0.000000 14.338174

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.