mardi 12 janvier 2021

R: Getting around periodic random numbers

I'm building a distribution of proportions of random values lower than a specified threshold.

ret = c(); thr = 0.5; n = 15; reps = 10000
for (x in 1:reps) {
  prop = sum(runif(n, 0, 1) < thr) / n
  ret = c(ret, prop)
}
plot(density(ret), main=NA)

The resulting density distribution is highly periodic and is not something one would theoretically expect:

enter image description here

I presume this has something to do with the periodicity of the random number generator. Is there any way around this?




Aucun commentaire:

Enregistrer un commentaire