DSQAR
Performs a d 2 test.
Required Arguments
X — Vector of length NRAN containing the data elements to be added to the test on this invocation. (Input)
COUNT — Vector of length NCELL containing the count of the number of d 2 values in each cell. (Output, if IDO = 0 or 1. Input/Output, if IDO = 2 or 3.)
EXPECT — The 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 DSQAR, and all the data are input at once.
1
This is the first invocation of DSQAR, and additional calls will be made. Initialization and updating for the NRAN data elements are performed.
2
This is an intermediate invocation of DSQAR, and updating for the NRAN data elements is performed.
3
This is the final invocation of DSQAR for this data set. Updating for the NRAN data elements is performed, followed by the wrap‑up computations.
NRAN — Number of data elements currently input in X. (Input)
NRAN may be positive or zero on any invocation of DSQAR.
Default: NRAN = size (X,1).
NCELL — The number of equiprobable cells into which the d2 statistics are to be tabulated. (Input)
Default: NCELL = size (COUNT,1).
FORTRAN 90 Interface
Generic: CALL DSQAR (X, COUNT, EXPECT, CHISQ, DF, PROB [])
Specific: The specific interface names are S_DSQAR and D_DSQAR.
FORTRAN 77 Interface
Single: CALL DSQAR (IDO, NRAN, X, NCELL, COUNT, EXPECT, CHISQ,
DF, PROB)
Double: The double precision name is DDSQAR.
Description
Routine DSQAR computes the d2 test for succeeding quadruples of hypothesized pseudorandom uniform (0, 1) deviates. The d2 test is performed as follows. Let X1, X2, X3, and X4 denote four pseudorandom uniform deviates, and consider
D2 = (X3  X1)2 + (X4  X2)2
The probability distribution of D2 is given as
when D2 1, where π denotes the value of pi. If D2 > 1, this probability is given as
See Gruenberger and Mark (1951) for a derivation of this distribution.
For each succeeding set of 4 pseudorandom uniform numbers input in X, d2 and the cumulative probability of d 2 (Pr(D2 d 2)) are computed. The resulting probability is tallied into one of k = NCELL equally spaced intervals.
Let n denote the number of sets of four random numbers input (n = the total number of observations/4). Then, under the null hypothesis that the numbers input are random uniform (0, 1) numbers, the expected value for each element in COUNT is e = n/k. An approximate chi‑squared statistic is computed as
where oi = COUNT(i) is the observed count. Thus, X2 has k  1 degrees of freedom, and the null hypothesis of pseudorandom uniform (0, 1) deviates is rejected if X2 is too large. As n increases, the chi‑squared approximation becomes better. A useful generalization is that e > 5 yields a good chi‑squared approximation.
Comments
Informational errors
Type
Code
Description
3
1
The expected value of a each cell is less than 5. The chi‑squared approximation may not be good.
4
2
The sum of the counts is equal to zero. There are no data elements so the chi‑squared statistic cannot be computed.
Example
In the following example, 2000 observations generated via routine RNUN (see Chapter 18, “Random Number Generation”) are input to DSQAR in one call. In the example, the null hypothesis of a uniform distribution is not rejected.
USE IMSL_LIBRARIES
IMPLICIT NONE
INTEGER IDO, NCELL, NROW
PARAMETER (NCELL=6, NROW=2000)
!
INTEGER NOUT
REAL CHISQ, COUNT(NCELL), DF, EXPECT, PROB, X(NROW)
!
CALL RNSET (123457)
! Generate the random numbers
CALL RNUN (X)
!
CALL DSQAR (X, COUNT, EXPECT, CHISQ, DF, PROB)
!
CALL WRRRN ('COUNT', COUNT, 1, NCELL, 1)
CALL UMACH (2, NOUT)
WRITE (NOUT,*) ' EXPECT = ', EXPECT
WRITE (NOUT,*) ' CHISQ = ', CHISQ
WRITE (NOUT,*) ' DF = ', DF
WRITE (NOUT,*) ' PROB = ', PROB
END
Output
 
COUNT
1 2 3 4 5 6
87.00 84.00 78.00 76.00 92.00 83.00
EXPECT = 83.3333
CHISQ = 2.056
DF = 5.0
PROB = 0.841343
Published date: 03/19/2020
Last modified date: 03/19/2020