NAG CL Interface
g08ecc (randtest_triplets)
1
Purpose
g08ecc performs the triplets test on a sequence of observations from the interval $[0,1]$.
2
Specification
The function may be called by the names: g08ecc, nag_nonpar_randtest_triplets or nag_triplets_test.
3
Description
g08ecc computes the statistics for performing a triplets test which may be used to investigate deviations from randomness in a sequence, $x=\{{x}_{i}:i=1,2,\dots ,n\}$, of $[0,1]$ observations.
An
$m\times m$ matrix,
$C$, of counts is formed as follows. The element
${c}_{\mathrm{jkl}}$ of
$C$ is the number of triplets
$({x}_{i},{x}_{i+1},{x}_{i+2})$ for
$i=1,4,7,\dots ,n2$, such that
Note that all triplets formed are nonoverlapping and are thus independent under the assumption of randomness.
Under the assumption that the sequence is random, the expected number of triplets for each class (i.e., each element of the count matrix) is the same; that is, the triplets should be uniformly distributed over the unit cube ${[0,1]}^{3}$. Thus the expected number of triplets for each class is just the total number of triplets, $\sum _{j,k,l=1}^{m}}{c}_{\mathrm{jkl}$, divided by the number of classes, ${m}^{3}$.
The
${\chi}^{2}$ test statistic used to test the hypothesis of randomness is defined as
where
$e={\displaystyle \sum _{j,k,l=1}^{m}}{c}_{\mathrm{jkl}}/{m}^{3}=\text{}$ expected number of triplets in each class.
The use of the ${\chi}^{2}$distribution as an approximation to the exact distribution of the test statistic, ${X}^{2}$, improves as the length of the sequence relative to $m$ increases and hence the expected value, $e$, increases.
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:
$\mathbf{n}$ – Integer
Input

On entry: $n$, the number of observations.
Constraint:
${\mathbf{n}}\ge 3$.

2:
$\mathbf{x}\left[{\mathbf{n}}\right]$ – const double
Input

On entry: the sequence of observations.
Constraint:
$0.0\le {\mathbf{x}}\left[\mathit{i}1\right]\le 1.0$, for $\mathit{i}=1,2,\dots ,n$.

3:
$\mathbf{max\_count}$ – Integer
Input

On entry: $m$, the size of the count matrix to be formed.
Constraint:
${\mathbf{max\_count}}\ge 2$.

4:
$\mathbf{chi}$ – double *
Output

On exit: contains the ${\chi}^{2}$ test statistic, ${X}^{2}$, for testing the null hypothesis of randomness.

5:
$\mathbf{df}$ – double *
Output

On exit: contains the degrees of freedom for the ${\chi}^{2}$ statistic.

6:
$\mathbf{prob}$ – double *
Output

On exit: contains the upper tail probability associated with the ${\chi}^{2}$ test statistic, i.e., the significance level.

7:
$\mathbf{fail}$ – 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_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 $\u27e8\mathit{\text{value}}\u27e9$ had an illegal value.
 NE_G08EC_CELL

max_count is too large relative to the number of triplets, therefore, the expected value for at least one cell is less than or equal to
$5.0$.
This implies that the
${\chi}^{2}$ distribution may not be a very good approximation to the distribution of the test statistic.
${\mathbf{max\_count}}=\u27e8\mathit{\text{value}}\u27e9$, number of triplets
$\text{}=\u27e8\mathit{\text{value}}\u27e9$ and
$\text{expected value}=\u27e8\mathit{\text{value}}\u27e9$.
All statistics are returned and may still be of use.
 NE_G08EC_TRIPLETS

No triplets were found because less than $3$ observations were provided in total.
 NE_INT_ARG_LE

On entry, ${\mathbf{max\_count}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{max\_count}}\ge 2$.
 NE_INT_ARG_LT

On entry, ${\mathbf{n}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{n}}\ge 3$.
 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_ARRAY_CONS

On entry, at least one element of
x is out of range.
Constraint:
$0\le {\mathbf{x}}\left[\mathrm{i}1\right]\le 1$, for
$i=1,2,\dots ,{\mathbf{n}}$.
7
Accuracy
The computations are believed to be stable. The computations 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
g08ecc is not threaded in any implementation.
The time taken by the function increases with the number of observations $n$.
10
Example
The following program performs the triplets test on
$10000$ pseudorandom numbers taken from a uniform distribution
$U(0,1)$, generated by
g05sac.
g08ecc is called with
${\mathbf{max\_count}}=5$.
10.1
Program Text
10.2
Program Data
None.
10.3
Program Results