Runs Test for Randomness Calculator Formula

Understand the math behind the runs test for randomness calculator. Each variable explained with a worked example.

Formulas Used

Expected Runs

expected_runs = 1 + (2 * n1 * n2) / (n1 + n2)

Std Dev

std_runs = sqrt((2 * n1 * n2 * (2 * n1 * n2 - n1 - n2)) / (pow(n1 + n2, 2) * (n1 + n2 - 1)))

Z Statistic

z_stat = (runs - (1 + (2 * n1 * n2) / (n1 + n2))) / sqrt((2 * n1 * n2 * (2 * n1 * n2 - n1 - n2)) / (pow(n1 + n2, 2) * (n1 + n2 - 1)))

Variables

VariableDescriptionDefault
n1Count Type A15
n2Count Type B10
runsNumber of Runs8

How It Works

Wald-Wolfowitz Runs Test

mu = 1 + 2*n1*n2/(n1+n2)

Tests randomness of binary sequences.

Worked Example

15 As, 10 Bs, 8 runs.

n1 = 15n2 = 10runs = 8
  1. 01Expected = 13
  2. 02Z = -2.15, not random