The routine may be called by the names g08edf or nagf_nonpar_randtest_gaps.
Gaps tests are used to test for cyclical trend in a sequence of observations. g08edf computes certain statistics for the gaps test.
g08edf may be used in two different modes:
(i)a single call to g08edf which computes all test statistics after counting the gaps;
(ii)multiple calls to g08edf with the final test statistics only being computed in the last call.
The second mode is necessary if all the data does not fit into the memory. See argument cl in Section 5 for details on how to invoke each mode.
The term gap is used to describe the distance between two numbers in the sequence that lie in the interval . That is, a gap ends at if . The next gap then begins at . The interval should lie within the region of all possible numbers. For example if the test is carried out on a sequence of random numbers then the interval must be contained in the whole interval . Let be the length of the interval which specifies all possible numbers.
g08edf counts the number of gaps of different lengths. Let denote the number of gaps of length , for . The number of gaps of length or greater is then denoted by . An unfinished gap at the end of a sequence is not counted unless the sequence is part of an initial or intermediate call to g08edf (i.e., unless there is another call to g08edf to follow) in which case the unfinished gap is used. The following is a trivial example.
Suppose we called g08edf twice (i.e., with and then with ) with the following two sequences and with and :
( ) and
Then after the second call g08edf would have counted the gaps of the following lengths:
, , , , and .
When the counting of gaps is complete g08edf computes the expected values of the counts. An approximate statistic with degrees of freedom is computed where
, if ;
, if ;
the number of gaps found and
The use of the -distribution as an approximation to the exact distribution of the test statistic improves as the expected values increase.
You may specify the total number of gaps to be found. If the specified number of gaps is found before the end of a sequence g08edf will exit before counting any further gaps.
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 g08edf.
This is the one and only call to g08edf (single call mode). All data are to be input at once. All test statistics are computed after the counting of gaps is complete.
This is the first call to the routine. All initializations are carried out before the counting of gaps begins. The final test statistics are not computed since further calls will be made to g08edf.
This is an intermediate call during which the counts of gaps are updated. The final test statistics are not computed since further calls will be made to g08edf.
This is the last call to g08edf. The test statistics are computed after the final counting of gaps is complete.
, , or .
2: – IntegerInput
On entry: , the length of the current sequence of observations.
3: – Real (Kind=nag_wp) arrayInput
On entry: the sequence of observations.
4: – IntegerInput
On entry: the maximum number of gaps to be sought. If then there is no limit placed on the number of gaps that are found.
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 g08edf may return useful information.
On entry, . Constraint: , , or .
On entry, .
On entry, and .
Constraint: if , .
On entry, . Constraint: .
On entry, and .
Constraint: if , .
On entry, , and . Constraint: .
On entry, and . Constraint: .
On entry, .
No gaps were found. Try using a longer sequence, or increase the size of the interval .
The expected frequency in class is zero. The value of may be too close to or . or maxg is too large relative to the number of gaps found.
The number of gaps requested were not found, only out of the requested where found. All statistics are returned and may still be of use.
The expected frequency of at least one class is less than . This implies that the may not be a very good approximation to the distribution of the test statistics. 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 computation of prob given the values of chi and df will obtain a relative accuracy of five significant places for most cases.
8Parallelism and Performance
g08edf 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.
g08edf is not threaded in any implementation.
The time taken by g08edf increases with the number of observations , and depends to some extent whether the call is an only, first, intermediate or last call.
The following program performs the gaps test on pseudorandom numbers. g08edf is called times with observations on each call. All gaps of length or more are counted together.