Runs Test for Randomness Calculator (Median Split)

Runs Test for Randomness Calculator (Median Split)

Emerging AI Skill PRO

Enter Calculation

Separate values with commas, spaces or new lines.
Two-sided.

Formula

R‾=2n1n2n1+n2+1\bar{R} = \frac{2 n_1 n_2}{n_1 + n_2} + 1
Show calculation steps (2)
  1. Variance of runs

    sR2=2n1n2(2n1n2−n1−n2)(n1+n2)2(n1+n2−1)s_R^2 = \frac{2 n_1 n_2(2 n_1 n_2 - n_1 - n_2)}{(n_1+n_2)^2 (n_1+n_2-1)}

    Variance of runs under randomness.

  2. Z statistic

    Z=Data sequence→R−R‾sR,at Significance levelZ = \frac{\text{Data sequence} \to R - \bar{R}}{s_R}, \quad \text{at } \text{Significance level}

    Standardised number of runs from the data sequence, judged at the chosen significance level.

Usage stats

Advertisement

Results

Z statistic
1.3784
Observed runs R 14
Values above median (n1) 10
Values below median (n2) 10
Values equal to median (omitted) 0
Median 3.9500
Expected runs 11.0000
Standard deviation of runs 2.1764
Two-sided p-value 0.1681
Critical value 1.9600
Reject randomness (H0)? No
Small-sample warning Yes

Report an error on this page

What the runs test calculator does

This calculator applies the runs test for detecting non-randomness to an ordered sequence of numbers. Each value is coded as above (+) or below (-) the median, the runs in that pattern are counted, and the count is compared with what a random ordering would produce. It returns the number of runs, the expected number, the standard deviation, the Z statistic, a two-sided p-value and a reject or do-not-reject decision. It suits analysts checking residuals, process measurements or any time-ordered series for trends, clustering or oscillation.

Data points above and below a dashed median line, coded as plus and minus symbols and grouped into runs
Each value is coded as above (+) or below (−) the median, and each unbroken stretch of the same sign counts as one run.

How to use it

Enter the values in time order in the data field, separated by commas, semicolons, spaces or new lines, with a dot as the decimal separator. Then choose the two-sided significance level alpha (0.10, 0.05, 0.025 or 0.01). The order matters because the data are never sorted. At least two numeric values are needed, and at least one value must lie above and one below the median.

The formula

A run is a series of consecutive values with the same sign. With \(R\) observed runs, the test statistic is:

$$Z = \frac{R - \bar{R}}{s_R}$$

The expected runs and variance under the hypothesis of randomness are:

$$\bar{R} = \frac{2 n_1 n_2}{n_1 + n_2} + 1$$$$s_R^2 = \frac{2 n_1 n_2(2 n_1 n_2 - n_1 - n_2)}{(n_1+n_2)^2 (n_1+n_2-1)}$$

Here \(n_1\) is the count of values above the median, \(n_2\) the count below, \(R\) the observed runs, \(\bar{R}\) the expected runs and \(s_R\) the standard deviation of runs. The two-sided p-value is \(p = 2(1-\Phi(|Z|))\), where \(\Phi\) is the standard normal CDF. Randomness is rejected when \(|Z| > z_{1-\alpha/2}\).

Advertisement
Standard normal curve with both tails shaded beyond minus z and plus z critical values
The two-sided test rejects randomness when the observed Z falls in either shaded tail, meaning there are too few or too many runs.

Conventions and assumptions

  • Values above the median are positive and values below are negative; a run is a block of consecutive values with the same sign.
  • The source does not say how to treat values equal to the median. As a design choice, they are omitted, the order of the rest is kept, and the omitted count is reported. \(n_1\) and \(n_2\) count only positive and negative values.
  • The median is the standard sample median of all entered values: the middle value for odd counts, the mean of the two middle values for even counts.
  • No continuity correction is applied.
  • The decision is strict: equality of \(|Z|\) and the critical value does not reject. The 5% critical value is 1.96.
  • The normal approximation is always used. A small-sample warning appears when \(n_1 \le 10\) or \(n_2 \le 10\), because exact tables are not implemented.
  • Statistics and the p-value are displayed to 4 decimal places; internal values are unrounded.

Worked example

The default 20-value sequence has median 3.95, with no values equal to it. Ten values are above and ten below, so \(n_1 = 10\), \(n_2 = 10\), and the sequence has \(R = 14\) runs.

$$\bar{R} = \frac{2 \times 10 \times 10}{20} + 1 = 11$$

The standard deviation of runs is \(s_R = 2.1764\), so:

$$Z = \frac{14 - 11}{2.1764} = 1.3784$$

The two-sided p-value is 0.1681 and the critical value at \(\alpha = 0.05\) is 1.9600. Since \(1.3784 < 1.9600\), randomness is not rejected. Because \(n_1 \le 10\), the small-sample warning is on.

Reading the result and limitations

Too few runs suggest clustering or a trend; too many suggest alternation. A large \(|Z|\) and a p-value below alpha indicate non-randomness. Failing to reject does not prove randomness, only that this test found no evidence against it. The median split is insensitive to some patterns, such as slow changes in spread. With small groups the normal approximation can be inaccurate, so treat borderline results cautiously.

Advertisement
Three sequences showing too few runs, a random number of runs, and too many runs
Too few runs point to clustering or a trend, too many point to oscillation, and a count near the expected value fits randomness.

FAQ

What does the runs test check?

It checks whether the order of values looks random, based on how often the sequence switches between above-median and below-median values.

How are values equal to the median handled?

They are dropped from the sequence, and the number dropped is reported. The remaining values keep their order.

Why is there a small-sample warning?

The normal approximation works best when both \(n_1\) and \(n_2\) exceed 10. Below that, exact tables would be preferable and are not included.

Does the order of the data matter?

Yes. The data are used exactly as entered, and reordering changes the number of runs.

When is randomness rejected?

When \(|Z|\) is strictly greater than the normal critical value for the chosen alpha, equivalent to the p-value being below alpha.

Sources

Sources & References

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators