NAG CL Interface
g08edc (randtest_gaps)
1
Purpose
g08edc performs a gaps test on a sequence of observations.
2
Specification
void |
g08edc (Integer n,
const double x[],
Integer num_gaps,
Integer max_gap,
double lower,
double upper,
double length,
double *chi,
double *df,
double *prob,
NagError *fail) |
|
The function may be called by the names: g08edc, nag_nonpar_randtest_gaps or nag_gaps_test.
3
Description
Gaps tests are used to test for cyclical trend in a sequence of observations. g08edc computes certain statistics for the gaps test.
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.
g08edc 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. The following is a trivial example.
Suppose we called
g08edc with the following sequence and with
and
:
- .
g08edc would have counted the gaps of the following lengths:
When the counting of gaps is complete
g08edc 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 g08edc 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
Arguments
-
1:
– Integer
Input
-
On entry: , the length of the current sequence of observations.
Constraint:
.
-
2:
– const double
Input
-
On entry: the sequence of observations.
-
3:
– Integer
Input
-
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.
Constraint:
.
-
4:
– Integer
Input
-
On entry: , the length of the longest gap for which tabulation is desired.
Constraint:
.
-
5:
– double
Input
-
On entry: the lower limit of the interval to be used to define the gaps, .
-
6:
– double
Input
-
On entry: the upper limit of the interval to be used to define the gaps, .
Constraint:
.
-
7:
– double
Input
-
On entry: the total length of the interval which contains all possible numbers that may arise in the sequence.
Constraint:
and .
-
8:
– double *
Output
-
On exit: contains the test statistic, , for testing the null hypothesis of randomness.
-
9:
– double *
Output
-
On exit: contains the degrees of freedom for the statistic.
-
10:
– double *
Output
-
On exit: contains the upper tail probability associated with the test statistic, i.e., the significance level.
-
11:
– NagError *
Input/Output
-
The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
6
Error Indicators and Warnings
- NE_2_INT_ARG_GT
-
On entry, and .
Constraint: .
- NE_2_REAL_ARG_GE
-
On entry, and .
Constraint: .
- NE_3_REAL_ARG_CONS
-
On entry, , and .
Constraint: .
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_G08ED_FREQ_LT_ONE
-
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.
- NE_G08ED_FREQ_ZERO
-
The expected frequency in class
is zero. The value of
may be too close to
. or
max_gap is too large relative to the number of gaps found.
- NE_G08ED_GAPS
-
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.
- NE_G08ED_GAPS_ZERO
-
No gaps were found. Try using a longer sequence, or increase the size of the interval .
- NE_INT_2
-
On entry, and .
Constraint: .
- NE_INT_ARG_LT
-
On entry, .
Constraint: .
- NE_INTERNAL_ERROR
-
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
See
Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library CL Interface for further information.
- NE_REAL_ARG_LE
-
On entry, .
Constraint: .
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.
8
Parallelism and Performance
g08edc is not threaded in any implementation.
The time taken by g08edc increases with the number of observations .
10
Example
The following program performs the gaps test on
pseudorandom numbers taken from a uniform distribution
, generated by
g05sqc. All gaps of length
or more are counted together.
10.1
Program Text
10.2
Program Data
None.
10.3
Program Results