Skip to content
Prev 55889 / 63421 Next

Bias in R's random integers?

On 20/09/2018 11:01 AM, Radford Neal wrote:
There are two bugs, one recent one (allowing fractional m to slip 
through) and one old one (the bias).  The test above shows the bias with 
m+1, i.e. in R 2.15.1

 > x <- sample(m + 1, 1000000, replace = TRUE)
 > table(x %% 2)

      0      1
466739 533261


and you can see it in the original m with

   x <- sample(m, 1000000, replace = TRUE)
   plot(density(x[x %% 2 == 0]))

Duncan Murdoch