### Runs Test

 P(X = x)  = P(X ≤ x)  = P(X ≥ x)  = $n_1 =$ $n_2=$ $x=$

This applet computes probabilities for the Wald–Wolfowitz Runs Test. If there is a sequence of $n_1$ elements of type 1 and $n_2$ elements of type 2, then the test specifies

• $H_0:$ the sequence is random (mutually independent)
• $H_a:$ the sequence is not random (not mutually independent)
The test is based upon the number of "runs" in the sequence (see the example below).

#### Directions

• Enter the number of events of type 1 in the $n_1$ box
• Enter the number of events of type 2 in the $n_2$ box.
• Hitting "Tab" or "Enter" on your keyboard will plot the probability mass function (pmf) of the number of runs $X$ (assuming $H_0$ is true).

To compute a probability, select $P(X=x)$ from the drop-down box, enter a numeric $x$ value, and press "Enter" on your keyboard. The probability $P(X=x)$ will appear in the pink box. Select $P(X \leq x)$ from the drop-down box for a left-tail probability (this is the cdf).

#### Example

If $n_1=2$ and $n_2=3$, then there are ${5 \choose 2}=10$ possible sequences.

• There are 2 sequences with 2 runs: '11222', '22211'.
• There are 3 sequences with 3 runs: '21122', '22112', and '12221'.
• There are 4 sequences with 4 runs: '12122', '12212', 21221', and '22121'.
• There is 1 sequence with 5 runs: '21212'.
Thus, assuming the sequence is random, $P(X=2)=0.2,$ $P(X=3)=0.3,$ $P(X=4)=0.4,$ and $P(X=5)=0.1$.

#### Details

• Probability mass function (pmf):
If $x$ is even, $$f(x)=P(X=x)= \frac{2 {n_1-1 \choose \frac{x}{2}-1} {n_2-1 \choose \frac{x}{2}-1}} {{n_1 + n_2 \choose n_1}}$$
• If $x$ is odd, $$f(x)=P(X=x)= \frac{{n_1-1 \choose \frac{x-1}{2}} {n_2-1 \choose \frac{x-1}{2}-1} + {n_1-1 \choose \frac{x-1}{2}-1} {n_2-1 \choose \frac{x-1}{2}}} {{n_1 + n_2 \choose n_1}}$$
• Support:
If $n_1 \ne n_2$, then $x=2,\ldots,2\, min(n_1,n_2)+1$
If $n_1 = n_2$, then $x=2,\ldots,2\, min(n_1,n_2)$
• $\mu=E(X)=\frac{2 n_1 n_2}{n_1 + n_2} + 1$
• $\sigma^2=Var(X)= \frac{2 n_1 n_2 (2 n_1 n_2 - n_1 - n_2)} {(n_1 + n_2)^2(n_1 + n_2 - 1)}$
• $\sigma=SD(X)=\sqrt{\frac{2 n_1 n_2 (2 n_1 n_2 - n_1 - n_2)} {(n_1 + n_2)^2(n_1 + n_2 - 1)}}$