Runs Test (Wald-Wolfowitz) Calculator
Statistical tests
- Runs: the sequence shows 18 runs, with 14 of one kind and 16 of the other, 30 observations in total.
- Expectation: under random ordering the expected runs are 2 x 14 x 16 / 30 + 1 = 15.93, with standard deviation 2.679.
- Deviation: (18 - 15.93) / 2.679 = 0.77; the continuity-corrected value is 0.58.
- Runs test result: z = 0.77, which does not reject randomness at the 5% level against 1.96.
Reduce any sequence to two kinds of event — up and down, pass and fail, above and below the median — and a pattern question remains that no average can answer: are the two kinds shuffled at random, or do they clump and alternate more than chance allows? The runs test, published by Wald and Wolfowitz in 1940, answers with a single count: the number of runs, the maximal stretches of one kind in a row.
Random shuffling predicts how many runs a sequence should show, given only how many of each kind it contains. Far fewer runs than expected means the kinds are clustering — a trend, a regime, a machine drifting. Far more means they are alternating with suspicious regularity — overcorrection, oscillation, a human faking randomness by never repeating themselves. The test compresses both failure modes into one z statistic.
Enter the runs you counted and the two group sizes. The calculator returns the z statistic with the expected runs, the standard deviation and the continuity-corrected z alongside, so the verdict can be read against the familiar 1.96 line.
Worked examples
Runs test on a near-random sequence
(18 · 14 · 16)
| Runs test z | 0.77 |
| Expected runs under randomness | 15.93 |
| Standard deviation of runs | 2.679 |
| z with continuity correction | 0.58 |
Runs test on a clustered sequence
(9 · 20 · 12)
| Runs test z | -2.69 |
| Expected runs under randomness | 16.00 |
| Standard deviation of runs | 2.603 |
| z with continuity correction | -2.50 |
Runs test on a balanced sequence
(27 · 25 · 25)
| Runs test z | 0.29 |
| Expected runs under randomness | 26.00 |
| Standard deviation of runs | 3.499 |
| z with continuity correction | 0.14 |
Counting runs
A run is an unbroken stretch of the same kind: the sequence A A B A B B B A holds five runs. Counting is the whole data reduction — the test never looks at magnitudes, spacings or values, only at the order of the two kinds. That austerity is its strength (no distributional assumptions anywhere) and its limit (a sequence can pass the runs test while failing every other randomness check devised).
In the first worked example the sequence shows 18 runs among 14 of one kind and 16 of the other. Random ordering of that composition expects 15.93 runs, so the observed sequence alternates a little more than chance predicts — but with a standard deviation of 2.679 runs, the excess is well inside ordinary luck, and the z of 0.77 says so.
| Pattern | Runs vs expected | Usual suspect |
|---|---|---|
| Far too few runs | Strongly negative z | Trend, drift, clustering, regime change |
| Somewhat few runs | Moderately negative z | Positive autocorrelation, sticky process |
| Near expected | z inside about +/-1 | Consistent with random ordering |
| Far too many runs | Strongly positive z | Alternation, overcorrection, faked randomness |
The normal approximation
Under random ordering, the runs count has a known mean — 2 n1 n2 / (n1 + n2) + 1 — and a known variance, so for reasonably sized samples its distribution is approximately normal and the z statistic follows. The approximation is the standard one once both group sizes reach about ten; below that, exact tables for the runs distribution replace it, because the discreteness of small counts bends the normal curve too far.
The second worked example shows the approximation earning its keep. Only 9 runs appear where 16.00 are expected from 20 of one kind and 12 of the other: the deficit is 7 runs against a standard deviation of 2.603, giving z = -2.69, beyond the 1.96 line. Something in that sequence is clumping — the test cannot say what, but it has done its job of pointing. The continuity correction, which nudges the count half a run toward the mean before standardising, softens the verdict slightly to -2.50 without changing it.
- Code the sequence into exactly two kinds before counting; the median split is the classic choice for continuous data.
- Both group sizes near or above 10 keep the normal approximation honest.
- The continuity correction matters most for small samples and borderline z values.
- A significant result indicts the ordering, not any particular cause.
- Runs above and below a trend line, rather than the median, adapt the test to drifting series.
Worked examples
Example 1: Number of runs R 18; Count of first kind n1 14; Count of second kind n2 16. Runs test z = 0.77. Supporting values: Expected runs under randomness 15.93; Standard deviation of runs 2.679; z with continuity correction 0.58. Runs: the sequence shows 18 runs, with 14 of one kind and 16 of the other, 30 observations in total. Expectation: under random ordering the expected runs are 2 x 14 x 16 / 30 + 1 = 15.93, with standard deviation 2.679. Deviation: (18 - 15.93) / 2.679 = 0.77; the continuity-corrected value is 0.58. Runs test result: z = 0.77, which does not reject randomness at the 5% level against 1.96.
Example 2: Number of runs R 9; Count of first kind n1 20; Count of second kind n2 12. Runs test z = -2.69. Supporting values: Expected runs under randomness 16.00; Standard deviation of runs 2.603; z with continuity correction -2.50. Runs: the sequence shows 9 runs, with 20 of one kind and 12 of the other, 32 observations in total. Expectation: under random ordering the expected runs are 2 x 20 x 12 / 32 + 1 = 16.00, with standard deviation 2.603. Deviation: (9 - 16.00) / 2.603 = -2.69; the continuity-corrected value is -2.50. Runs test result: z = -2.69, which rejects randomness at the 5% level against 1.96.
Example 3: Number of runs R 27; Count of first kind n1 25; Count of second kind n2 25. Runs test z = 0.29. Supporting values: Expected runs under randomness 26.00; Standard deviation of runs 3.499; z with continuity correction 0.14. Runs: the sequence shows 27 runs, with 25 of one kind and 25 of the other, 50 observations in total. Expectation: under random ordering the expected runs are 2 x 25 x 25 / 50 + 1 = 26.00, with standard deviation 3.499. Deviation: (27 - 26.00) / 3.499 = 0.29; the continuity-corrected value is 0.14. Runs test result: z = 0.29, which does not reject randomness at the 5% level against 1.96.
Too few, too many
The two tails accuse different culprits, and reading them apart is the test's practical value. Too few runs is the signature of persistence: bull and bear regimes in markets, a tool wearing gradually in a production line, weather systems parking over a region. The sequence remembers itself. Too many runs is the signature of anti-persistence: a controller overcorrecting, a gambler alternating bets, a thermostat hunting around its set point. The sequence remembers itself in the opposite way, by avoiding repetition.
The balanced third example — 27 runs from 25 of each kind, against 26.00 expected — lands at z = 0.29, about as unremarkable as a sequence can be. That null-looking result is itself informative: whatever generated the sequence, its ordering carries no detectable memory of either kind, and suspicion should move to other properties — the counts, the magnitudes, the spacings — that the runs test deliberately ignores.
The runs test in practice
Quality control adopted the test early: a run of consecutive above-target measurements on a control chart is exactly a runs deficit, and the Western Electric rules that still govern production floors are the runs test wearing overalls. Clinical and psychological research uses it on binary outcome sequences; finance applies it to the signs of returns, where significant clustering of up-days and down-days argues against the random-walk picture in its strictest form.
Its modern role is usually as a first screen — cheap, assumption-free and hard to argue with. A sequence that fails it has a documented ordering problem worth investigating; a sequence that passes has cleared the lowest bar of randomness, no more. Battery-of-tests suites for random number generators include it for exactly that reason: necessary, nowhere near sufficient, and embarrassing to fail.
What the test cannot see
Because only the order of two kinds enters the count, entire families of non-randomness pass straight through. A sequence can alternate in perfect runs-test innocence while its magnitudes follow a rigid pattern — up a little, down a lot, up a little, down a lot. A periodic sequence whose period happens to produce an average runs count passes too. And the test says nothing about whether the two kinds occur in the right proportions; that is a separate question for a separate test.
The honest workflow is therefore layered: runs for ordering, a proportion test for composition, autocorrelation for graded memory, and a distributional test for shape — several of which live on this site. The runs test's contribution to that stack is the one thing none of the others check as directly: whether the sequence's own arrangement, stripped of everything else, already betrays a pattern. For a statistic built from a single count, that is a respectable amount of truth.
FAQs
What z does the first example give?
0.77, from 18 observed runs against 15.93 expected — comfortably consistent with random ordering.
What standard deviation goes with it?
2.679 runs, from the two group sizes of 14 and 16.
What z does the clustered example give?
-2.69: only 9 runs where 16.00 were expected, a significant deficit at the 5% level.
What does the continuity correction do there?
It softens the statistic to -2.50 by moving the count half a run toward the mean before standardising.
What z does the balanced example give?
0.29, from 27 runs against 26.00 expected with equal groups of 25.
What does a strongly positive z mean?
Too many runs: the kinds alternate more than chance allows, the classic signature of overcorrection or hand-faked randomness.