NAG CL Interface
g08eac (randtest_runs)
1
Purpose
g08eac performs a runs up (or a runs down) test on a sequence of observations.
2
Specification
The function may be called by the names: g08eac, nag_nonpar_randtest_runs or nag_runs_test.
3
Description
Runs tests may be used to investigate for trends in a sequence of observations. g08eac computes statistics for the runs up test. If the runs down test is desired then each observation must be multiplied by before g08eac is called with the modified vector of observations.
A run up is a sequence of numbers in increasing order. A run up ends at when and the new run then begins at . g08eac counts the number of runs up of different lengths. Let denote the number of runs of length , for . The number of runs of length or greater is then denoted by .
An unfinished run at the end of a sequence is not counted. The following is a trivial example.
Suppose we called
g08eac with the following sequence:
- .
Then
g08eac would have counted the runs up of the following lengths:
When the counting of runs is complete
g08eac computes the expected values and covariances of the counts,
. For the details of the method used see
Knuth (1981). An approximate
statistic with
degrees of freedom is computed, where
where
- is the vector of counts, , for ,
- is the vector of expected values,
- , for , where is the expected value for under the null hypothesis of randomness, and
- is the covariance matrix of under the null hypothesis.
The use of the -distribution as an approximation to the exact distribution of the test statistic, , improves as the length of the sequence relative to increases and hence the expected value, , increases.
You may specify the total number of runs to be found. If the specified number of runs is found before the end of a sequence
g08eac will exit before counting any further runs. The number of runs actually counted and used to compute the test statistic is returned via
nruns.
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 length of the longest run for which tabulation is desired. That is, all runs with length greater than or equal to are counted together.
Constraint:
.
-
4:
– Integer *
Output
-
On exit: the number of runs actually found.
-
5:
– double *
Output
-
On exit: contains the approximate test statistic, .
-
6:
– double *
Output
-
On exit: contains the degrees of freedom of the statistic.
-
7:
– double *
Output
-
On exit: contains the upper tail probability corresponding to the test statistic, i.e., the significance level.
-
8:
– 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_GE
-
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_G08EA_COVAR
-
Internally computed covariance matrix is not positive definite.
This may be because the value of
max_run is too large relative to the full length of the series.
Thus the approximate
test statistic cannout be computed.
- NE_G08EA_RUNS
-
The number of runs requested were not found, only out of the requested where found.
All statistics are returned and may still be of use.
- NE_G08EA_RUNS_LENGTH
-
The total length of the runs found is less than
max_run.
whereas the total length of all runs is
.
- NE_G08EA_TIE
-
There is a tie in the sequence of observations.
- NE_INT_ARG_LT
-
On entry, .
Constraint: .
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.
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 figures for most cases.
8
Parallelism and Performance
Background information to multithreading can be found in the
Multithreading documentation.
g08eac makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The time taken by g08eac increases with the number of observations .
10
Example
The following program performs a runs up test on
pseudorandom numbers taken from a uniform distribution
, generated by
g05sqc. All runs of length
or more are counted together.
10.1
Program Text
10.2
Program Data
None.
10.3
Program Results