NAG Library Routine Document
G08EDF
1 Purpose
G08EDF performs a gaps test on a sequence of observations.
2 Specification
SUBROUTINE G08EDF ( |
CL, N, X, M, MAXG, RLO, RUP, TOTLEN, NGAPS, NCOUNT, EX, CHI, DF, PROB, IFAIL) |
INTEGER |
N, M, MAXG, NGAPS, NCOUNT(MAXG), IFAIL |
REAL (KIND=nag_wp) |
X(N), RLO, RUP, TOTLEN, EX(MAXG), CHI, DF, PROB |
CHARACTER(1) |
CL |
|
3 Description
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 parameter
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:
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
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.
4 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
5 Parameters
- 1: CL – 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.
Constraint:
, , or .
- 2: N – INTEGERInput
On entry: , the length of the current sequence of observations.
Constraint:
.
- 3: X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the sequence of observations.
- 4: M – 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.
M should not be changed between calls to G08EDF.
Constraint:
if , .
- 5: MAXG – INTEGERInput
On entry:
, the length of the longest gap for which tabulation is desired.
MAXG must not be changed between calls to G08EDF.
Constraints:
- ;
- if , .
- 6: RLO – REAL (KIND=nag_wp)Input
-
On entry: the lower limit of the interval to be used to define the gaps,
.
RLO must not be changed between calls to G08EDF.
- 7: RUP – REAL (KIND=nag_wp)Input
-
On entry: the upper limit of the interval to be used to define the gaps,
.
RUP must not be changed between calls to G08EDF.
Constraint:
.
- 8: TOTLEN – REAL (KIND=nag_wp)Input
-
On entry: the total length of the interval which contains all possible numbers that may arise in the sequence.
Constraint:
and .
- 9: NGAPS – INTEGERInput/Output
On entry: if
or
,
NGAPS need not be set.
If
or
,
NGAPS must contain the value returned by the previous call to G08EDF.
On exit: the number of gaps actually found, .
- 10: NCOUNT(MAXG) – INTEGER arrayInput/Output
On entry: if
or
,
NCOUNT need not be set.
If
or
,
NCOUNT must contain the values returned by the previous call to G08EDF.
On exit: the counts of gaps of the different lengths,
, for .
- 11: EX(MAXG) – REAL (KIND=nag_wp) arrayOutput
On exit: if
or
(i.e., if it is a final exit) then
EX contains the expected values of the counts.
Otherwise the elements of
EX are not set.
- 12: CHI – REAL (KIND=nag_wp)Output
-
On exit: if
or
(i.e., if it is a final exit) then
CHI contains the
test statistic,
, for testing the null hypothesis of randomness.
Otherwise
CHI is not set.
- 13: DF – REAL (KIND=nag_wp)Output
-
On exit: if
or
(i.e., if it is a final exit) then
DF contains the degrees of freedom for the
statistic.
- 14: PROB – REAL (KIND=nag_wp)Output
-
On exit: if
or
(i.e., if it is a final exit) then
PROB contains the upper tail probability associated with the
test statistic, i.e., the significance level.
Otherwise
PROB is not set.
- 15: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if
on exit, the recommended value is
.
When the value 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).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: G08EDF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
-
On entry, | , , or . |
-
-
On entry, | with , . |
On entry, | , |
or | with , . |
On entry, | , |
or | , |
or | . |
No gaps were found. You may need to use a longer sequence or increase the size of the interval .
The expected frequency of a certain class is zero, that is , for some .
The number of gaps requested were not found.
Some classes have expected frequencies less than . This implies that the -distribution may not be a very good approximation to the distribution of the test statistic.
7 Accuracy
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.
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.
9 Example
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.
9.1 Program Text
Program Text (g08edfe.f90)
9.2 Program Data
Program Data (g08edfe.d)
9.3 Program Results
Program Results (g08edfe.r)