Next: Tests for Auto-correlation Up: Tests for Random Numbers Previous: Frequency test

## Runs Tests

1. Runs up and down

• The runs test examines the arrangement of numbers in a sequence to test the hypothesis of independence.

• See the tables on page 303. With a closer look, the numbers in the first table go from small to large with certain pattern. Though these numbers will pass the uniform tests in previous section, they are not quite independent.

• A run is defined as a succession of similar events proceded and followed by a different event.

E.g. in a sequence of tosses of a coin, we may have

  H T T H H T T T H T

The first toss is proceded and the last toss is followed by a "no event". This sequence has six runs, first with a length of one, second and third with length two, fourth length three, fifth and sixth length one.

• A few features of a run
• two characteristics: number of runs and the length of run
• an up run is a sequence of numbers each of which is succeeded by a larger number; a down run is a squence of numbers each of which is succeeded by a smaller number

• If a sequence of numbers have too few runs, it is unlikely a real random sequence. E.g. 0.08, 0.18, 0.23, 0.36, 0.42, 0.55, 0.63, 0.72, 0.89, 0.91, the sequence has one run, an up run. It is not likely a random sequence.

• If a sequence of numbers have too many runs, it is unlikely a real random sequence. E.g. 0.08, 0.93, 0.15, 0.96, 0.26, 0.84, 0.28, 0.79, 0.36, 0.57. It has nine runs, five up and four down. It is not likely a random sequence.

• If a is the total number of runs in a truly random sequence, the mean and variance of a is given by

and

• For , the distribution of a is reasonably approximated by a normal distribution, . Converting it to a standardized normal distribution by

that is

• Failure to reject the hypothesis of independence occurs when , where the is the level of significance.

• See Figure 8.3 on page 305

• See Example 8.8 on page 305

2. Runs above and below the mean.

• The previous test for up runs and down runs are important. But they are not adquate to assure that the sequence is random.

• Check the sequence of numbers at the top of page 306, where they pass the runs up and down test. But it display the phenomenon that the first 20 numbers are above the mean, while the last 20 are below the mean.

• Let and be the number of individual observations above and below the mean, let b the total number of runs.

• For a given and , the mean and variance of b can be expressed as

and

• For either or greater than 20, b is approximately normally distributed

• Failure to reject the hypothesis of independence occurs when , where is the level of significance.

• See Example 8.9 on page 307

3. Runs test: length of runs.

• The example in the book:
0.16, 0.27, 0.58, 0.63, 0.45, 0.21, 0.72, 0.87, 0.27, 0.15, 0.92, 0.85,...

If the same pattern continues, two numbers below average, two numbers above average, it is unlikely a random number sequence. But this sequence will pass other tests.

• We need to test the randomness of the length of runs.

• Let be the number of runs of length i in a sequence of N numbers. E.g. if the above sequence stopped at 12 numbers (N = 12), then and

Obviously is a random variable. Among various runs, the expected value for runs up and down is given by

and

• The number of runs above and below the mean, also random variables, the expected value of is approximated by

where E(I) the approximate expected length of a run and is the approximate probability of length .

• is given by

• E(I) is given by

• The approximate expected total number of runs (of all length) in a sequence of length N is given by

(total number divided by expected run length).

• The appropriate test is the chi-square test with being the observed number of runs of length i

where L = N - 1 for runs up and down, L = N for runs above and belown the mean.

• See Example 8.10 on page 308 for length of runs up and down.

• See Example 8.11 on page 311 for length of above and below the mean.

Next: Tests for Auto-correlation Up: Tests for Random Numbers Previous: Frequency test
Meng Xiannong 2002-10-18