NAG Library Routine Document
G08AGF
1 Purpose
G08AGF performs the Wilcoxon signed rank test on a single sample of size .
2 Specification
SUBROUTINE G08AGF ( |
N, X, XME, TAIL, ZER, W, WNOR, P, N1, WRK, IFAIL) |
INTEGER |
N, N1, IFAIL |
REAL (KIND=nag_wp) |
X(N), XME, W, WNOR, P, WRK(3*N) |
CHARACTER(1) |
TAIL, ZER |
|
3 Description
The Wilcoxon one-sample signed rank test may be used to test whether a particular sample came from a population with a specified median. It is assumed that the population distribution is symmetric. The data consists of a single sample of observations denoted by . This sample may arise from the difference between pairs of observations from two matched samples of equal size taken from two populations, in which case the test may be used to test whether the median of the first population is the same as that of the second population.
The hypothesis under test,
, often called the null hypothesis, is that the median is equal to some given value
, and this is to be tested against an alternative hypothesis
which is
- : population median ; or
- : population median ; or
- : population median ,
using a two tailed, upper tailed or lower tailed probability respectively. You select the alternative hypothesis by choosing the appropriate tail probability to be computed (see the description of parameter
TAIL in
Section 5).
The Wilcoxon test differs from the Sign test (see
G08AAF) in that the magnitude of the scores is taken into account, rather than simply the direction of such scores.
The test procedure is as follows
(a) |
For each , for , the signed difference is found, where is a given test value for the median of the sample. |
(b) |
The absolute differences are ranked with rank and any tied values of are assigned the average of the tied ranks. You may choose whether or not to ignore any cases where by removing them before or after ranking (see the description of the parameter ZER in Section 5). |
(c) |
The number of nonzero is found. |
(d) |
To each rank is affixed the sign of the to which it corresponds. Let . |
(e) |
The sum of the positive-signed ranks, , is calculated. |
G08AGF returns
(a) |
the test statistic ; |
(b) |
the number of nonzero ; |
(c) |
the approximate Normal test statistic , where
|
(d) |
the tail probability, , corresponding to , depending on the choice of the alternative hypothesis, . |
If , is computed exactly; otherwise, an approximation to is returned based on an approximate Normal statistic corrected for continuity according to the tail specified.
The value of can be used to perform a significance test on the median against the alternative hypothesis. Let be the size of the significance test (that is, is the probability of rejecting when is true). If then the null hypothesis is rejected. Typically might be or .
4 References
Conover W J (1980) Practical Nonparametric Statistics Wiley
Neumann N (1988) Some procedures for calculating the distributions of elementary nonparametric teststatistics Statistical Software Newsletter 14(3) 120–126
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
5 Parameters
- 1: – INTEGERInput
-
On entry: , the size of the sample.
Constraint:
.
- 2: – REAL (KIND=nag_wp) arrayInput
-
On entry: the sample observations, .
- 3: – REAL (KIND=nag_wp)Input
-
On entry: the median test value, .
- 4: – CHARACTER(1)Input
-
On entry: indicates the choice of tail probability, and hence the alternative hypothesis.
- A two tailed probability is calculated and the alternative hypothesis is : population median .
- An upper tailed probability is calculated and the alternative hypothesis is : population median .
- A lower tailed probability is calculated and the alternative hypothesis is : population median .
Constraint:
, or .
- 5: – CHARACTER(1)Input
-
On entry: indicates whether or not to include the cases where
in the ranking of the
's.
- All are included when ranking.
- All , are ignored, that is all cases where are removed before ranking.
Constraint:
or .
- 6: – REAL (KIND=nag_wp)Output
-
On exit: the Wilcoxon rank sum statistic, , being the sum of the positive ranks.
- 7: – REAL (KIND=nag_wp)Output
-
On exit: the approximate Normal test statistic,
, as described in
Section 3.
- 8: – REAL (KIND=nag_wp)Output
-
On exit: the tail probability,
, as specified by the parameter
TAIL.
- 9: – INTEGEROutput
-
On exit: the number of nonzero 's, .
- 10: – REAL (KIND=nag_wp) arrayWorkspace
-
- 11: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
-
On entry, | , or . |
or | or . |
-
-
The whole sample is identical to the given median test value.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
The approximation used to calculate when will return a value with a relative error of less than for most cases. The error may increase for cases where there are a large number of ties in the sample.
8 Parallelism and Performance
G08AGF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The time taken by G08AGF increases with , until , from which point on the approximation is used. The time decreases significantly at this point and increases again modestly with for .
10 Example
This example performs the Wilcoxon signed rank test on two matched samples of size , taken from two populations. The distribution of the differences between pairs of observations from the two populations is assumed to be symmetric. The test is used to test whether the medians of the two distributions of the populations are equal or not. The test statistic, the approximate Normal statistic and the two tailed probability are computed and printed.
10.1 Program Text
Program Text (g08agfe.f90)
10.2 Program Data
Program Data (g08agfe.d)
10.3 Program Results
Program Results (g08agfe.r)