[R] Is the random number generator biased?

Oliver Faulhaber oliverfaulhaber at gmx.de
Mon Mar 26 20:48:50 CEST 2007


Hi all,

in order to verify some results I did the following test in R (2.4.1., 
windows system):

X <- cumsum(rnorm(1000000))
for (i in 1:1000) {
  tmp                   <- seq(1,length(X),by=i)
  X.coarse              <- X[tmp]
  X.return              <- diff(X.coarse)
  X.scale.mean[i]       <- mean(X.return)
}
plot(X.scale.mean,type="l")

As X is a random walk with increments following a standard normal 
distribution, the mean of X should be 0. Further more, each "piece" of 
the random walk should also have zero mean - independent of its length.

Why is it then, that the plot of X.scale.mean shows a clear linear trend?

Is the generation of the random walk in some way biased or do I just 
miss some point?

Thanks for any enlighting
replies in advance
Oliver



More information about the R-help mailing list