Runs Test Calculator
The Wald-Wolfowitz runs test asks whether the ORDER of the observations in a sequence is random. The values are coded in binary form as "above" or "below" a cut point (the median by default); each block of consecutive identical signs is called a run, and the number of runs R is compared with the value expected under randomness.
What sets it apart from other tests is that it examines the pattern rather than the central tendency: the same set of observations gives a different result when supplied in a different order. FEWER runs than expected mean clustering or a trend (autocorrelation); MORE runs mean excessive alternation (oscillation) — both are departures from randomness. This calculator reports R, n1, n2, the expected R, the standard deviation, z and p with and without the continuity correction, a table coding the sequence as above/below, and a set of run charts.
Wald-Wolfowitz Runs Test Formulas
Coding: xᵢ > cut → "A" , xᵢ < cut → "B" , xᵢ = cut → dropped
n₁, n₂: counts of observations coded above and below
Number of runs: R = the number of consecutive same-sign blocks
Expected value: E(R) = 2·n₁·n₂ / (n₁ + n₂) + 1
Variance: σ²_R = 2n₁n₂(2n₁n₂ − n₁ − n₂) / [ (n₁+n₂)² (n₁+n₂−1) ]
z statistic: z = (R − E(R)) / σ_R
Continuity corr.: z_c = (|R − E(R)| − 0.5) / σ_R
Acceptance range: E(R) ± z_{α/2} · σ_RThe null hypothesis is that the order of the observations is random, and the test is two-tailed: both too few and too many runs lead to rejecting H₀. The normal approximation is regarded as reliable when n₁ ≥ 10 and n₂ ≥ 10; for smaller counts, use the continuity-corrected version or an exact runs distribution table.
How to Calculate
- Enter the values in the order they were observed: the time, production number, or row order must be preserved — sorted data carries no information for this test.
- Choose the cut-point criterion: the median is the most common choice, and a manual threshold of 0 is the natural one for regression residuals.
- Decide which p-value to report; if n1 or n2 is below 20, prefer the continuity-corrected version.
- Compare the number of runs R with the expected E(R) and look at the acceptance interval: if R falls outside it, randomness is rejected.
- Interpret the direction: too few runs mean clustering and trend, too many mean excessive alternation.
- Study the long blocks in the sign table and the sequence chart to see which part of the sequence the pattern comes from.
Worked Examples
A shift in quality control measurements
The median is 12.50; 10 observations lie above it and 10 below. Only 5 runs are counted while the expected value is 11.00: with z = -2.757 and p = 0.006 the sequence is not random. The process ran high in the first half and low in the second, so the measurements are clustered; this is a typical shift pattern.
Number of runs (R): 5 · Expected number of runs E(R): 11.000 · Standard deviation of the number of runs: 2.1764
An excessively alternating sequence — too many runs
The values switch regularly between low and high: 14 runs are counted in 14 observations, whereas the expected value is 8.00. With a continuity-corrected z = 3.060 and p = 0.002, randomness is rejected. This pattern usually points to an alternating measurement error or to negative autocorrelation.
Number of runs (R): 14 · Expected number of runs E(R): 8.000 · Standard deviation of the number of runs: 1.7974
A measurement sequence that looks random
The median is taken as 22.50; 10 observations lie above that value and 10 below. 12 runs are observed while the expected value is 11.00, and σ_R = 2.1764; z = 0.459 gives p = 0.646, so nothing contradicts randomness. The observed R stays inside the 95% acceptance interval (6.73 – 15.27).
Number of runs (R): 12 · Expected number of runs E(R): 11.000 · Standard deviation of the number of runs: 2.1764