The R_TEST function tests the hypothesis that a binary population (a sequence of 1s and 0s) represents a “random sampling”.
This routine is written in the IDL language. Its source code can be found in the file r_test.pro in the lib subdirectory of the IDL distribution.
Result = R_TEST( X [, N0=variable] [, N1=variable] [, R=variable] )
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.”
An n-element integer, single-, or double-precision floating-point vector. Elements not equal to 0 or 1 are removed and the length of X is correspondingly reduced.
Set this keyword to a named variable that will contain the number of 0s in X.
Set this keyword to a named variable that will contain the number of 1s in X.
Set this keyword to a named variable that will contain the number of runs (clusters of 0s and 1s) in X.
; 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 X 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, result
IDL prints:
[2.26487, 0.0117604]
Print the values of the keyword parameters:
PRINT, 'Runs: ', r & PRINT, 'Zeros: ', n0 & PRINT, 'Ones: ', n1
Runs: 22
Zeros: 16
Ones: 14
The computed probability (0.0117604) is less than the 0.05 significance level and therefore we reject the hypothesis that X represents a random sampling. The results show that there are too many runs, indicating a non-random cyclical pattern.
4.0 |
Introduced |
CTI_TEST , FV_TEST , KW_TEST , LNP_TEST , MD_TEST , RS_TEST , S_TEST , TM_TEST , XSQ_TEST