PAIRS
Performs a pairs test.
Required Arguments
X — Vector of length NRAN containing the data elements to be added to the test on this invocation. (Input)
LAG — The lag to be used in computing the pairs statistic. (Input)
Pairs (X(i), X(i + LAG)) for i = 1, K, N  LAG are tabulated, where N is the total sample size.
COUNTNCELL by NCELL matrix containing the count of the number of pairs in each cell. (Output, if IDO = 0 or 1; input/output, if IDO = 2 or 3)
EXPECT — Expected number of counts in each cell. (Output, if IDO = 0 or 3; not referenced otherwise)
CHISQ — Chi‑squared statistic for testing the null hypothesis of a uniform distribution. (Output, if IDO = 0 or 3; not referenced otherwise)
DF — Degrees of freedom for chi‑squared. (Output, if IDO = 0 or 3; not referenced otherwise)
PROB — Probability of a larger chi‑squared. (Output, if IDO = 0 or 3; not referenced otherwise)
Optional Arguments
IDO — Processing option. (Input)
Default: IDO = 0.
IDO
Action
0
This is the only invocation of PAIRS, and all the data are input at once.
1
This is the first invocation of PAIRS, and additional calls will be made. Initialization and updating for the NRAN data elements are performed.
2
This is an intermediate invocation of PAIRS, and updating for the NRAN data elements is performed.
3
This is the final invocation of PAIRS. Updating for the NRAN data elements is performed, followed by the wrap‑up computations.
NRAN — Number of random deviates currently input in X. (Input)
NRAN may be positive or zero on any invocation of PAIRS.
Default: NRAN = size (X,1).
NCELL — Number of equiprobable cells on each axis into which the pairs statistics are to be tabulated. (Input)
Default: NCELL = size (COUNT,1).
LDCOUN — Leading dimension of COUNT exactly as specified in the dimension statement of the calling program. (Input)
Default: LDCOUN = size (COUNT,1).
FORTRAN 90 Interface
Generic: CALL PAIRS (X, LAG, COUNT, EXPECT, CHISQ, DF, PROB [])
Specific: The specific interface names are S_PAIRS and D_PAIRS.
FORTRAN 77 Interface
Single: CALL PAIRS (IDO, NRAN, X, NCELL, LAG, COUNT, LDCOUN, EXPECT, CHISQ, DF, PROB)
Double: The double precision name is DPAIRS.
Description
Routine PAIRS computes the pairs test (or the Good’s serial test) on a hypothesized sequence of uniform (0,1) pseudorandom numbers. The test proceeds as follows. Subsequent pairs
(X(i), X(i + LAG)) are tallied into a k × k matrix, where k = NCELL. In this tally, element (j, m) of the matrix is incremented, where
where l = LAG, and the notation   represents the greatest integer function, Y is the greatest integer less than or equal to Y, where Y is a real number. If l = 1, then i = 1, 3, 5, K , n  1. If l > 1, then i = 1, 2, 3, , n  l, where n is the total number of pseudorandom numbers input on the current invocation of PAIRS (i.e., n = NRAN).
Given the tally matrix in COUNT, chi‑squared is computed as
where e = Σoij/k2, and oij is the observed count in cell (i, j) (oij = COUNT(i, j)).
Because pair statistics for the trailing observations are not tallied on any call, the user should call PAIRS with NRAN as large as possible. For LAG < 20 and NRAN = 2000, little power is lost.
Comments
Informational errors
Type
Code
Description
3
1
For better efficiency, it is recommended that NRAN be at least twice as large as LAG.
4
2
The sum of the counts is zero. All output statistics are set to NaN (not a number).
Example
The following example illustrates the calculations of the PAIRS statistics when a random sample of size 104 is used and the LAG is 1. The results are not significant. On each call to PAIRS, 2000 random deviates are processed. On the first call, initialization is also performed, while on the fifth call the wrap‑up computations are performed. Routine RNUN (see Chapter 18, “Random Number Generation”) is used in obtaining the pseudorandom deviates.
 
USE IMSL_LIBRARIES
 
IMPLICIT NONE
INTEGER LAG, LDCOUN, NCELL, NOBS
PARAMETER (LAG=5, LDCOUN=10, NCELL=10, NOBS=2000)
!
INTEGER I, IDO, NOUT
REAL CHISQ, COUNT(LDCOUN,NCELL), DF, EXPECT, PROB, X(NOBS)
!
CALL RNSET (123467)
!
DO 10 I=1, 5
CALL RNUN (X)
IF (I .EQ. 1) THEN
IDO = 1
ELSE IF (I .EQ. 5) THEN
IDO = 3
ELSE
IDO = 2
END IF
CALL PAIRS (X, LAG, COUNT, EXPECT, CHISQ, DF, PROB, IDO=IDO)
10 CONTINUE
CALL UMACH (2, NOUT)
CALL WRRRN ('COUNT', COUNT)
WRITE(NOUT,'('' Expect = '', F12.2, /, '' Chi-squared = '', F12.2, &
'' DF = '', F12.0, /, '' PROBABILITY = '', F12.4)') &
EXPECT, CHISQ, DF, PROB
END
Output
 
COUNT
1 2 3 4 5 6 7 8 9
1 111.0 82.0 95.0 117.0 102.0 102.0 112.0 84.0 90.0
2 104.0 106.0 109.0 108.0 101.0 97.0 102.0 92.0 109.0
3 88.0 111.0 86.0 105.0 112.0 79.0 103.0 105.0 106.0
4 91.0 110.0 108.0 92.0 88.0 108.0 113.0 93.0 105.0
5 104.0 105.0 103.0 104.0 101.0 94.0 96.0 86.0 93.0
6 98.0 104.0 103.0 104.0 79.0 89.0 92.0 104.0 92.0
7 103.0 91.0 97.0 101.0 116.0 83.0 117.0 118.0 106.0
8 105.0 105.0 110.0 91.0 92.0 82.0 100.0 104.0 110.0
9 92.0 102.0 82.0 101.0 93.0 128.0 101.0 109.0 125.0
10 79.0 99.0 103.0 97.0 104.0 101.0 93.0 93.0 98.0
 
10
1 73.0
2 88.0
3 99.0
4 114.0
5 103.0
6 99.0
7 99.0
8 89.0
9 98.0
10 105.0
Expect = 99.75
Chi-squared = 104.31 DF = 99.
Probability = 0.3379
Published date: 03/19/2020
Last modified date: 03/19/2020