naginterfaces.library.nonpar.randtest_​pairs

naginterfaces.library.nonpar.randtest_pairs(cl, x, lag, ncount, comm)[source]

randtest_pairs performs a pairs test on a sequence of observations in the interval .

For full information please refer to the NAG Library document for g08eb

https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g08/g08ebf.html

Parameters
clstr, length 1

Indicates the type of call to randtest_pairs.

This is the one and only call to randtest_pairs (single call mode). All data are to be input at once. All test statistics are computed after the counting of pairs is complete.

This is the first call to the function. All initializations are carried out and the counting of pairs begins. The final test statistics are not computed since further calls will be made to randtest_pairs.

This is an intermediate call during which the counts of pairs are updated. The final test statistics are not computed since further calls will be made to randtest_pairs.

This is the last call to randtest_pairs. The test statistics are computed after the final counting of runs is complete.

xfloat, array-like, shape

The sequence of observations.

lagint

, the lag to be used in choosing pairs.

If , then we consider the pairs , for , where is the number of observations.

If , then we consider the pairs , for , where is the number of observations.

must not be changed between calls to randtest_pairs.

ncountint, array-like, shape

If or , need not be set.

If or , must contain the values returned by the previous call to randtest_pairs.

commdict, communication object, modified in place

Communication structure.

On initial entry: need not be set.

Returns
ncountint, ndarray, shape

Is an by matrix containing the counts of the number of pairs in each cell, , for , for .

exfloat

If or (i.e., if it is a final exit) then contains the expected number of counts in each cell, .

Otherwise is not set.

chifloat

If or (i.e., if it is a final exit) then contains the test statistic, , for testing the null hypothesis of randomness.

Otherwise is not set.

dffloat

If or (i.e., if it is a final exit) then contains the degrees of freedom for the statistic.

Otherwise is not set.

probfloat

If or (i.e., if it is a final exit) then contains the upper tail probability associated with the test statistic, i.e., the significance level.

Otherwise is not set.

Raises
NagValueError
(errno )

On entry, .

Constraint: , , or .

(errno )

On entry, .

Constraint: if , , otherwise .

(errno )

On entry, .

Constraint:

(errno )

On entry, and .

Constraint: and if , .

(errno )

On entry, at least one element of is out of range.

Constraint: , for .

(errno )

No pairs were found. This will occur if the value of is greater than or equal to the total number of observations.

Warns
NagAlgorithmicWarning
(errno )

is too large relative to the number of pairs, therefore, the expected value for at least one cell is less than or equal to .

This implies that the distribution may not be a very good approximation to the distribution of test statistic.

, number of pairs and expected value .

All statistics are returned and may still be of use.

Notes

randtest_pairs computes the statistics for performing a pairs test which may be used to investigate deviations from randomness in a sequence, , of observations.

For a given lag, , an matrix, , of counts is formed as follows. The element of is the number of pairs such that

where if , and , if .

Note that all pairs formed are non-overlapping pairs and are thus independent under the assumption of randomness.

Under the assumption that the sequence is random, the expected number of pairs for each class (i.e., each element of the matrix of counts) is the same; that is, the pairs should be uniformly distributed over the unit square . Thus the expected number of pairs for each class is just the total number of pairs, , divided by the number of classes, .

The test statistic used to test the hypothesis of randomness is defined as

where expected number of pairs in each class.

The use of the -distribution as an approximation to the exact distribution of the test statistic, , improves as the length of the sequence relative to increases and hence the expected value, , increases.

randtest_pairs may be used in two different modes:

  1. a single call to randtest_pairs which computes all test statistics after counting the pairs;

  2. multiple calls to randtest_pairs with the final test statistics only being computed in the last call.

The second mode is necessary if all the data do not fit into the memory. See argument in Parameters for details on how to invoke each mode.

References

Dagpunar, J, 1988, Principles of Random Variate Generation, Oxford University Press

Knuth, D E, 1981, The Art of Computer Programming (Volume 2), (2nd Edition), Addison–Wesley

Morgan, B J T, 1984, Elements of Simulation, Chapman and Hall

Ripley, B D, 1987, Stochastic Simulation, Wiley