NAG Library Manual, Mark 27.2
Interfaces:
FL
CL
CPP
AD
NAG CL Interface Introduction
G08 (Nonpar) Chapter Contents
G08 (Nonpar) Chapter Introduction
g08eb:
FL
CL
CPP
AD
NAG CL Interface
g08ebc (randtest_pairs)
Keyword Search:
NAG Library Manual, Mark 27.2
Interfaces:
FL
CL
CPP
AD
NAG CL Interface Introduction
G08 (Nonpar) Chapter Contents
G08 (Nonpar) Chapter Introduction
g08eb:
FL
CL
CPP
AD
▸
▿
Contents
1
Purpose
2
Specification
3
Description
4
References
5
Arguments
6
Error Indicators and Warnings
7
Accuracy
8
Parallelism and Performance
9
Further Comments
▸
▿
10
Example
10.1
Program Text
10.2
Program Data
10.3
Program Results
© The Numerical Algorithms Group Ltd. 2021
Settings help
CL Name Style:
Short (
a00aac
)
Long (
impl_details
)
Full (
nag_info_impl_details
)
1
Purpose
g08ebc
performs a pairs test on a sequence of observations in the interval
[
0
,
1
]
.
2
Specification
copy
#include <nag.h>
void
g08ebc
(
Integer
n
,
const double
x
[],
Integer
max_count
,
Integer
lag
,
double *
chi
,
double *
df
,
double *
prob
,
NagError *
fail
)
The function may be called by the names:
g08ebc
,
nag_nonpar_randtest_pairs
or
nag_pairs_test
.
3
Description
g08ebc
computes the statistics for performing a pairs test which may be used to investigate deviations from randomness in a sequence,
x
=
{
x
i
:
i
=
1
,
2
,
…
,
n
}
, of
[
0
,
1
]
observations.
For a given lag,
l
≥
1
, an
m
×
m
matrix,
C
, of counts is formed as follows. The element
c
j
k
of
C
is the number of pairs
(
x
i
,
x
i
+
l
)
such that
j
-
1
m
≤
x
i
<
j
m
k
-
1
m
≤
x
i
+
l
<
k
m
where
i
=
1
,
3
,
5
,
…
,
n
-
1
if
l
=
1
, and
i
=
1
,
2
,
…
,
l
,
2
l
+
1
,
2
l
+
2
,
…
3
l
,
4
l
+
1
,
…
,
n
-
l
, if
l
>
1
.
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
[
0
,
1
]
2
. Thus the expected number of pairs for each class is just the total number of pairs,
∑
j
,
k
=
1
m
c
j
k
, divided by the number of classes,
m
2
.
The
χ
2
test statistic used to test the hypothesis of randomness is defined as
X
2
=
∑
j
,
k
=
1
m
(
c
j
k
-
e
)
2
e
,
where
e
=
∑
j
,
k
=
1
m
c
j
k
/
m
2
=
expected number of pairs in each class.
The use of the
χ
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:
n
–
Integer
Input
On entry
:
n
, the number of observations.
Constraint
:
n
≥
2
.
2:
x
[
n
]
–
const double
Input
On entry
: the sequence of observations.
Constraint
:
0.0
≤
x
[
i
-
1
]
≤
1.0
, for
i
=
1
,
2
,
…
,
n
.
3:
max_count
–
Integer
Input
On entry
:
m
, the size of the matrix of counts.
Constraint
:
max_count
≥
2
.
4:
lag
–
Integer
Input
On entry
:
l
, the lag to be used in choosing pairs.
If
lag
=
1
, then we consider the pairs
(
x
[
i
-
1
]
,
x
[
i
]
)
, for
i
=
1
,
3
,
…
,
n
-
1
, where
n
is the number of observations.
If
lag
>
1
, then we consider the pairs
(
x
[
i
-
1
]
,
x
[
i
+
l
-
1
]
)
, for
i
=
1
,
2
,
…
,
l
,
2
l
+
1
,
2
l
+
2
,
…
,
3
l
,
4
l
+
1
,
…
,
n
-
l
, where
n
is the number of observations.
Constraint
:
1
≤
lag
<
n
.
5:
chi
–
double *
Output
On exit
: contains the
χ
2
test statistic,
X
2
, for testing the null hypothesis of randomness.
6:
df
–
double *
Output
On exit
: contains the degrees of freedom for the
χ
2
statistic.
7:
prob
–
double *
Output
On exit
: contains the upper tail probability associated with the
χ
2
test statistic, i.e., the significance level.
8:
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
⟨
value
⟩
had an illegal value.
NE_G08EB_CELL
max_count
is too large relative to the number of pairs, therefore, the expected value for at least one cell is less than or equal to
5.0
.
This implies that the
χ
2
distribution may not be a very good approximation to the distribution of test statistic.
max_count
=
⟨
value
⟩
, number of pairs
=
⟨
value
⟩
and expected value
=
⟨
value
⟩
.
All statistics are returned and may still be of use.
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,
lag
=
⟨
value
⟩
and
n
=
⟨
value
⟩
.
Constraint:
1
≤
lag
<
n
.
NE_INT_ARG_LE
On entry,
max_count
=
⟨
value
⟩
.
Constraint:
max_count
≥
2
.
NE_INT_ARG_LT
On entry,
n
=
⟨
value
⟩
.
Constraint:
n
≥
2
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
≤
x
[
i
-
1
]
≤
1
, for
i
=
1
,
2
,
…
,
n
.
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
g08ebc
is not threaded in any implementation.
9
Further Comments
The time taken by the function increases with the number of observations
n
.
10
Example
The following program performs the pairs test on
10000
pseudorandom numbers taken from a uniform distribution
U
(
0
,
1
)
, generated by
g05sac
.
g08ebc
is called with
lag
=
1
and
max_count
=
10
..
10.1
Program Text
Program Text (g08ebce.c)
10.2
Program Data
None.
10.3
Program Results
Program Results (g08ebce.r)
NAG Library Manual, Mark 27.2
Interfaces:
FL
CL
CPP
AD
NAG CL Interface Introduction
G08 (Nonpar) Chapter Contents
G08 (Nonpar) Chapter Introduction
g08eb:
FL
CL
CPP
AD
© The Numerical Algorithms Group Ltd. 2021