Runs Test Calculator (Wald-Wolfowitz)
Test whether a binary sequence is random using the Wald-Wolfowitz runs test. A run is a consecutive sequence of identical values. Too few or too many runs compared to what is expected under randomness indicates a non-random pattern.
The Wald-Wolfowitz runs test is a non-parametric test for detecting non-randomness in a sequence of two types of elements (coded as 0 and 1). A 'run' is a maximal subsequence of identical values. For example, the sequence 1 1 0 0 1 0 has four runs: (1 1), (0 0), (1), (0).
Under the null hypothesis of randomness, the expected number of runs is E(R) = (2n1n2)/(n1+n2) + 1, where n1 and n2 are the counts of each type. The variance is Var(R) = (2n1n2*(2n1n2 - n1 - n2)) / ((n1+n2)^2 * (n1+n2 - 1)). For moderate sample sizes, the standardized statistic Z = (R - E(R)) / sqrt(Var(R)) is approximately standard normal.
Too few runs suggest clustering or positive autocorrelation (similar values tend to group together). Too many runs suggest alternation or negative autocorrelation. The runs test is widely used in quality control, time series analysis, and testing the randomness of residuals from regression models.