Serial Randomness Test

The StatsSRTest operation contains both parametric and non-parametric serial randomness tests. In the following examples we illustrate how they work (and how they fail).

1. Testing serial randomenss of gnoise().

The first data set is created with the command:

Make/n=50 data1=10+gnoise(2)

The resulting wave appears in the figure below.

Picture0

To run both tests on this wave execute the command:

StatsSRTest/T=1/Q/P/NP  data1

The results are displayed in the Serial Randomness Test table:

N50

s23.71269

ss23.30635

C0.109447

Critical0.228249

P-Value0.217518

Runs Up17

Runs Down16

Unchanged0

Longest Run4

Longest Run Prob.0.473586

Total Runs33

Prob0.565534

The first six rows in the table belong to the parametric test. In this case we have a statistic C which is smaller than the critical value so the hypothesis H0 that the wave contains a random variation is accepted though the P-value is not particularly high. The remaining rows of the table belong to the non-parametric test. After listing the number of runs up and down, the table includes the longest run and the probability that a run of such length can happen by chance. The last two rows contain the total number of runs and the probability that such a value can be attained by chance.

2. Testing serial randomness in the presence of non-random data segment.

We create the second data set by duplicating the first and setting a contiguous run of length N/10 to a constant. The following commands were used:

Duplicate data1,data2
data2[10,14]=10

Picture1

To run both tests on this wave execute:

StatsSRTest/T=1/Q/P/NP  data2

The results are displayed in the Serial Randomness Test table:

N50
s23.53478
ss23.18483
C0.099004
Critical0.228249
P-Value0.240177
Runs Up16
Runs Down15
Unchanged1
Longest Run4
Longest Run Prob.0.473586
Converted0
Total Runs31
Prob0.302833

The results of the parametric test are similar to those of the test in (1) above. The non-parametric tests shows a slightly lower probability of attaining 31 runs by chance but this value is still not enough to reject H0.

3. Testing serial randomness in the presence of a non-random segment set to be different from the mean value.

Duplicate data1,data3
data3[10,14]=0

Picture2

To run both tests on this wave execute:

StatsSRTest/T=1/Q/P/NP  data3

The results are displayed in the Serial Randomness Test table:

N50
s213.268
ss25.61904
C0.576496
Critical0.228249
P-Value3.07736e-06
Runs Up16
Runs Down15
Unchanged1
Longest Run4
Longest Run Prob.0.473586
Converted0
Total Runs31
Prob0.302833

As expected, the non-parametric results remain unchanged but the parametric test statistic C exceeds the critical value and so H0 must be rejected. This illustrates a major deficiency of the parametric test in that it is less likely to fail if the non-random sections have values sufficiently close to the mean.

4. Testing in the presence of a very long non-random segment.

We used the following commands to create the input wave:

Duplicate data1,data4
data4[5,20]=10

Picture3

To run both tests on this wave execute:

StatsSRTest/T=1/Q/P/NP  data4

The results are displayed in the Serial Randomness Test table:

N50
s23.08189
ss22.88656
C0.063382
Critical0.228249
P-Value0.325941
Runs Up13
Runs Down13
Unchanged1
Longest Run15
Longest Run Prob.3.15448e-12
Converted1
Max Runs27
Min Runs25
Mean Runs26
Max Prob0.0303374
Min Prob0.005209
Mean Prob0.005209

In this case, despite the presence of a very long constant segment, the parametric test does not reject H0. On the other hand, the non-parametric test indicates a vanishing probability of the longest run being that long by chance and (all) run probabilities are too low to accept H0.

5. Testing longer waves.

If the wave that you are testing exceeds 150 points, the parametric test uses the normal approximation to calculate the critical value and the P-value. If your wave has more than 100 points then the non-parametric test uses the normal approximation for the runs up and down distribution. For example,

Make/O/N=160 data5=10+gnoise(1)

Picture4

StatsSRTest/T=1/Q/P/NP  data5

N160
s20.994158
ss21.04365
C-0.0497789
Normal Approx Z-0.631623
Critical1.64485
Runs Up52
Runs Down52
Unchanged0
Longest Run4
Longest Run Prob.0.885759
Total Runs104
Normal Approx Z-0.439999
Critical1.64485