x1 <- c('H','T','T','H','H','H','T','T','T','T','T','T','T','H','H',
'H','T','H','T','H','H','H','T','H','H','H','T','H','T','H')
runs.test(x1)
## $Z
## [1] -0.1617764
## $p.value
## [1] 0.8714819
x2 <- rep(c(0, 1), 50)
runs.test(x2)
## $Z
## [1] 9.849873
## $p.value
## [1] 0
# Which sequence is random?
x3 <- c(1,1,0,1,0,1,0,1,0,0,1,0,1,1,0,0,1,1,1,0,1,0,1,1,1,
0,0,1,0,0,1,0,0,0,1,0,1,0,1,1,0,1,0,0,1,1,1,0,1)
x4 <- c(0,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,0,1,0,0,1,0,0,0,0,
1,0,1,0,1,1,1,0,0,0,0,0,1,0,1,0,1,1,0,0,1,1,1,0)
runs.test(x3) # null hypotheses rejected at 0.05 level
## $Z
## [1] 2.05555
## $p.value
## [1] 0.03982587
runs.test(x4) # randomness is very probable
## $Z
## [1] 0.002947558
## $p.value
## [1] 0.9976482
Run the code above in your browser using DataLab