About the Runs Test
This calculator runs the Wald-Wolfowitz runs test on a binary sequence, such as wins and losses, heads and tails, or up and down price days, to check whether the order of values looks statistically random or shows a detectable pattern of clustering or alternation. It is a nonparametric test that only looks at the sequence of runs, not the values' magnitude.
How It Works
You paste a sequence containing exactly two distinct values, separated by commas or spaces. The calculator counts the total number of runs (unbroken streaks of the same value), then compares that count to the number of runs you would expect under a truly random ordering given how many of each value appear. The result is a z-statistic measuring how far the observed run count deviates from that expectation.
Formula & Methodology
Count each value's total occurrences (countA and countB) and count the total runs by scanning the sequence and incrementing whenever consecutive values differ, starting the count at 1. Plug both counts into the expected-runs and variance formulas above, then subtract expected from observed runs and divide by the square root of the variance to get the z-statistic.
Examples
Default 15-value sequence
For the sequence 1,1,0,1,0,0,0,1,1,0,1,0,0,1,1 (8 ones, 7 zeros), there are 9 runs against an expected 8.47, giving a variance of about 3.45 and a z-statistic of roughly 0.29, well inside the ±1.96 range, so the ordering looks consistent with randomness.
Perfectly alternating sequence
For 1,0,1,0,1,0,1,0,1,0 (5 ones, 5 zeros), every adjacent pair differs, producing 10 runs against an expected 6, a variance of about 2.22, and a z-statistic near 2.68, which exceeds ±1.96 and flags the sequence as alternating far more than chance would predict.
Advantages
- Detects patterns in ordering that a simple frequency count of each value would completely miss.
- Requires no assumption about the underlying distribution, since it works purely from the sequence of runs.
- Distinguishes between two opposite failure modes, clustering (too few runs) and over-alternation (too many runs), rather than lumping both into a single generic flag.
Common Mistakes
- Treating a non-significant z-statistic as proof the sequence is truly random, when it only means the test found no detectable pattern in this particular check.
- Running the test on a sequence with more than two distinct categories without first collapsing it into a binary form, which the calculator will reject as invalid input.
- Ignoring the sign of the z-statistic, which distinguishes a clustering pattern (negative, too few runs) from an alternating pattern (positive, too many runs).
Edge Cases to Watch For
- The sequence must contain at least 4 values and exactly 2 distinct values; anything else returns an input error.
- If the computed variance is zero or negative, the calculator returns an error asking for a longer or more balanced sequence, since the z-statistic cannot be computed in that case.
- A z-statistic beyond about ±1.96 is treated as evidence against randomness at the 95% confidence level; too few runs indicates clustering, too many indicates over-regular alternation.
- The test only evaluates the order of the two values, not their frequency balance, so a sequence with an unusual mix of the two values can still test as random if the order itself is unpatterned.
Common Use Cases
- Analysts checking whether a sequence of trading days, coin flips, or quality-control pass/fail results shows hidden patterning.
- Auditors and quality assurance teams screening data entry logs or randomization procedures for unexpected regularity.
- Statistics students and researchers verifying that a random number generator or sampling process produced a genuinely unordered sequence.