[R] Random numbers negatively correlated?

From: Christian Hennig <chrish_at_stats.ucl.ac.uk>
Date: Wed 28 Jun 2006 - 03:42:02 EST


Dear list,

I did simulations in which I generated 10000 independent Bernoulli(0.5)-sequences of length 100. I estimated p for each sequence and I also estimated the conditional probability that a one is followed by another one (which should be p as well). However, the second probability is significantly smaller than 0.5 (namely about 0.494, see below) and of course smaller than the direct estimates of p as well, indicating negative correlation between the random numbers.

See below the code and the results.
Did I do something wrong or are the numbers in fact negatively correlated? (A type I error is quite unlikely with a
p-value below 2.2e-16.)

Best,
Christian

set.seed(123456)
n <- 100
p <- 0.5
simruns <- 10000
est <- est11 <- numeric(0)
for (i in 1:simruns){
# if (i/100==round(i/100)) print(i)

     x <- rbinom(n,1,p)
     est[i] <- mean(x)
     x11 <- 3*x[2:n]-x[1:(n-1)]
     est11[i] <- sum(x11==2)/sum(x11==2 | x11==(-1))
     # x11==(-1): 0 follows 1, x11==2: 1 follows 1.
}

> print(mean(est))

[1] 0.499554
> print(sd(est)/sqrt(simruns))

[1] 0.0004958232
# OK

> print(mean(est11))

[1] 0.4935211
> print(sd(est11)/sqrt(simruns))

[1] 0.0007136213
# mean(est11)+2*sd(mean) < 0.495

> print(sum(est>est11))

[1] 5575
> binom.test(5575,10000)

         Exact binomial test

data: 5575 and 10000
number of successes = 5575, number of trials = 10000, p-value < 2.2e-16


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jun 28 03:52:34 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 28 Jun 2006 - 06:12:39 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.