NAG Library Function Document
nag_gaps_test (g08edc) performs a gaps test on a sequence of observations.
||nag_gaps_test (Integer n,
const double x,
Gaps tests are used to test for cyclical trend in a sequence of observations. nag_gaps_test (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 (0,1) random numbers then the interval must be contained in the whole interval (0,1). Let be the length of the interval which specifies all possible numbers.
nag_gaps_test (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 nag_gaps_test (g08edc) with the following sequence and with
- 0.20 0.40 0.45 0.40 0.15 0.75 0.95 0.23 0.27 0.40 0.25 0.10 0.34 0.39 0.61 0.12.
nag_gaps_test (g08edc) will count gaps of the following lengths:
When the counting of gaps is complete nag_gaps_test (g08edc) computes the expected values of the counts. An approximate
statistic with max_gap
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 nag_gaps_test (g08edc) 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
n – IntegerInput
On entry: the length of the current sequence of observations, .
x[n] – const doubleInput
On entry: the sequence of observations.
num_gaps – 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.
max_gap – IntegerInput
On entry: the length of the longest gap for which tabulation is desired, .
lower – doubleInput
On entry: the lower limit of the interval to be used to define the gaps, .
upper – doubleInput
On entry: the upper limit of the interval to be used to define the gaps, .
length – doubleInput
On entry: the total length of the interval which contains all possible numbers that may arise in the sequence.
chi – double *Output
On exit: contains the test statistic, , for testing the null hypothesis of randomness.
df – double *Output
On exit: contains the degrees of freedom for the statistic.
prob – double *Output
On exit: contains the upper tail probability associated with the test statistic, i.e., the significance level.
fail – NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
On entry, while . These arguments must satisfy .
On entry, , while . These arguments must satisfy .
On entry, , and . These arguments must satisfy .
Dynamic memory allocation failed.
Some classes have expected frequencies less than 1.0. This implies that the may not be a good approximation to the distribution of the test statistic.
The expected frequency of a certain class is zero, that is
, for some
. For further details please refer to Section 3
The number of gaps requested were not found.
No gaps were found. Try using a longer sequence or increase the size of the interval .
On entry, , .
On entry, .
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
On entry, length
must not be less than or equal to 0.0:
The computations are believed to be stable. The computation of prob
given the values of chi
will obtain a relative accuracy of five significant places for most cases.
The time taken by nag_gaps_test (g08edc) increases with the number of observations .
The following program performs the pairs test on 10000 pseudorandom numbers from a uniform distribution between 0 and 1 generated by nag_rand_uniform (g05sqc)
. nag_gaps_test (g08edc) is called 10 times with 1000 observations on each call. All gaps of length 10 or more are counted together.
9.1 Program Text
Program Text (g08edce.c)
9.2 Program Data
9.3 Program Results
Program Results (g08edce.r)