terrycojones / ggboxplot-random-seed-demo

A Shiny app showing how ggboxplot resets the RNG to a constant value each time it is used

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This simple app (based on this Shiny demo) highlights the current (version 0.4.0, 2021-11-19) behavior of ggboxplot (in ggpubr), which calls set.seed(123) each time it is used. This resets the random number generator (RNG), resulting in subsequent random numbers being identical to those already generated.

To see this, leave the "Set seed before getting samples?" radio button on "No", and change the number of observations. The data (coming from a call to rnorm, shown beneath the box plot) will always have the same initial values.

If you change "Set seed before getting samples?" to "Yes", the RNG seed is set prior to each call to get a new dataset to get around ggboxplot setting the seed to the constant 123 value each time it is used. The data are then different on each sample, as would be expected.

There is a GitHub issue here to (hopefully) change this behavior.

The code for this app can be found here.

About

A Shiny app showing how ggboxplot resets the RNG to a constant value each time it is used


Languages

Language:R 100.0%