Post · 4 min read· pp. 244–246

1.3.5.13. Runs Test for Detecting Non-randomness

1. Exploratory Data Analysis 1.3. EDA Techniques 1.3.5. Quantitative Techniques
Purpose: Detect Non-RandomnessThe runs test (Bradley, 1968) can be used to decide if a data set is from a random process. A run is defined as a series of increasing values or a series of decreasing values. The number of increasing, or decreasing, values is the length of the run. In a random data set, the probability that the (I+1)th value is larger or smaller than the Ith value follows a binomial distribution, which forms the basis of the runs test.
Typical Analysis and Test StatisticsThe first step in the runs test is to count the number of runs in the data sequence. There are several ways to define runs in the literature, however, in all cases the formulation must produce a dichotomous sequence of values. For example, a series of 20 coin tosses might produce the following sequence of heads (H) and tails (T). H H T T H T H H H H T H H T T T T T H H The number of runs for this series is nine. There are 11 heads and 9 tails in the sequence.
DefinitionWe will code values above the median as positive and values below the median as negative. A run is defined as a series of consecutive positive (or negative) values. The runs test is defined as:
Runs Test ExampleA runs test was performed for 200 measurements of beam deflection contained in the LEW.DAT data set. ```text

H0: the sequence was produced in a random manner Ha: the sequence was not produced in a random manner

Test statistic: Z = 2.6938 Significance level: α = 0.05 Critical value (upper tail): Z1-α/2 = 1.96 Critical region: Reject H0 if |Z| > 1.96

Since
| *Question* | The runs test can be used to answer the following question:  - Were these sample data generated from a random   process? |
| *Importance* | Randomness is one of the key [assumptions](/u/e9b6365236531caf) in determining if a univariate statistical process is in control. If the assumptions of constant location and scale, randomness, and fixed distribution are reasonable, then the univariate process can be modeled as:  
Yi=A0+EiY_{i} = A_0 + E_{i}
where ***E<sub>i</sub>*** is an error term. If the randomness assumption is not valid, then a different model needs to be used. This will typically be either a [times series model](https://www.itl.nist.gov/div898/handbook/pmc/section4/pmc4.htm) or a [non-linear model](https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd142.htm) (with time as the independent variable). | | *Related Techniques* | [Autocorrelation](/u/4525e99fe70c1e24) [Run Sequence Plot](https://www.itl.nist.gov/div898/handbook/eda/section3/runseqpl.htm) [Lag Plot](https://www.itl.nist.gov/div898/handbook/eda/section3/lagplot.htm) | | *Case Study* | [Heat flow meter](/u/3efc7eda3fa35f69) data | | *Software* | Most general purpose statistical software programs support a runs test. Both [Dataplot code](https://www.itl.nist.gov/div898/handbook/eda/section3/eda35d.dp) and [R code](https://www.itl.nist.gov/div898/handbook/eda/section3/eda35d.r) can be used to generate the analyses in this section. These scripts use the [LEW.DAT](https://www.itl.nist.gov/div898/handbook/datasets/LEW.DAT) data file. |