Function Repository Resource:

CUSUMMaxRandomnessTest

Source Notebook

Conduct a cumulative sum-based randomness test that creates a test statistic from the maximum value that a cumulative sums random walk achieves

Contributed by: Emmy/Noah Blumenthal
noahb320@gmail.com
emmyb320@bu.edu

ResourceFunction["CUSUMMaxRandomnessTest"][sequence]

conducts a cumulative sum-based randomness test on sequence.

ResourceFunction["CUSUMMaxRandomnessTest"][sequence,"properties"]

conducts a cumulative sum-based randomness test on sequence and returns the associated property.

Details and Options

ResourceFunction["CUSUMMaxRandomnessTest"] creates a test statistic from the maximum value that a cumulative sums random walk achieves and returns the associated p-value.
Properties include:
"TestStatistic"returns the test statistic
"PValue"returns the p-value associated with the test
The test works only for sequences of zeros and ones.
Results are generally invalid for sequence lengths shorter than 100.
The test returns a two-tailed p-value of the distribution.

Examples

Basic Examples (3) 

Generate a sequence of random integers:

In[1]:=
sequence = RandomInteger[{0, 1}, 1000];

Visualize the sequence:

In[2]:=
ArrayPlot[Partition[sequence, 16]\[Transpose], Sequence[
 ImageSize -> Large, ColorFunction -> "CandyColors"]]
Out[2]=

Apply a cumulative sums test:

In[3]:=
ResourceFunction["CUSUMMaxRandomnessTest"][sequence, "TestStatistic"]
Out[3]=
In[4]:=
ResourceFunction["CUSUMMaxRandomnessTest"][sequence, "PValue"]
Out[4]=

Applications (2) 

Generate a sequence of integers from a random subsequence:

In[5]:=
subsequence = RandomInteger[{0, 1}, 40];
In[6]:=
sequence = Flatten@Table[subsequence, 20];

Visualize the sequence:

In[7]:=
ArrayPlot[Partition[sequence, 16]\[Transpose], Sequence[
 ImageSize -> Large, ColorFunction -> "CandyColors"]]
Out[7]=

Apply a cumulative sums test. The small p-value indicates that the sequence is non-random and hence should be rejected:

In[8]:=
ResourceFunction["CUSUMMaxRandomnessTest"][sequence, "TestStatistic"]
Out[8]=
In[9]:=
ResourceFunction["CUSUMMaxRandomnessTest"][sequence, "PValue"]
Out[9]=

Define and plot rule 30:

In[10]:=
rule30seq = CellularAutomaton[30, {{1}, 0}, {100000, 0}]\[Transpose][[1]];
In[11]:=
ArrayPlot[Partition[Take[rule30seq, 1000], 16]\[Transpose], Sequence[
 ColorFunction -> "CandyColors", ImageSize -> Large]]
Out[11]=

Test whether rule 30 is random:

In[12]:=
ResourceFunction["CUSUMMaxRandomnessTest"][rule30seq]
Out[12]=

Possible Issues (1) 

CUSUMMaxRandomnessTest requires sequences of length 100 or more:

In[13]:=
ResourceFunction["CUSUMMaxRandomnessTest"][RandomInteger[{0, 1}, 50]]

Neat Examples (1) 

Visualize the sampling distribution of the test statistic:

In[14]:=
samp = Table[
   ResourceFunction["CUSUMMaxRandomnessTest"][
    RandomInteger[{0, 1}, 1000], "TestStatistic"], 1000];
In[15]:=
Histogram[samp, Automatic, "PDF"]
Out[15]=

Publisher

Emmy Blumenthal

Version History

  • 1.0.0 – 08 July 2019

Source Metadata

Related Resources

Author Notes

This test is entirely derived from the NIST publication.

License Information