naginterfaces.library.nonpar.randtest_triplets¶
- naginterfaces.library.nonpar.randtest_triplets(cl, x, ncount, comm)[source]¶
randtest_triplets
performs the triplets test on a sequence of observations from the interval .For full information please refer to the NAG Library document for g08ec
https://www.nag.com/numeric/nl/nagdoc_29.3/flhtml/g08/g08ecf.html
- Parameters
- clstr, length 1
Indicates the type of call to
randtest_triplets
.This is the one and only call to
randtest_triplets
(single call mode). All data are to be input at once. All test statistics are computed after counting of the triplets is complete.This is the first call to the function. All initializations are carried out and the counting of triplets begins. The final test statistics are not computed since further calls will be made to
randtest_triplets
.This is an intermediate call during which counts of the triplets are updated. The final test statistics are not computed since further calls will be made to
randtest_triplets
.This is the last call to
randtest_triplets
. The test statistics are computed after the final counting of the triplets is complete.- xfloat, array-like, shape
The sequence of observations.
- ncountint, array-like, shape
If or , need not be set.
If or , must contain the values returned by the previous call to
randtest_triplets
.- commdict, communication object, modified in place
Communication structure.
On initial entry: need not be set.
- Returns
- ncountint, ndarray, shape
Is an by by matrix containing the counts of the number of triplets, , for , for , for .
- exfloat
If or (i.e., if it is a final exit) then contains the expected number of counts for each element of the count matrix.
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, at least one element of is out of range.
Constraint: , for .
- (errno )
No triplets were found because less than observations were provided in total.
- Warns
- NagAlgorithmicWarning
- (errno )
is too large relative to the number of triplets, 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 the test statistic.
, number of triplets and .
All statistics are returned and may still be of use.
- Notes
randtest_triplets
computes the statistics for performing a triplets test which may be used to investigate deviations from randomness in a sequence, , of observations.An matrix, , of counts is formed as follows. The element of is the number of triplets for , such that
Note that all triplets formed are non-overlapping and are thus independent under the assumption of randomness.
Under the assumption that the sequence is random, the expected number of triplets for each class (i.e., each element of the count matrix) is the same; that is, the triplets should be uniformly distributed over the unit cube . Thus the expected number of triplets for each class is just the total number of triplets, , divided by the number of classes, .
The test statistic used to test the hypothesis of randomness is defined as
where expected number of triplets 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_triplets
may be used in two different modes:a single call to
randtest_triplets
which computes all test statistics after counting the triplets;multiple calls to
randtest_triplets
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