hypothesis that a binary population (a sequence of 1s and 0s) represents a "random sampling". The result is a two-element vector containing the nearly-normal test statistic Z and its associated probability. This two-tailed test is based on the "theory of runs" and is often referred to as the "
Runs Test for Randomness."
This routine is written in the IDL language. Its source code can be found in the file
subdirectory of the IDL distribution.
Result = R_TEST(
-element integer, single-, or double-precision floating-point vector. Elements not equal to 0 or 1 are removed and the length of
is correspondingly reduced.
Set this keyword to a named variable that will contain the number of 0s in
Set this keyword to a named variable that will contain the number of 1s in
Set this keyword to a named variable that will contain the number of runs (clusters of 0s and 1s) in
Define a binary population.
X = [0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, $
1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1]
Test the hypothesis that
represents a random sampling against the hypothesis that it does not represent a random sampling at the 0.05 significance level.
result = R_TEST(X, R = r, N0 = n0, N1 = n1)
Print the values of the keyword parameters:
PRINT, 'Runs: ', r & PRINT, 'Zeros: ', n0 & PRINT, 'Ones: ', n1
The computed probability (0.0117604) is less than the 0.05 significance level and therefore we reject the hypothesis that
represents a random sampling. The results show that there are too many runs, indicating a non-random cyclical pattern.