A Look at Random Seeds in R… Or: “85, why can’t you be more like 548?”

[This article was first published on You Know, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Have you ever wondered whether the set.seed() function in R has any quirkiness? This analysis was inspired by a Stack Overflow posting by Wolfgang and I incorporate some of his code.

For each seed (1-1000, for this analysis), I took the mean and standard deviation of the first 1,000 random numbers. Then I get the percent of the density function that intersects with the normal curve as well as a distance from the origin function (0,1 in this case).

With the resulting points, I find the most interesting ones based on min/max mean, min/max sd, max distance from shifted origin for points in each of the quadrants, overall max distance, and the point closest to the center.

Below is the summary of interesting points.

##      type seed     mu    sd  dist intersect
## 1  mu_min   85 -0.110 1.008 0.110     0.956
## 2  mu_max  501  0.104 1.002 0.104     0.959
## 3  sd_min  180 -0.005 0.921 0.079     0.960
## 4  sd_max  168  0.002 1.065 0.065     0.969
## 5      q1  501  0.104 1.002 0.104     0.959
## 6      q2   85 -0.110 1.008 0.110     0.956
## 7      q3  713 -0.075 0.935 0.100     0.957
## 8      q4  394  0.090 0.988 0.091     0.964
## 9     out   85 -0.110 1.008 0.110     0.956
## 10     in  548  0.000 1.000 0.000     1.000
## 11    sim  548  0.000 1.000 0.000     1.000
## 12   diff   85 -0.110 1.008 0.110     0.956

Below is a chart showing the overlap of the most similar point and a chart showing the overlap of the least similar point. Thanks again to Wolfgang for this code chunk.
Top:  Seed 548; Bottom:  Seed 85
As you can see, even the worst point has an overlap of 95.6%. Point 548 is almost perfect. However since there are values that could cause issues, it might be a good practice to pick different seeds over time. You could throw a dart or a manager could assign the seed as part of the requirements document. This practice might mitigate the risk of an analyst’s intentionally biased seed selection.

To leave a comment for the author, please follow the link and comment on their blog: You Know.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)