The function may be called by the names: g08agc, nag_nonpar_test_wilcoxon or nag_wilcoxon_test.
3Description
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 consist of a single sample of $n$ observations denoted by ${x}_{1},{x}_{2},\dots ,{x}_{n}$. 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, ${H}_{0}$, often called the null hypothesis, is that the median is equal to some given value $\left({X}_{\mathit{med}}\right)$, and this is to be tested against an alternative hypothesis ${H}_{1}$ which is
${H}_{1}$ : population median $\ne {X}_{\mathit{med}}$; or
${H}_{1}$ : population median $>{X}_{\mathit{med}}$; or
${H}_{1}$ : population median $<{X}_{\mathit{med}}$,
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 argument tail in Section 5).
The Wilcoxon test differs from the Sign test (see g08aac) 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 ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, the signed difference ${d}_{i}={x}_{i}-{X}_{\mathit{med}}$ is found, where ${X}_{\mathit{med}}$ is a given test value for the median of the sample.
(b)The absolute differences $\left|{d}_{i}\right|$ are ranked with rank ${r}_{i}$ and any tied values of $\left|{d}_{i}\right|$ are assigned the average of the tied ranks. You may choose whether or not to ignore any cases where ${d}_{i}=0$ by removing them before or after ranking (see the description of the argument zeros in Section 5).
(c)The number of nonzero ${d}_{i}$'s is found.
(d)To each rank is affixed the sign of the ${d}_{i}$ to which it corresponds. Let ${s}_{i}=\mathrm{sign}\left({d}_{i}\right){r}_{i}$.
(e)The sum of the positive-signed ranks, $W={\displaystyle \sum _{{s}_{i}>0}}\phantom{\rule{0.25em}{0ex}}{s}_{i}={\sum}_{i=1}^{n}\mathrm{max}\phantom{\rule{0.125em}{0ex}}({s}_{i},0.0)$, is calculated.
g08agc returns:
(a)The test statistic $W$;
(b)The number ${n}_{1}$ of nonzero ${d}_{i}$'s;
(c)The approximate Normal test statistic $z$, where
(d)The tail probability, $p$, corresponding to $W$, depending on the choice of the alternative hypothesis, ${H}_{1}$.
If ${n}_{1}\le 80$, $p$ is computed exactly; otherwise, an approximation to $p$ is returned based on an approximate Normal statistic corrected for continuity according to the tail specified.
The value of $p$ can be used to perform a significance test on the median against the alternative hypothesis. Let $\alpha $ be the size of the significance test (that is, $\alpha $ is the probability of rejecting ${H}_{0}$ when ${H}_{0}$ is true). If $p<\alpha $ then the null hypothesis is rejected. Typically $\alpha $ might be $0.05$ or 0.01.
4References
Conover W J (1980) Practical Nonparametric Statistics Wiley
Neumann N (1988) Some procedures for calculating the distributions of elementary nonparametric teststatistics Statistical Software Newsletter14(3) 120–126
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
The whole sample is identical to the given median test value.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
7Accuracy
The approximation used to calculate $p$ when ${n}_{1}>80$ will return a value with a relative error of less than 10 percent for most cases. The error may increase for cases where there are a large number of ties in the sample.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g08agc is not threaded in any implementation.
9Further Comments
The time taken by g08agc increases with ${n}_{1}$, until ${n}_{1}>80$, from which point on the approximation is used. The time decreases significantly at this point and increases again modestly with ${n}_{1}$ for ${n}_{1}>80$.
10Example
The example program performs the Wilcoxon signed rank test on two matched samples of size $8$, 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.