SNRNK
Performs a Wilcoxon signed rank test.
Required Arguments
Y — Vector of length NOBS containing the data. (Input)
FUZZ — Constant used to determine when a value is 0.0 or when two values are tied. (Input)
When ∣Y(i)∣ or ∣Y(i) ‑ Y(j)∣ is less than or equal to FUZZ, then the i‑th observation is taken to be zero, or the i‑th and j‑th observations are said to be tied, respectively.
STAT — Vector of length 10 containing the computed statistics. (Output)
Statistics are computed in two ways. In method 1, the average rank of tied observations is used, and observations equal to zero are not counted. In method 2, ties are randomly broken, and observations equal to zero are randomly assigned to the positive or negative half line.
I |
STAT(I) |
1 |
The positive rank sum, W+, using method 1. |
2 |
The absolute value of the negative rank sum, W‑, using method 1. |
3 |
The standardized (to an asymptotic variance of 1.0) minimum of (W+, W‑) using method 1. |
4 |
The asymptotic probability of not exceeding STAT(3) under the null hypothesis that the distribution is symmetric about 0.0. |
5 |
The positive rank sum, W+, using method 2. |
6 |
The absolute value of the negative rank sum, W‑, using method 2. |
7 |
The standardized (to an asymptotic variance of 1.0) minimum of (W+, W‑) using method 2. |
8 |
The asymptotic probability of not exceeding STAT(7) under the null hypothesis that the distribution is symmetric about 0.0. |
9 |
The number of zero observations. |
10 |
The total number of observations that are tied, and that are not within FUZZ of zero. |
Optional Arguments
NOBS — Number of observations. (Input)
Default: NOBS = size (Y,1).
NMISS — Number of missing values in Y. (Output)
FORTRAN 90 Interface
Generic: CALL SNRNK (Y, FUZZ, STAT [, …])
Specific: The specific interface names are S_SNRNK and D_SNRNK.
FORTRAN 77 Interface
Single: CALL SNRNK (NOBS, Y, FUZZ, STAT, NMISS)
Double: The double precision name is DSNRNK.
Description
Routine SNRNK performs a Wilcoxon signed rank test of symmetry about zero. In one sample, this test can be viewed as a test that the population median is zero. In matched samples, a test that the medians of the two populations are equal can be computed by first computing difference scores. These difference scores would then be used as input to SNRNK. A general reference for the methods used is Conover (1980).
Routine SNRNK computes statistics for two methods for handling zero and tied observations. In the first method, observations within FUZZ of zero are not counted, and the average rank of tied observations is used. (Observations within FUZZ of each other are said to be tied.) In the second method, observations within FUZZ of zero are randomly assigned a positive or negative sign, and the ranks of tied observations are randomly permuted.
The W+ and W‑ statistics are computed as the sums of the ranks of the positive observations and the sum of the ranks of the negative observations, respectively. Asymptotic probabilities are computed using standard methods (see, e.g., Conover 1980, page 282).
The W+ and W‑ statistics may be used to test the following hypotheses about the median, M. In deciding whether to reject the null hypothesis, use the bracketed statistic if method 2 for handling ties is preferred. Possible null hypotheses and alternatives are given as follows:
-
H0 : M ≤ 0 H1 : M > 0
Reject if STAT(1) [or STAT(5)] is too large.
-
H0 : M ≥ 0 H1 : M < 0
Reject if STAT(2) [or STAT(6)] is too large.
-
H0 : M = 0 H1 : M ≠ 0
Reject if STAT(3) [or STAT(7)] is too small. Alternatively, if an asymptotic test is desired, reject if 2 * STAT(4) [or 2 * STAT(8)] is less than the significance level.
-
Tabled values of the test statistic can be found in the references. If possible, tabled values should be used. If the number of nonzero observations is too large, then the asymptotic probabilities computed by SNRNK can be used.
The assumptions required for the hypothesis tests are as follows:
-
The distribution of each Xi is symmetric.
-
The Xi are mutually independent.
-
All Xi’s have the same median.
-
An ordering of the observations exists (i.e., X1 > X2 and X2 > X3 implies that X1 > X3).
-
If other assumptions are made, related hypotheses that are more (or less) restrictive can be tested.
Comments
1. Workspace may be explicitly provided, if desired, by use of S2RNK/DS2RNK. The reference is:
CALL S2RNK (NOBS, Y, FUZZ, ISEED, STAT, NMISS, IR, YRANK)
The additional arguments are as follows:
IR — Work vector of length NOBS.
YRANK — Work vector of length NOBS.
If Y is not needed, Y and YRANK can share the same storage locations.
2. Informational errors
Type |
Code |
Description |
3 |
4 |
NOBS is less than 50 and exact tables should be referenced for probabilities. |
3 |
5 |
Each element of Y is within FUZZ of 0. STAT(1) through STAT(8) are set to NaN (not a number). |
3. The signed rank statistic provides a test of the hypothesis that the population median is equal to zero. To test that the median is equal to some other value, say, 10.0, use the routine SADD (IMSL MATH/LIBRARY) to subtract 10.0 from each observation prior to calling SNRNK.
4. The signed rank test can be used to test that the medians of two matched random variables are equal. This is the nonparametric equivalent of the paired t‑test. To use SNRNK to perform this test, use the routine SAXPY (IMSL MATH/LIBRARY) prior to calling SNRNK to compute the differences, Y(i) ‑ X(i). Then, call SNRNK with these differences.
5. The routine RNUN (see Chapter 18, “Random Number Generation”) is used to randomly break ties. The routine RNSET in Chapter 18 can be used to initialize the seed of the random number generator. The routine RNOPT (also in Chapter 18) can be used to select the form of the generator.
Example
This example illustrates the application of the Wilcoxon signed rank test to a test on two matched samples (matched pairs). A test that the median difference is 10.0 (rather than 0.0) is performed by subtracting 10.0 from each of the differences prior to calling SNRNK. The routine RNSET (Chapter 18, “Random Number Generation”) is used to set the seed. As can be seen from the output, the null hypothesis is rejected. The warning error will always be printed when the number of observations is 50 or less unless printing is turned off for warning errors. See routine ERSET in the Reference Material.
USE WRRRN_INT
USE RNSET_INT
USE SNRNK_INT
USE UMACH_INT
IMPLICIT NONE
INTEGER NOBS
REAL FUZZ
PARAMETER (FUZZ=0.0001, NOBS=7)
!
INTEGER I, NMISS, NOUT
REAL STAT(10), W(NOBS), X(NOBS), Y(NOBS)
!
DATA W/223, 216, 211, 212, 209, 205, 201/
DATA X/208, 205, 202, 207, 206, 204, 203/
!
DO 10 I=1, NOBS
Y(I) = X(I) - W(I) - 10.0
10 CONTINUE
! Print Y prior to calling SNRNK
CALL WRRRN ('Y', Y, 1, NOBS, 1, 0)
! Initialize the seed
CALL RNSET (123457)
!
CALL SNRNK (Y, FUZZ, STAT, NMISS=NMISS)
! Print output
CALL UMACH (2, NOUT)
WRITE (NOUT,99999) STAT(1), STAT(5), STAT(2), STAT(6), STAT(3), &
STAT(7), STAT(4), STAT(8), STAT(9), STAT(10), &
NMISS
!
99999 FORMAT (' Statistic Method 1 Method 2', &
/, ' W+.......................', F9.0, 4X, F9.0, /, &
' W-.......................', F9.0, 4X, F9.0, /, &
' Standardized Minimum.....', F9.4, 4X, F9.4, /, &
' p-value..................', F9.4, 4X, F9.4, //, &
' Number of zeros..........', F9.0, /, ' Number of ', &
'ties...........', F9.0, /, ' Number of missing........', &
I5)
!
END
Output
Y
1 2 3 4 5 6 7
-25.00 -21.00 -19.00 -15.00 -13.00 -11.00 -8.00
*** WARNING ERROR 4 from SNRNK. NOBS = 7. The number of
*** observations, NOBS, is less than 50, and exact
*** tables should be referenced for probabilities.
Statistic Method 1 Method 2
W+....................... 0. 0.
W-....................... 28. 28.
Standardized Minimum..... -2.3664 -2.3664
p-value.................. 0.0090 0.0090
Number of zeros.......... 0.
Number of ties........... 0.
Number of missing........ 0