naginterfaces.library.nonpar.randtest_gaps¶
- naginterfaces.library.nonpar.randtest_gaps(cl, x, m, rlo, rup, totlen, ngaps, ncount, comm)[source]¶
randtest_gaps
performs a gaps test on a sequence of observations.For full information please refer to the NAG Library document for g08ed
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g08/g08edf.html
- Parameters
- clstr, length 1
Indicates the type of call to
randtest_gaps
.This is the one and only call to
randtest_gaps
(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 function. 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
randtest_gaps
.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
randtest_gaps
.This is the last call to
randtest_gaps
. The test statistics are computed after the final counting of gaps is complete.- xfloat, array-like, shape
The sequence of observations.
- mint
The maximum number of gaps to be sought. If then there is no limit placed on the number of gaps that are found.
should not be changed between calls to
randtest_gaps
.- rlofloat
The lower limit of the interval to be used to define the gaps, .
must not be changed between calls to
randtest_gaps
.- rupfloat
The upper limit of the interval to be used to define the gaps, .
must not be changed between calls to
randtest_gaps
.- totlenfloat
The total length of the interval which contains all possible numbers that may arise in the sequence.
- ngapsint
If or , need not be set.
If or , must contain the value returned by the previous call to
randtest_gaps
.- ncountint, array-like, shape
If or , need not be set.
If or , must contain the values returned by the previous call to
randtest_gaps
.- commdict, communication object, modified in place
Communication structure.
On initial entry: need not be set.
- Returns
- ngapsint
The number of gaps actually found, .
- ncountint, ndarray, shape
The counts of gaps of the different lengths, , for .
- exfloat, ndarray, shape
If or (i.e., if it is a final exit) then contains the expected values of the counts.
Otherwise the elements of are not set.
- chifloat
If or (i.e., if it is a final exit) then contains the test statistic, , for testing the null hypothesis of randomness.
Otherwise is not set.
- dffloat
If or (i.e., if it is a final exit) then contains the degrees of freedom for the statistic.
Otherwise is not set.
- probfloat
If or (i.e., if it is a final exit) then contains the upper tail probability associated with the test statistic, i.e., the significance level.
Otherwise is not set.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: , , or .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: if , .
- (errno )
On entry, and .
Constraint: if , .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, , and .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- (errno )
No gaps were found. Try using a longer sequence, or increase the size of the interval .
- (errno )
The expected frequency in class is zero. The value of may be too close to or . or is too large relative to the number of gaps found.
- Warns
- NagAlgorithmicWarning
- (errno )
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.
- (errno )
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.
- Notes
Gaps tests are used to test for cyclical trend in a sequence of observations.
randtest_gaps
computes certain statistics for the gaps test.randtest_gaps
may be used in two different modes:a single call to
randtest_gaps
which computes all test statistics after counting the gaps;multiple calls to
randtest_gaps
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 in Parameters 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.
randtest_gaps
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 torandtest_gaps
(i.e., unless there is another call torandtest_gaps
to follow) in which case the unfinished gap is used. The following is a trivial example.Suppose we called
randtest_gaps
twice (i.e., with and then with ) with the following two sequences and with and :( ) and
( ).
Then after the second call
randtest_gaps
would have counted the gaps of the following lengths:, , , , and .
When the counting of gaps is complete
randtest_gaps
computes the expected values of the counts. An approximate statistic with degrees of freedom is computed wherewhere
, 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
randtest_gaps
will exit before counting any further gaps.
- 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