NAG Library Function Document
nag_pairs_test (g08ebc)
1 Purpose
nag_pairs_test (g08ebc) performs a pairs test on a sequence of observations in the interval .
2 Specification
| #include <nag.h> |
| #include <nagg08.h> |
| void |
nag_pairs_test (Integer n,
const double x[],
Integer max_count,
Integer lag,
double *chi,
double *df,
double *prob,
NagError *fail) |
|
3 Description
nag_pairs_test (g08ebc) computes the statistics for performing a pairs test which may be used to investigate deviations from randomness in a sequence of observations.
For a given lag,
, an
by
matrix,
, of counts is formed as follows. The element
of
is the number of pairs (
x,
x) such that
where
if
, and
if
.
Note that all pairs formed are non-overlapping pairs and are thus independent under the assumption of randomness.
Under the assumption that the sequence is random, the expected number of pairs for each class (i.e., each element of the matrix of counts) is the same, that is the pairs should be uniformly distributed over the unit square . Thus the expected number of pairs for each class is just the total number of pairs, , divided by the number of classes, .
The
test statistic used to test the hypothesis of randomness is defined as:
where
expected number of pairs in each class.
The use of the distribution as an approximation to the exact distribution of the test statistic, , improves as 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:
n – IntegerInput
-
On entry: the number of observations, .
Constraint:
.
- 2:
x[n] – const doubleInput
-
On entry: the sequence of observations.
Constraint:
, for .
- 3:
max_count – IntegerInput
-
On entry: the size of the matrix of counts, .
Constraint:
.
- 4:
lag – IntegerInput
-
On entry: the lag,
, to be used in choosing pairs.
- We consider the pairs , for , where is the number of observations.
- We consider the pairs , for , where is the number of observations.
Constraint:
.
- 5:
chi – double *Output
-
On exit: contains the test statistic, , for testing the null hypothesis of randomness.
- 6:
df – double *Output
-
On exit: contains the degrees of freedom for the statistic.
- 7:
prob – double *Output
-
On exit: contains the upper tail probability associated with the test statistic, i.e., the significance level.
- 8:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
Dynamic memory allocation failed.
- NE_G08EB_CELL
The expected value for each cell is less than or equal to 5.0. This implies that the distribution may not be a very good approximation to the test statistic.
- NE_G08EB_PAIRS
No pairs were found. This will occur if the value of
lag is greater than or equal to the total number of observations.
- NE_INT_2
On entry, , .
Constraint: .
- NE_INT_ARG_LE
On entry,
max_count must not be less than or equal to 1:
.
- 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.
- NE_REAL_ARRAY_CONS
On entry, .
Constraint: , for .
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.
The time taken by nag_pairs_test (g08ebc) increases with the number of observations, .
9 Example
The following program performs the pairs test on 10000 pseudorandom numbers from a uniform distribution
generated by
nag_rand_basic (g05sac). nag_pairs_test (g08ebc) is called with
and
.
9.1 Program Text
Program Text (g08ebce.c)
9.2 Program Data
None.
9.3 Program Results
Program Results (g08ebce.r)