SDPLC
Performs the Cox and Stuart sign test for trends in dispersion and location.
Required Arguments
X — Vector of length NOBS containing the observations in chronological order. (Input)
K — Number of consecutive X elements to be used to measure dispersion. (Input)
Not required if IOPT is different from zero.
IDS — Dispersion measure option. (Input)
If IDS is zero, the range is used as a measure of dispersion. Otherwise, the centered sum of squares is used. Not required if IOPT is different from zero.
FUZZ — Value used to determine when elements in X are tied. (Input)
If X(i X(j) is less than or equal to FUZZ, X(i) and X(j) are said to be tied. FUZZ must be nonnegative.
NSTAT — Vector of length 8. (Output)
The first 4 elements of NSTAT are the output statistics when the observations are divided into two groups. The last 4 elements are the output statistics when the observations are divided into three groups.
I
NSTAT(I)
1
Number of negative differences (two groups)
2
Number of positive differences (two groups)
3
Number of zero differences (two groups)
4
Number of differences used to calculate PSTAT(1) through PSTAT(4) (two groups).
5
Number of negative differences (three groups)
6
Number of positive differences (three groups)
7
Number of zero differences (three groups)
8
Number of differences used to calculate PSTAT(5) through PSTAT(8) (three groups).
PSTAT — Vector of length 8 containing probabilities. (Output)
The first four elements of PSTAT are computed from two groups of observations.
I
PSTAT(I)
1
Probability of NSTAT(1) + NSTAT(3) or more negative signs (ties are considered negative).
2
Probability of obtaining NSTAT(2) or more positive signs (ties are considered negative).
3
Probability of NSTAT(1) + NSTAT(3) or more negative signs (ties are considered positive).
4
Probability of obtaining NSTAT(2) or more positive signs (ties are considered positive).
The last four elements of PSTAT are computed from three groups of observations.
I
PSTAT(I)
5
Probability of NSTAT(1) + NSTAT(3) or more negative signs (ties are considered negative).
6
Probability of obtaining NSTAT(2) or more positive signs (ties are considered negative).
7
Probability of NSTAT(1) + NSTAT(3) or more negative signs (ties are considered positive).
8
Probability of obtaining NSTAT(2) or more positive signs (ties are considered positive).
Optional Arguments
NOBS — Number of observations. (Input)
Default: NOBS = size (X,1).
IOPT — Statistic option parameter. (Input)
If IOPT = 0, the Cox and Stuart tests for trends in dispersion are computed. Otherwise, the Cox and Stuart tests for trends in location are computed.
Default: IOPT = 0.
NMISS — Number of missing values in X. (Output)
FORTRAN 90 Interface
Generic: CALL SDPLC (X, K, IDS, FUZZ, NSTAT, PSTAT [])
Specific: The specific interface names are S_SDPLC and D_SDPLC.
FORTRAN 77 Interface
Single: CALL SDPLC (NOBS, X, IOPT, K, IDS, FUZZ, NSTAT, PSTAT, NMISS)
Double: The double precision name is DSDPLC.
Description
Routine SDPLC tests for trends in dispersion or location in a sequence of random variables depending upon the value of the input variable IOPT. A derivative of the sign test is used (see Cox and Stuart 1955).
Location Test
For the location test (IOPT = 1) with two groups, the observations are first divided into two groups with the middle observation thrown out if there are an odd number of observations. Each observation in group one is then compared with the observation in group two that has the same lexicographical order. A count is made of the number of times a group‑one observation is less than (NSTAT(1)), greater than (NSTAT(2)), or equal to (NSTAT(3)), its counterpart in group two. Two observations are counted as equal if they are within FUZZ of one another.
In the three‑group test, the observations are divided into three groups, with the center group losing observations if the division is not exact. The first and third groups are then compared as in the two‑group case, and the counts are stored in NSTAT(5) through NSTAT(7).
Probabilities in PSTAT are computed using the binomial distribution with sample size equal to the number of observations in the first group (NSTAT(4) or NSTAT(8)), and binomial probability p = 0.5.
Dispersion Test
The dispersion tests proceed exactly as with the tests for location, but using one of two derived dispersion measures. The input value K is used to define NOBS/K groups of consecutive observations starting with observation 1. The first K observations define the first group, the next K observations define the second group, etc., with the last observations omitted if NOBS is not evenly divisible by K. A dispersion score is then computed for each group as either the range (IDS = 0), or a multiple of the variance (IDS 0) of the observations in the group. The dispersion scores form a derived sample. The tests proceed on the derived sample as above.
Ties
Ties are defined as occurring when a group one observation is within FUZZ of its last group counterpart. Ties imply that the probability distribution of X is not strictly continuous, which means that Pr(X1 > X2) 0.5 under the null hypothesis of no trend (and the assumption of independent identically distributed observations). When ties are present, the computed binomial probabilities are not exact, and the hypothesis tests will be conservative.
Hypothesis tests
In the following, i indexes an observation from group 1, while j indexes the corresponding observation in group 2 (two groups) or group 3 (three groups).
*H0 : Pr(Xi > Xj) = Pr(Xi < Xj) = 0.5
H1 : Pr(Xi > Xj) < Pr(Xi < Xj)
Hypothesis of upward trend. Reject if PSTAT(3) (or PSTAT(7)) is less than the significance level.
*H0 : Pr(Xi > Xj) = Pr(Xi < Xj) = 0.5
H1 : Pr(Xi > Xj) > Pr(Xi < Xj)
Hypothesis of downward trend. Reject if PSTAT(2) (or PSTAT(6)) is less than the significance level.
*H0 : Pr(Xi > Xj) = Pr(Xi < Xj) = 0.5
H1 : Pr(Xi > Xj) Pr(Xi < Xj)
Two tailed test. Reject if 2 max(PSTAT (2), PSTAT(3)) (or 2 max(PSTAT (6), PSTAT(7)) is less than the significance level.
Assumptions
1. The observations are a random sample; i.e., the observations are independently and identically distributed.
2. The distribution is continuous.
Comments
1. Workspace may be explicitly provided, if desired, by use of S2PLC/DS2PLC. The reference is:
CALL S2PLC (NOBS, X, IOPT, K, IDS, FUZZ, NSTAT, PSTAT, NMISS, XWK)
The additional argument is:
XWK — Work vector of length NOBS.
If X is not needed, X and XWK can share the same storage location.
2. Informational errors
Type
Code
Description
4
4
NSTAT(4) is too small to continue with a dispersion test.
3
5
At least one tie is detected in X.
Example
This example illustrates both the location and dispersion tests. The data, which are taken from Bradley (1968), page 176, give the closing price of AT&T on the New York stock exchange for 36 days in 1965. Tests for trends in location (IOPT = 1), and for trends in dispersion (IOPT = 0) are performed. Trends in location are found.
 
USE IMSL_LIBRARIES
 
IMPLICIT NONE
INTEGER IDS, K, NOBS, IS
REAL FUZZ
PARAMETER (FUZZ=0.001, IDS=0, K=2, NOBS=36)
!
INTEGER IOPT, NSTAT(8)
REAL PSTAT(8), X(NOBS)
!
DATA X/9.5, 9.875, 9.25, 9.5, 9.375, 9.0, 8.75, 8.625, 8.0, &
8.25, 8.25, 8.375, 8.125, 7.875, 7.5, 7.875, 7.875, 7.75, &
7.75, 7.75, 8.0, 7.5, 7.5, 7.125, 7.25, 7.25, 7.125, 6.75, &
6.5, 7.0, 7.0, 6.75, 6.625, 6.625, 7.125, 7.75/
! Tests for trends in location
IOPT = 1
IS = 1
CALL SDPLC (X, K, IDS, FUZZ, NSTAT, PSTAT, IOPT=IOPT)
! Print results
CALL WROPT (-6, IS, 1)
CALL WRIRN ('NSTAT', NSTAT, 1, 8, 1, 0)
CALL WRRRN ('PSTAT', PSTAT, 1, 8, 1, 0)
! Tests for trends in dispersion
IOPT = 0
CALL SDPLC (X, K, IDS, FUZZ, NSTAT, PSTAT)
! Print results
CALL WRIRN ('NSTAT', NSTAT, 1, 8, 1, 0)
CALL WRRRN ('PSTAT', PSTAT, 1, 8, 1, 0)
!
END
 
 
Output
 
*** WARNING ERROR 5 from SDPLC. At least one tie is detected in X.
 
NSTAT
1 2 3 4 5 6 7 8
0 17 1 18 0 12 0 12
 
PSTAT
1 2 3 4 5
1.00000 0.00007 1.00000 0.00000 1.00000
 
6 7 8
0.00024 1.00000 0.00024
 
*** WARNING ERROR 5 from SDPLC. At least one tie is detected in X.
 
NSTAT
1 2 3 4 5 6 7 8
4 3 2 9 4 2 0 6
 
PSTAT
1 2 3 4 5
0.253906 0.910156 0.746094 0.500000 0.343750
6 7 8
0.890625 0.343750 0.890625