The routine may be called by the names g08ecf or nagf_nonpar_randtest_triplets.
g08ecf 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.
g08ecf may be used in two different modes:
(i)a single call to g08ecf which computes all test statistics after counting the triplets;
(ii)multiple calls to g08ecf 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 cl in Section 5 for details on how to invoke each mode.
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
1: – Character(1)Input
On entry: indicates the type of call to g08ecf.
This is the one and only call to g08ecf (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 routine. 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 g08ecf.
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 g08ecf.
This is the last call to g08ecf. The test statistics are computed after the final counting of the triplets is complete.
, , or .
2: – IntegerInput
On entry: , the number of observations.
if , ;
3: – Real (Kind=nag_wp) arrayInput
On entry: the sequence of observations.
, for .
4: – IntegerInput
On entry: , the size of the count matrix to be formed.
msize must not be changed between calls to g08ecf.
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended since useful values can be provided in some output arguments even when on exit. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
Note: in some cases g08ecf may return useful information.
On entry, . Constraint: , , or .
On entry, . Constraint: if , , otherwise .
On entry, . Constraint: .
On entry, and .
On entry, at least one element of x is out of range.
Constraint: , for .
No triplets were found because less than observations were provided in total.
msize 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.
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
The computations are believed to be stable. The computations of prob given the values of chi and df will obtain a relative accuracy of five significant figures for most cases.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g08ecf is not thread safe and should not be called from a multithreaded user program. Please see Section 1 in FL Interface Multithreading for more information on thread safety.
g08ecf is not threaded in any implementation.
If the call to g08ecf is an initial call or intermediate call with further calls to follow then any unused observations are saved for use at the beginning of the new sequence provided in the following call. Clearly any observations left over from an only or final call to g08ecf are ignored.
The time taken by the routine increases with the number of observations , and also depends to some extent whether the call to g08ecf is an only, first, intermediate or last call.
The following program performs the triplets test on pseudorandom numbers. g08ecf is called times with observations on each call. The triplets are tallied into a matrix.