NAG Library Function Document
nag_triplets_test (g08ecc)
1
Purpose
nag_triplets_test (g08ecc) performs the triplets test on a sequence of observations from the interval .
2
Specification
#include <nag.h> |
#include <nagg08.h> |
void |
nag_triplets_test (Integer n,
const double x[],
Integer max_count,
double *chi,
double *df,
double *prob,
NagError *fail) |
|
3
Description
nag_triplets_test (g08ecc) computes the statistics for performing a triplets test which may be used to investigate deviations from randomness in a sequence, , of observations.
An
by
matrix,
, of counts is formed as follows. The element
of
is the number of triplets
for
, such that
Note that all triplets formed are non-overlapping 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 . Thus the expected number of triplets for each class is just the total number of triplets, , divided by the number of classes, .
The
test statistic used to test the hypothesis of randomness is defined as
where
expected number of triplets in each class.
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.
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:
– IntegerInput
-
On entry: , the number of observations.
Constraint:
.
- 2:
– const doubleInput
-
On entry: the sequence of observations.
Constraint:
, for .
- 3:
– IntegerInput
-
On entry: , the size of the count matrix to be formed.
Constraint:
.
- 4:
– double *Output
-
On exit: contains the test statistic, , for testing the null hypothesis of randomness.
- 5:
– double *Output
-
On exit: contains the degrees of freedom for the statistic.
- 6:
– double *Output
-
On exit: contains the upper tail probability associated with the test statistic, i.e., the significance level.
- 7:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
6
Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument 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
.
This implies that the
distribution may not be a very good approximation to the distribution of the test statistic.
, number of triplets
and
.
All statistics are returned and may still be of use.
- NE_G08EC_TRIPLETS
-
No triplets were found because less than observations were provided in total.
- NE_INT
-
On entry, .
Constraint: .
- NE_INT_ARG_LE
-
On entry, .
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
- NE_REAL_ARRAY_CONS
-
On entry, at least one element of
x is out of range.
Constraint:
, for
.
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
nag_triplets_test (g08ecc) is not threaded in any implementation.
The time taken by the function increases with the number of observations .
10
Example
The following program performs the triplets test on
pseudorandom numbers taken from a uniform distribution
, generated by
nag_rand_basic (g05sac).
nag_triplets_test (g08ecc) is called with
.
10.1
Program Text
Program Text (g08ecce.c)
10.2
Program Data
None.
10.3
Program Results
Program Results (g08ecce.r)