For $n$ independent nonzero paired differences, the sign test refers the number of plus signs to the binomial with $p = \tfrac12$, exactly for every $n$. Wilcoxon's signed-rank statistic $W^+$, the sum of the ranks of the positive differences, has an exact null distribution from the $2^n$ equally likely sign patterns, with mean $n(n+1)/4$ and variance $n(n+1)(2n+1)/24$, reduced for ties. On Student's sleep data, the second drug against the first, the sign test gives $p = 0.0039$. The sign test tests whether positive and negative differences are equally common, which is a test of the median only for continuous data. The signed-rank test responds to $P(D_1 + D_2 > 0)$ and tests a center only for symmetric differences. Under normality they need about 5% and 57% more pairs than the paired $t$-test; for heavy tails, fewer.
Ten patients each took two sleeping drugs. On the second drug every patient but one slept longer than on the first, and the remaining patient slept the same. The paired t-test summarized the ten differences by their mean, 1.58 hours, and their standard deviation, and found $p = 0.0028$. That $p$-value assumes the differences come from a normal population. Ten values cannot confirm it, and one of them, 4.6 hours, is nearly twice the next largest. Can we test whether the second drug helps without assuming anything about the shape of the differences?
R. A. Fisher, analyzing the same data in 1925, added a check that needed no such assumption. If the drugs were equally effective, each of the nine nonzero differences would be as likely to be negative as positive. All nine would then share the same sign by chance "only twice in 512 trials" (Fisher, 1925, §24; see Hypothesis Tests for a Mean). That calculation uses nothing but the signs of the differences. It does not assume that the differences are normal, or that their mean describes them well. It does not even assume a scale on which subtraction means anything beyond "more" or "less".
This article develops two tests built on that idea:
- The sign test counts how many differences are positive and refers the count to a binomial distribution.
- The Wilcoxon signed-rank test, proposed by Frank Wilcoxon (1945), also uses the order of the differences' sizes. It ranks the absolute differences and adds up the ranks that carry a plus sign.
First we state what each test's null hypothesis says, and work the sign test. Then we build the signed-rank test and find its exact null distribution by counting sign patterns, on drug 1 alone and on Wilcoxon's own example. Next comes the normal approximation, with corrections for ties and zero differences, on repeated NHANES blood pressure readings. Finally we establish what each test actually tests and what it costs, in efficiency and power, against the $t$-test, and solve three problems in full. The article assumes The Paired Samples t-Test. It is the unit's home of exact null distributions by counting and the correction for ties; the rank-sum test and the Kruskal–Wallis test build on both. The efficiencies it quotes are derived in Asymptotic Relative Efficiency of Rank Tests.
Paired data and the null hypothesis
The setting is the one of the paired t-test. Either there are $n$ pairs of measurements, each reduced to a difference $d_i = x_{i2} - x_{i1}$, or there is a single sample $x_1, \dots, x_n$ to be compared with a hypothesized center $m_0$, in which case $d_i = x_i - m_0$. Write $D$ for the difference of a randomly chosen pair. The $t$-test asks whether $E(D) = 0$, and it needs $D$ to be roughly normal in small samples. The rank tests ask about the distribution of $D$ in other terms, and their null hypotheses differ:
- the sign test asks whether $D$ is as likely to be positive as negative, $P(D > 0) = P(D < 0)$; when $D$ is continuous this says that the median of $D$ is 0;
- the signed-rank test asks whether $D$ is symmetric about 0, that is, whether $D$ and $-D$ have the same distribution.
For a symmetric distribution the center of symmetry is both the median and (if it exists) the mean. So under symmetry all three tests are about the same number. When the distribution of the differences is skewed they part ways. The section on what each test tests shows by example that they can then reach different conclusions on the same population, each correctly.
Throughout, a difference of exactly zero carries no sign. The usual convention, Wilcoxon's, is to drop such pairs and let $n$ be the number of nonzero differences. An alternative due to Pratt (1959) is described with the normal approximation below.
The sign test
Here is the idea in one sentence: if the null hypothesis holds, each nonzero difference is a fair coin toss, so the number of plus signs is binomial.
Let $S$ be the number of positive differences among the $n$ nonzero ones. If the pairs are independent and $P(D > 0) = P(D < 0)$, then each nonzero difference is positive with probability $\tfrac{1}{2}$, independently of the others, so
$$S \sim \text{Binomial}\left(n, \tfrac{1}{2}\right), \qquad P(S = s) = \binom{n}{s}\frac{1}{2^n}, \quad s = 0, 1, \dots, n.$$
Large and small values of $S$ are both evidence against $H_0$. Because the binomial with $p = \tfrac12$ is symmetric, the two-sided $p$-value is twice the smaller tail:
$$p = \min\left\{1,\ 2\,P\big(S \le \min(s, n - s)\big)\right\} = \min\left\{1,\ \frac{2}{2^n}\sum_{i=0}^{\min(s,\,n-s)}\binom{n}{i}\right\}.$$
It is exact for every $n$. No approximation is involved, and no assumption beyond independent pairs and the null hypothesis itself. It is the exact binomial test of a proportion with $p_0 = \tfrac12$, which Inference on Proportions develops for any $p_0$. Applied to paired yes-or-no outcomes, it is McNemar's test.
Back to the ten sleep patients. Nine differences are positive, none is negative and one is zero, so $n = 9$, $s = 9$ and
$$p = 2\,P(S = 9) = 2 \cdot \frac{1}{512} = 0.0039.$$
This is Fisher's calculation: all nine signs alike, plus or minus, twice in 512. It is also the smallest two-sided $p$-value the sign test can produce with nine pairs, since the data are as extreme as nine signs can be. The test gives up what the paired $t$-test used, the sizes of the differences. Nothing in its result reflects that one patient gained 4.6 hours and another 0.8.
For large $n$ the binomial is approximated by the normal with the same mean and variance. The Binomial Distribution proves that these are $np = n/2$ and $np(1-p) = n/4$ when $p = \tfrac12$, and The Normal Approximation to the Binomial treats the approximation and its continuity correction. The correction is one half, because $S$ moves in steps of 1:
$$z = \frac{|s - n/2| - \tfrac12}{\sqrt{n/4}}.$$
The approximation is worked on a larger sample in the section on repeated blood pressure readings. The sign test throws away all information about the sizes of the differences. The next test keeps some of it.
The Wilcoxon signed-rank test
The sign test treats a difference of 0.8 hours and one of 4.6 hours alike. Wilcoxon's refinement keeps the order of the sizes, though not the sizes themselves. Rank the absolute values $|d_1|, \dots, |d_n|$ from 1 (smallest) to $n$ (largest). Tied values get the mean of the ranks they span, called their midrank. Then attach to each rank the sign of its difference. The test statistic is
$$W^+ = \sum_{i:\, d_i > 0} r_i,$$
the sum of the ranks of the positive differences, where $r_i$ is the rank of $|d_i|$. Its complement $W^- = \sum_{i:\,d_i<0} r_i$ carries the same information, because the ranks always add up to $1 + 2 + \cdots + n$:
$$W^+ + W^- = \frac{n(n+1)}{2}.$$
Wilcoxon (1945) worked with the smaller of the two sums, "the sum of rank numbers of one sign only, + or −, whichever is less", and tabulated its small values in his Table II. Software usually reports one of the two sums, and the $p$-value is the same either way.
The null distribution, by counting
Here is the idea: under the null hypothesis the signs are fair coin tosses attached to fixed ranks, so we can list every outcome.
Under $H_0$ the distribution of $D$ is symmetric about 0. The sign of $D$ is then independent of its size $|D|$, and each sign is $+$ or $-$ with probability $\tfrac12$.
Proof. Symmetry says that $D$ and $-D$ have the same distribution. So for any set $A$ of positive sizes,
$$P(D > 0,\ |D| \in A) = P(D \in A) = P(-D \in A) = P(D < 0,\ |D| \in A).$$
The two outer probabilities add up to $P(|D| \in A)$, so each is half of it:
$$P(D > 0,\ |D| \in A) = \tfrac12\,P(|D| \in A).$$
Given any information about the size of a nonzero difference, then, its sign is plus with probability $\tfrac12$. That is independence of sign and size. The argument does not use continuity. It holds for discrete differences too, once the zeros are set aside. $\square$
The pairs are independent, so, given which differences are zero, the $n$ nonzero signs are independent of each other and of all $n$ sizes. The ranks depend only on the sizes. So, given the ranks, the signs attached to them are $n$ independent fair coin tosses. Every one of the $2^n$ patterns of signs is equally likely. The null distribution of $W^+$ is found by listing the patterns and adding up, for each, the ranks that carry a plus sign. This is the sign test's reasoning applied to ranks instead of counts, and like the sign test it is exact for any $n$; both are sign-flip tests in the sense of Permutation Tests. When some sizes are tied, the same statement holds with the midranks in place of the ranks $1, \dots, n$. The distribution is then exact given the observed midranks, and is called the exact conditional distribution.
The distribution is symmetric about its center $n(n+1)/4$. Reversing every sign in a pattern turns the plus ranks into the minus ranks, so it turns $W^+ = w$ into $W^+ = n(n+1)/2 - w$. The reversal matches the patterns in pairs, so each value $w$ has exactly as many patterns as its mirror image $n(n+1)/2 - w$.
For the sleep data the computation is short. Dropping the zero leaves nine differences. Their sizes and ranks are
| $\lvert d_i \rvert$ (hours) | 0.8 | 1.0 | 1.2 | 1.3 | 1.3 | 1.4 | 1.8 | 2.4 | 4.6 |
|---|---|---|---|---|---|---|---|---|---|
| Rank | 1 | 2 | 3 | 4.5 | 4.5 | 6 | 7 | 8 | 9 |
| Sign | + | + | + | + | + | + | + | + | + |
The two differences of 1.3 hours share ranks 4 and 5 and receive 4.5 each.
Example (all signs alike). The signed-rank test uses more information than the sign test, yet for these nine differences its $p$-value is the same $0.0039$, not a smaller one. All signs are positive, so $W^+ = 45$ and $W^- = 0$. Only one of the 512 sign patterns gives $W^+ = 45$ and only one gives $W^+ = 0$, so the exact two-sided $p$-value is $2/512 = 0.0039$, the same as the sign test's. When every difference has the same sign, the sizes cannot add anything. With nine pairs neither rank test can produce a $p$-value below $0.0039$, while the paired $t$-test, which uses the actual sizes, gives 0.0028.
A worked enumeration: drug 1 against no drug
All plus signs make a dull example, so we need data where the signs are mixed. Student's (1908) numbers, which he took from Cushny and Peebles (1905), are the extra hours of sleep each patient gained on a drug compared with nights without one. A more instructive case for the rank tests is the first drug on its own, and whether it adds any sleep at all. The null hypothesis is that the ten values for drug 1,
$$0.7,\ -1.6,\ -0.2,\ -1.2,\ -0.1,\ 3.4,\ 3.7,\ 0.8,\ 0.0,\ 2.0,$$
come from a distribution centered at zero. All three tests in this section find the data consistent with it. The mean of the values is 0.75 hours and their median 0.35. Five are positive, four negative and one zero.
The sign test. With $n = 9$ and $s = 5$, $P(S \ge 5) = 0.5$, so $p = 1$. Five plus signs out of nine is exactly what a fair coin would produce most often.
Example (what the ranks add to the signs). The signed-rank test finds stronger evidence of a positive center in these ten values than the sign test's $p = 1$, though not strong evidence: its $p$-value is 0.359. The reason can be read from the values before any ranking. Two of the four negative values, $-0.1$ and $-0.2$, are the smallest in size, and the three largest values are positive. So the ranks lean further toward a positive center than the plain count of signs does. The rest of this section measures how far.
The signed-rank test. The nine nonzero values ranked by size are
| $\lvert x_i \rvert$ | 0.1 | 0.2 | 0.7 | 0.8 | 1.2 | 1.6 | 2.0 | 3.4 | 3.7 |
|---|---|---|---|---|---|---|---|---|---|
| Rank | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| Sign | − | − | + | + | − | − | + | + | + |
so $W^- = 1 + 2 + 5 + 6 = 14$ and $W^+ = 45 - 14 = 31$.
To find the null distribution, the script enumerated all $2^9 = 512$ sign patterns of the ranks 1 to 9. It counted the patterns giving each value of $W^+$ from 0 to 45. The counts rise from 1 at each end to a maximum of 23 in the middle, and they are symmetric about the mean 22.5, as the reversal of signs requires. The lower tail is
| $w$ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Patterns with $W^+ = w$ | 1 | 1 | 1 | 2 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 |
| $P(W^+ \le w)$ | 0.0020 | 0.0039 | 0.0059 | 0.0098 | 0.0137 | 0.0195 | 0.0273 | 0.0371 | 0.0488 | 0.0645 | 0.0820 | 0.1016 |
For example, $W^+ = 3$ arises from two patterns: rank 3 alone positive, or ranks 1 and 2 positive. Continuing the count to $w = 14$ gives 92 patterns with $W^+ \le 14$, and by symmetry 92 with $W^+ \ge 31$, so
$$p = \frac{92 + 92}{512} = 0.359.$$
The table also gives the critical values. A two-sided test at $\alpha = 0.05$ with nine pairs rejects when $\min(W^+, W^-) \le 5$, which has actual size $2 \times 0.0195 = 0.039$. The next value, 6, would give 0.055. As with any test on a discrete statistic, the attainable levels are a finite list. In practice "$\alpha = 0.05$" means the largest attainable level that does not exceed 0.05.
The one-sample $t$-test on the same ten values gives $t = 1.326$ on 9 degrees of freedom and $p = 0.218$. The three tests agree that the data are consistent with drug 1 adding nothing. They rank the strength of the evidence in the order of the information they use:
- the sign test sees five against four ($p = 1$);
- the signed-rank test sees that the large values are mostly positive ($p = 0.359$);
- the $t$-test sees how large they are ($p = 0.218$).
Wilcoxon's own example
Does more information always mean a smaller $p$-value? Wilcoxon's own example says no. He illustrated the paired test with fifteen differences in height between cross-fertilized and self-fertilized corn (maize) plants grown in pairs. He took them from Fisher's The Design of Experiments (§17), where Fisher analyzes them as data from Charles Darwin's experiments on cross- and self-fertilization (Fisher, 1935, ch. III). In eighths of an inch, Fisher's unit, the differences were
$$6,\ 8,\ 14,\ 16,\ 23,\ 24,\ 28,\ 29,\ 41,\ -48,\ 49,\ 56,\ 60,\ -67,\ 75.$$
The two negative differences have ranks 10 and 14, so the smaller rank sum is 24. Wilcoxon read from his Table II that the probability of a total of 24 or less "is between 0.019 and 0.054 for 15 pairs", and he noted that Fisher's $t$-test gave 0.0497. The script recomputed all three tests:
- the signed-rank test, by enumerating the $2^{15} = 32{,}768$ sign patterns: exact two-sided $2\,P(W^- \le 24) = 0.0413$;
- the $t$-test: $t = 2.148$ and $p = 0.0497$, as Fisher found;
- the sign test, with 13 positive differences out of 15: $p = 0.0074$, the smallest of the three.
That reversal of the usual order is instructive. The two negative differences are among the largest in absolute size. The tests that weigh sizes, by value or by rank, are pulled toward the null by them, while the sign test counts them as two votes out of fifteen.
Recomputing Wilcoxon's Table II, his table for the paired test, by enumeration reproduces his probabilities to within 0.01, and about half of them to the third decimal; the largest differences are in the 5% column for 14 to 16 pairs. He described the tabulation as an exercise in counting partitions of integers. The number of sign patterns with $W^- = r$ is the number of ways to write $r$ as a sum of distinct ranks, which he related to tables of partitions. A computer makes the counting immediate. For small $n$ it can list the patterns. For larger $n$ it can build the distribution one rank at a time: if $P_{k}(w)$ is the distribution of the sum over the first $k$ ranks, then
$$P_{k}(w) = \tfrac12 P_{k-1}(w) + \tfrac12 P_{k-1}(w - r_k),$$
since the $k$-th rank either is or is not included, with probability one half each. The recursion works for midranks too, after doubling them so that they are whole numbers. That gives exact $p$-values in the presence of ties.
The normal approximation
Exact counting is cheap for nine pairs, but what about a few hundred? For larger $n$ the exact distribution is well approximated by a normal distribution with the same mean and variance. Here is the plan: write $W^+$ as a sum of independent pieces, one per rank, and add up their means and variances.
The formal version. Write $W^+ = \sum_{i=1}^n r_i I_i$, where $I_i = 1$ if the $i$-th rank carries a plus sign and 0 otherwise. Under $H_0$ the $I_i$ are independent with $P(I_i = 1) = \tfrac12$, so $E(I_i) = \tfrac12$ and $\operatorname{Var}(I_i) = \tfrac14$. The ranks are fixed numbers. Hence
$$E(W^+) = \frac12 \sum_{i=1}^n r_i, \qquad \operatorname{Var}(W^+) = \frac14 \sum_{i=1}^n r_i^2.$$
Without ties the ranks are $1, 2, \dots, n$, with $\sum i = n(n+1)/2$ and $\sum i^2 = n(n+1)(2n+1)/6$, so
$$E(W^+) = \frac{n(n+1)}{4}, \qquad \operatorname{Var}(W^+) = \frac{n(n+1)(2n+1)}{24},$$
and the standardized statistic is
$$z = \frac{\left|W^+ - \dfrac{n(n+1)}{4}\right| - \dfrac12}{\sqrt{\dfrac{n(n+1)(2n+1)}{24}}},$$
with the one-half a continuity correction, since $W^+$ moves in steps of 1.
Why the distribution is close to normal. $W^+$ is a sum of independent terms that do not share one distribution, so the theorem of The Central Limit Theorem for identically distributed terms does not apply. The version that does is Lyapunov's (Billingsley, 1995). For each $n$ let $X_{n1}, \dots, X_{nn}$ be independent with means zero (the terms may change with $n$, as midranks do), and let $s_n^2$ be the variance of their sum. If
$$\frac{1}{s_n^3}\sum_{i=1}^n E|X_{ni}|^3 \to 0 \quad \text{as } n \to \infty,$$
then the sum divided by $s_n$ converges in distribution to the standard normal. The theorem is cited, and its condition is checked here. Write $X_i$ for $X_{ni}$, and take $X_i = r_i\left(I_i - \tfrac12\right)$, so that $\sum X_i = W^+ - E(W^+)$. Since $I_i - \tfrac12$ is $\pm\tfrac12$, we have $|X_i| = r_i/2$ always, and
$$E|X_i|^3 = \left(\frac{r_i}{2}\right)^3, \qquad s_n^2 = \sum_{i=1}^n \left(\frac{r_i}{2}\right)^2.$$
No rank or midrank exceeds $n$, so $\sum (r_i/2)^3 \le (n/2)\sum (r_i/2)^2 = (n/2)\,s_n^2$, and the ratio is at most $n/(2 s_n)$. The ranks or midranks always total $n(n+1)/2$. By the Cauchy–Schwarz inequality $\left(\sum r_i\right)^2 \le n\sum r_i^2$, so $\sum r_i^2 \ge n(n+1)^2/4$ and $s_n \ge \sqrt{n}\,(n+1)/4$. Hence
$$\frac{1}{s_n^3}\sum_{i=1}^n E|X_i|^3 \le \frac{n}{2 s_n} \le \frac{2\sqrt{n}}{n+1} \to 0.$$
The condition holds with or without ties. So the standardized $W^+$ converges to the standard normal under the null hypothesis. The figure above shows how close it already is at $n = 9$, where the bound is $0.60$ and the ratio itself $0.42$.
Back to drug 1. There $E(W^+) = 22.5$, $\operatorname{Var}(W^+) = 9 \cdot 10 \cdot 19/24 = 71.25$, and
$$z = \frac{|31 - 22.5| - 0.5}{\sqrt{71.25}} = \frac{8}{8.441} = 0.948, \qquad p = 0.343,$$
against the exact 0.359. Without the continuity correction, $z = 1.007$ and $p = 0.314$. The correction matters most in small samples. At the exact critical values for 10, 20 and 30 pairs the script found:
| Pairs $n$ | Critical $\min(W^+, W^-)$ | Exact two-sided level | Normal, with correction | Normal, without |
|---|---|---|---|---|
| 10 | 8 | 0.0488 | 0.0528 | 0.0469 |
| 20 | 52 | 0.0484 | 0.0500 | 0.0479 |
| 30 | 137 | 0.0497 | 0.0507 | 0.0495 |
With ten or more pairs the approximation is good to about half a percentage point. Since software computes exact values, the approximation matters only for large samples.
The closed forms for the mean and variance assumed the ranks $1, \dots, n$. Real measurements are often recorded coarsely, so some of them tie, and the variance needs a correction.
Ties
Here is the idea in one sentence: midranks keep the total of the ranks but squeeze them toward their middle, so the mean of $W^+$ stays put and its variance shrinks.
When some absolute differences are tied and receive midranks, the mean $\tfrac12\sum r_i$ is unchanged. A midrank is the average of the ranks it replaces, so the total is still $n(n+1)/2$. The variance $\tfrac14\sum r_i^2$ is smaller, by an amount we now compute. Suppose $t$ consecutive ranks $a+1, \dots, a+t$ are replaced by their mean $m = a + (t+1)/2$. For any numbers $x_1, \dots, x_t$ with mean $m$,
$$\sum_{j=1}^t x_j^2 = \sum_{j=1}^t (x_j - m)^2 + t\,m^2,$$
because the cross term $2m\sum(x_j - m)$ is zero. After the replacement the sum of squares is $t\,m^2$. So the replacement reduces the sum of squares by $\sum (x_j - m)^2$, the sum of squared deviations of the $t$ consecutive ranks from their mean. Shifting by $a$ does not change deviations, so this is $t$ times the variance of the integers $1, \dots, t$. Using $\sum_{j=1}^t j^2 = t(t+1)(2t+1)/6$, that variance is
$$\frac{(t+1)(2t+1)}{6} - \left(\frac{t+1}{2}\right)^2 = \frac{(t+1)\big[2(2t+1) - 3(t+1)\big]}{12} = \frac{(t+1)(t-1)}{12} = \frac{t^2 - 1}{12},$$
and the reduction in the sum of squares is
$$t \cdot \frac{t^2 - 1}{12} = \frac{t^3 - t}{12}.$$
Summing over the groups of ties and dividing by 4,
$$\operatorname{Var}(W^+) = \frac{n(n+1)(2n+1)}{24} - \frac{1}{48}\sum_{\text{tie groups}} (t^3 - t),$$
where $t$ is the number of values in each group of tied absolute differences. Kruskal and Wallis (1952, §3.1.2, equation 3.7) derive the same reduction, $(t^3-t)/12$ in the sum of squares, for their test, and the rank-sum test and the Kruskal–Wallis test use it in this form. The correction is small unless the ties are extensive, but with measurements recorded coarsely they can be.
Zero differences
Dropping zero differences, as above, is Wilcoxon's convention and the default in most software. Its consequence is that pairs showing no change contribute nothing to the test. Pratt's alternative keeps the zeros in the ranking, where they occupy the smallest ranks, and then drops their ranks from the sum. The remaining ranks then start above 1. The mean and variance are computed from the ranks actually used, $\tfrac12\sum r_i$ and $\tfrac14\sum r_i^2$, as above. The scipy documentation describes the Pratt method as the more conservative of the two. When the zeros are few the choice hardly matters. When they are many, as in the next example, it can.
Repeated blood pressure readings
The sleep data have one tie and one zero. A sample with many of both shows the corrections at work. The NHANES examination of 2017 to 2018 took up to three systolic readings from each participant, recorded in steps of 2 mm Hg. The paired t-test article drew 40 adults at random (the script's seed 1) and analyzed the first reading minus the third. Their differences, in mm Hg, with counts, are
| Difference | −12 | −10 | −8 | −6 | −4 | −2 | 0 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 22 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Count | 1 | 1 | 2 | 2 | 6 | 6 | 7 | 3 | 4 | 1 | 1 | 1 | 1 | 3 | 1 |
The paired $t$-test gave $\bar{d} = 0.900$ mm Hg, $t = 0.790$ and $p = 0.434$. Seven differences are zero, and the rest have only eight distinct sizes, so this is a sample with heavy ties.
Sign test. There are 15 positive and 18 negative differences, $n = 33$. The exact two-sided $p$-value is 0.728; the normal approximation, $z = (|15 - 16.5| - 0.5)/\sqrt{33/4} = 0.348$, gives 0.728 as well.
Signed-rank test, zeros dropped. The 33 nonzero absolute differences take the values 2 (nine times), 4 (ten times), 6, 8, 10, 12, 14 and 22, with midranks 5, 14.5, 21, 24, 26.5, 28.5, 31 and 33. The positive differences hold ranks totaling $W^+ = 299$, and $W^- = 262$; together they make $33 \cdot 34/2 = 561$. Then:
- $E(W^+) = 33 \cdot 34/4 = 280.5$;
- without ties, $\operatorname{Var}(W^+) = 33 \cdot 34 \cdot 67/24 = 3132.25$;
- the tie groups have sizes 9, 10, 3, 3, 2, 2 and 3, so $\sum(t^3 - t)/48 = 37.375$ and $\operatorname{Var}(W^+) = 3094.875$, a standard deviation of 55.63;
- $z = (|299 - 280.5| - 0.5)/55.63 = 0.324$ and $p = 0.746$.
The exact conditional $p$-value, from the recursion over the observed midranks, is 0.748. Ignoring the tie correction changes $z$ only to 0.322.
With Pratt's treatment of zeros, the seven zeros take ranks 1 to 7 and the remaining ranks are shifted up. Then $W^+ = 404$ and $W^- = 388$, and $p = 0.919$.
All four rank-based analyses agree with the $t$-test that 40 adults cannot detect the difference. But they report it as weaker evidence than the $t$-test does ($p$ around 0.73 to 0.92 against 0.43). The reason is visible in the table. There are more negative differences than positive ones, but the positive ones include the largest: 14, 14, 14 and 22. The mean is pulled up by them; the counts of signs are not, and the ranks only partly.
The tests can weigh the same sample so differently because they do not test the same hypothesis, as the next section shows.
What each test tests
On symmetric data the three tests are three ways of asking whether the center is zero. On skewed or discrete data they ask three different questions, and the NHANES population of differences shows it. Among the 4,782 adults with a first and a third reading, the difference has
- mean 0.786 mm Hg;
- median exactly 0: 46.7% of adults have a positive difference, 15.8% a zero one and 37.5% a negative one, so neither side holds half;
- $P(D > 0 \mid D \ne 0) = 0.555$;
- for two adults chosen independently, $P(D_1 + D_2 > 0) = 0.521$ and $P(D_1 + D_2 < 0) = 0.374$.
Take the three null hypotheses in turn:
- The $t$-test's, $E(D) = 0$, is false: the mean is 0.79.
- The sign test's, $P(D > 0) = P(D < 0)$, is false too, even though the median is zero. The zeros that hold the median at 0 are exactly the observations the test discards.
- The signed-rank test's, symmetry about zero, is false as well.
What the signed-rank test responds to is the last line of the population summary, $P(D_1 + D_2 > 0)$. The signed-rank statistic is the number of positive pairwise averages. For nonzero differences without ties,
$$W^+ = \#\left\{(i, j): i \le j,\ \tfrac12(d_i + d_j) > 0\right\},$$
counting each difference with itself as well as with every other.
Proof. There are $n(n+1)/2$ pairs $(i, j)$ with $i \le j$. Assign each pair to its member of larger absolute value (to $d_i$ itself when $i = j$). Without ties, the difference of rank $r$ is assigned exactly $r$ pairs: itself with itself, and itself with each of the $r - 1$ differences of smaller absolute value. In each of these pairs the sum $d_i + d_j$ has the sign of the larger member, because the smaller one cannot outweigh it. So a positive difference of rank $r$ accounts for $r$ positive averages, and a negative difference of rank $r$ for $r$ negative ones. Adding over the positive differences, the number of positive averages is $\sum_{d_i>0} r_i = W^+$. $\square$
The averages $\tfrac12(d_i + d_j)$ are called Walsh averages. For drug 1 there are 45 of them, and 31 are positive, which is $W^+$. The identity gives the mean of $W^+$ under any continuous distribution of the differences, not only under the null hypothesis. Of the pairs, $n$ have $i = j$, and each is positive with probability $P(D > 0)$. The other $\binom{n}{2}$ have $i < j$, and each is positive with probability $P(D_1 + D_2 > 0)$. So
$$E(W^+) = n\,P(D > 0) + \binom{n}{2}\,P(D_1 + D_2 > 0).$$
For large $n$ the second term dominates. Under the null hypothesis half of the averages should be positive. So the test detects populations in which $P(D_1 + D_2 > 0)$ differs from $P(D_1 + D_2 < 0)$.
Example (a zero median, and a sign test that rejects). The population median of the differences is exactly zero, yet the sign test at $\alpha = 0.05$ rejects more and more often as the samples grow: in about half of all samples of 400, as the table below shows. Since all three nulls are false here, all three tests reject more often as the sample grows, but at different rates. The script drew 10,000 samples of each size from the population, for each of 30 seeds, and applied each test at $\alpha = 0.05$. The signed-rank test used the tie-corrected normal approximation and the sign test its exact distribution; the table gives medians over the seeds.
| Adults in the sample | Paired $t$ | Signed-rank | Sign |
|---|---|---|---|
| 25 | 0.098 | 0.091 | 0.048 |
| 50 | 0.159 | 0.149 | 0.085 |
| 100 | 0.278 | 0.259 | 0.143 |
| 200 | 0.504 | 0.469 | 0.271 |
| 400 | 0.800 | 0.764 | 0.506 |
The sign test rejects in half of the samples of 400 although the population median is exactly zero. That is not a malfunction. With continuous data the sign test is a test of the median. With discrete data it is a test of whether positive and negative differences are equally common, and here they are not. Suppose a report said "the median difference was significantly different from zero" on the strength of a sign test. It would be wrong about this population, while "positive differences were significantly more common than negative ones" would be right. The general lesson is that the choice among these tests is partly a choice of question. State the hypothesis in the terms of the test actually used.
The signed-rank test's symmetry assumption deserves the same care. It is not a technical condition to be checked and forgotten. If the differences are skewed, the signed-rank test can reject when the mean is zero, or fail to reject when the median is not, because it is testing neither. When the question is about the mean of a skewed variable, the $t$-test answers it more directly; its validity for the mean rests on the central limit theorem in moderate samples. A test on a transformed scale is the other option.
Suppose, then, that the differences are symmetric and all three tests are about the same center. The choice among them is then a matter of power, which the next section measures.
Efficiency and robustness
The rank tests use less of the information in the data than the $t$-test does, and when the data are normal they pay for it in power. When the data are not normal they can be much more powerful. Both effects can be measured.
The standard measure is the asymptotic relative efficiency of one test to another: for large samples and alternatives close to the null hypothesis, the limiting ratio of the sample sizes the two tests need to reach the same power. Asymptotic Relative Efficiency of Rank Tests defines it, derives it for these tests and tabulates it. For normal differences the efficiency relative to the $t$-test is $3/\pi = 0.955$ for the signed-rank test and $2/\pi = 0.637$ for the sign test: the signed-rank test needs about 5% more pairs than the $t$-test for the same power, and the sign test about 57% more. For the other shapes used below, the signed-rank test's efficiency is above 1 for all four (logistic, Laplace, $t$ with 3 degrees of freedom and contaminated normal). The sign test's is above 1 for the Laplace shape (2.0, against the signed-rank test's 1.5) and for the $t$ with 3 degrees of freedom, below 1 for the logistic, and 0.998 for the contaminated normal.
Power in small samples
Asymptotic efficiencies describe large samples and small effects. A simulation with 20 pairs shows how far they carry over to a small sample. The script used this design:
- the shift was $0.660\,\sigma$, which gives the paired $t$-test power 0.80 for normal differences at $\alpha = 0.05$;
- each shape was scaled to have the same standard deviation;
- each test used its exact critical value: the signed-rank test rejects when $\min(W^+, W^-) \le 52$, an exact level of 0.0484, and the sign test when the smaller count is 5 or less, a level of 0.0414.
For each shape the script drew 10,000 samples for each of 30 seeds:
| Shape | Power, paired $t$ | Signed-rank | Sign | Level of $t$ when $H_0$ is true |
|---|---|---|---|---|
| Normal | 0.801 | 0.780 | 0.598 | 0.050 |
| Logistic | 0.803 | 0.815 | 0.689 | 0.049 |
| Laplace | 0.805 | 0.855 | 0.817 | 0.046 |
| $t$, 3 df | 0.854 | 0.929 | 0.895 | 0.043 |
| Contaminated normal | 0.811 | 0.879 | 0.779 | 0.045 |
In every comparison with the $t$-test the simulation goes the way the efficiencies say: a rank test has more power than the $t$-test for exactly the shapes where its efficiency is above 1. (For the contaminated normal the sign test's efficiency is 0.998, too close to 1 to predict a direction, and its power is three points lower.) The signed-rank test gives up two percentage points of power under normality and gains one to eight under the other shapes. One comparison between the two rank tests goes the other way. For the Laplace shape the sign test has the higher efficiency, 2.0 against 1.5, but with 20 pairs the signed-rank test has the higher power, 0.855 against 0.817. The sign test here runs at the lower level, 0.041 against 0.048, but that explains only a small part of the gap. The script computed the sign test's exact power for this shape and shift: 0.816 at its own level, and about 0.825 if it is randomized up to the signed-rank test's level 0.048, still below 0.855. Most of the gap is a small-sample effect. The efficiencies are limits for large samples and small shifts, and this is an observation from the experiment at $n = 20$, not a general fact. The rank tests' levels (0.048 and 0.041 for every shape, not shown in the table) do not depend on the shape at all, since their null distributions come from counting sign patterns. The $t$-test's level drifts slightly below 0.05 for heavy-tailed data, which makes it conservative rather than invalid. Its weakness with heavy tails is not that it rejects too often. It is that the standard deviation, inflated by the extreme values, swamps the shift the test is trying to detect.
When to use which
The trade-off is moderate in both directions, and a few points settle most cases.
- The paired $t$-test is the right tool for the mean difference, and with moderate samples it is valid for skewed data too. If the question is about the mean, a rank test answers a different question.
- The signed-rank test is a good default when outliers or heavy tails are plausible and the differences can be assumed roughly symmetric. Its cost under normality is about 5% of the sample size.
- The sign test needs the least: only the direction of each difference. It is the test to use when the data are signs (better or worse, preferred A or B), when the measurements are ordinal and differences of ranks mean nothing, or when a few differences are so extreme or so doubtful that even their ranks should not count.
- None of the three tests helps with dependence between pairs, a study design that confounds the comparison, or a sample too small to detect the effect of interest.
In information retrieval, Significance Testing applies both tests to per-query differences between search engines, where their results can disagree with the $t$-test's.
Worked problems
The three problems are posed here, on the unit's sleep data and on the article's own results; none is taken from the course text. Each exercises one main result, and the script named under "In Python" checks every number.
Problem 1 (drug 2 against no drug). Student's ten values for the second drug, the extra hours of sleep each patient gained over nights without a drug, are $1.9,\ 0.8,\ 1.1,\ 0.1,\ -0.1,\ 4.4,\ 5.5,\ 1.6,\ 4.6,\ 3.4$. Test whether they come from a distribution centered at zero, with the sign test, the signed-rank test (exactly and by the normal approximation) and the one-sample $t$-test.
Solution. No value is zero, so $n = 10$ for both rank tests.
Sign test. Nine values are positive and one is negative. Under the null hypothesis the number of plus signs is $\text{Binomial}(10, \tfrac12)$, and the two-sided $p$-value is twice the probability of at most one minus sign:
$$p = \frac{2}{2^{10}}\left[\binom{10}{0} + \binom{10}{1}\right] = \frac{2 \times 11}{1024} = \frac{22}{1024} = 0.0215.$$
Signed-rank test. The sizes in order, with their ranks and signs:
| $\lvert x_i \rvert$ | 0.1 | 0.1 | 0.8 | 1.1 | 1.6 | 1.9 | 3.4 | 4.4 | 4.6 | 5.5 |
|---|---|---|---|---|---|---|---|---|---|---|
| Rank | 1.5 | 1.5 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| Sign | + | − | + | + | + | + | + | + | + | + |
The values $0.1$ and $-0.1$ tie in size, share ranks 1 and 2, and receive the midrank 1.5 each. So $W^- = 1.5$ and $W^+ = 55 - 1.5 = 53.5$.
For the exact conditional $p$-value, count the sign patterns of these ten midranks with $W^- \le 1.5$. There are three: no minus sign at all ($W^- = 0$), and a single minus sign on either of the two midranks 1.5. Any other pattern puts a minus sign on a rank of 3 or more, or on both midranks 1.5, and has $W^- \ge 3$. By the symmetry of the null distribution, three patterns have $W^+ \le 1.5$. So
$$p = \frac{3 + 3}{1024} = 0.0059.$$
For the normal approximation, $E(W^+) = 10 \cdot 11/4 = 27.5$. The one tie group has $t = 2$, so
$$\operatorname{Var}(W^+) = \frac{10 \cdot 11 \cdot 21}{24} - \frac{2^3 - 2}{48} = 96.25 - 0.125 = 96.125,$$
with square root 9.804, and
$$z = \frac{|53.5 - 27.5| - 0.5}{9.804} = \frac{25.5}{9.804} = 2.601, \qquad p = 0.0093.$$
The approximate 0.0093 is further from the exact 0.0059, in proportion, than the two values were for drug 1 (0.343 and 0.359). Here the observed value lies in the extreme tail, which holds only three patterns.
The $t$-test. The mean is $23.3/10 = 2.33$ hours and the standard deviation 2.002, so $t = 2.33/(2.002/\sqrt{10}) = 3.680$ on 9 degrees of freedom, $p = 0.0051$.
All three tests reject at $\alpha = 0.05$: the second drug adds sleep. The $p$-values fall in the order of the information used, 0.0215 for the signs, 0.0059 for the signed ranks and 0.0051 for the values, as they did for drug 1.
Problem 2 (the smallest sample that can reject). Find the smallest possible two-sided $p$-value of the sign test and of the signed-rank test with $n$ nonzero differences, and the smallest $n$ with which each test can reject at $\alpha = 0.05$ and at $\alpha = 0.01$.
Solution. The smallest $p$-value of both tests is $2/2^n$, so both need $n \ge 6$ to reject at 0.05 and $n \ge 8$ to reject at 0.01.
For the sign test the most extreme outcomes are $S = n$ and $S = 0$, each with probability $1/2^n$. For the signed-rank test the most extreme outcomes are $W^+ = n(n+1)/2$ and $W^+ = 0$. Each arises from exactly one of the $2^n$ equally likely sign patterns, all plus or all minus, since every rank is positive and any other pattern gives a sum strictly between the two. So in both tests the smallest two-sided $p$-value is $2/2^n$, whatever the ties. The values are
| $n$ | 5 | 6 | 7 | 8 |
|---|---|---|---|---|
| $2/2^n$ | 0.0625 | 0.0313 | 0.0156 | 0.0078 |
Five pairs can never reject at 0.05, and seven can never reject at 0.01. This is why the sleep data's nine like signs gave $2/512 = 0.0039$ in both tests. The $t$-test has no such floor.
Problem 3 (the tie correction on three differences). Three nonzero differences have sizes 2, 2 and 5. List the null distribution of $W^+$, and check its mean and variance against the formulas of this article.
Solution. The mean is 3 and the variance 3.375, as the formulas give. The two sizes of 2 share ranks 1 and 2, so the midranks are 1.5, 1.5 and 3. The $2^3 = 8$ sign patterns, each with probability $\tfrac18$, give
| Ranks with a plus sign | none | 1.5 | 1.5 | 1.5, 1.5 | 3 | 1.5, 3 | 1.5, 3 | all |
|---|---|---|---|---|---|---|---|---|
| $W^+$ | 0 | 1.5 | 1.5 | 3 | 3 | 4.5 | 4.5 | 6 |
The mean is $(0 + 1.5 + 1.5 + 3 + 3 + 4.5 + 4.5 + 6)/8 = 24/8 = 3$, which is $n(n+1)/4 = 3 \cdot 4/4$. The squared deviations from 3 are $9,\ 2.25,\ 2.25,\ 0,\ 0,\ 2.25,\ 2.25,\ 9$, with mean $27/8 = 3.375$. The general formula gives the same: $\tfrac14\sum r_i^2 = \tfrac14(2.25 + 2.25 + 9) = 3.375$. So does the tie-corrected form: without ties the variance would be $3 \cdot 4 \cdot 7/24 = 3.5$, and the one tie group with $t = 2$ removes $(2^3 - 2)/48 = 0.125$.
What we have learned
Under the null hypothesis each sign is a fair coin toss, so the sign test is an exact binomial test. Attaching the signs to the ranks of the sizes gives Wilcoxon's $W^+$, whose exact distribution comes from counting the $2^n$ equally likely sign patterns. Its mean and variance, reduced for ties, give a normal approximation that is already close at nine pairs. Under normality the signed-rank test needs about 5% more pairs than the $t$-test and the sign test about 57% more; for heavy tails both can need far fewer. But each test answers its own question, as the NHANES readings showed.
When the two measurements come from different people, there are no pairs to subtract. The Wilcoxon rank-sum test ranks the two samples together and counts the same way, and the Kruskal–Wallis test extends it to several groups, as Friedman's test in Comparing Systems Across Many Tasks extends the paired design to several measurements on each unit. Asymptotic Relative Efficiency of Rank Tests derives the efficiencies quoted here.
In Python
import numpy as np
from scipy import stats
drug1 = np.array([0.7, -1.6, -0.2, -1.2, -0.1, 3.4, 3.7, 0.8, 0.0, 2.0])
drug2 = np.array([1.9, 0.8, 1.1, 0.1, -0.1, 4.4, 5.5, 1.6, 4.6, 3.4])
d = np.round(drug2 - drug1, 1) # round so that equal differences tie exactly
print(stats.binomtest(9, 9).pvalue) # sign test: 9 of 9 nonzero positive, 0.0039
print(stats.wilcoxon(d).pvalue) # signed-rank, zero dropped, 0.0039
print(stats.wilcoxon(drug1)) # statistic 14 (= W-), p 0.359 (exact)
print(stats.wilcoxon(drug1, method='asymptotic', correction=True).pvalue) # 0.343
wilcoxon reports the smaller of $W^+$ and $W^-$ as its statistic, drops zeros by default (zero_method='wilcox'; 'pratt' gives Pratt's method) and applies the tie correction in its normal approximation. The rounding in the third line matters: computed in floating point, $1.9 - 0.7$ and $1.3$ may differ in the last digit, which would turn tied differences into untied ones with different ranks, a hazard the scipy documentation warns about. The outputs shown were checked with scipy 1.17.1, and every number in this article is computed by tools/experiments/applied-statistics/sign-and-signed-rank-tests.py in the site's repository, which computes the exact distributions itself.
References
- Billingsley, P. (1995). Probability and Measure (3rd ed.). New York: Wiley. The chapter on the central limit theorem (Lyapunov's condition). record · 11 pages
- Cushny, A. R., and Peebles, A. R. (1905). The action of optical isomers. II. Hyoscines. The Journal of Physiology, 32(5–6), 501–510. record · 3 pages
- Fisher, R. A. (1925). Statistical Methods for Research Workers. Edinburgh: Oliver and Boyd. §24, Ex. 19. Online edition: Classics in the History of Psychology, York University. https://psychclassics.yorku.ca/Fisher/Methods/ record · 8 pages
- Fisher, R. A. (1935). The Design of Experiments. Edinburgh: Oliver and Boyd. Chapter III, "A Historical Experiment on Growth Rate" (Darwin's experiment; Wilcoxon cites its §17). record · 4 pages
- Kruskal, W. H., and Wallis, W. A. (1952). Use of ranks in one-criterion variance analysis. Journal of the American Statistical Association, 47(260), 583–621. record · 4 pages
- National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018: Demographic Variables and Sample Weights (DEMO_J) and Blood Pressure (BPX_J) data files. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2017 record · 109 pages
- Pratt, J. W. (1959). Remarks on zeros and ties in the Wilcoxon signed rank procedures. Journal of the American Statistical Association, 54(287), 655–667. record
- SciPy.
scipy.stats.wilcoxonandscipy.stats.binomtest. SciPy reference documentation. https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.wilcoxon.html record - Student (1908). The probable error of a mean. Biometrika, 6(1), 1–25. record · 17 pages
- Wilcoxon, F. (1945). Individual comparisons by ranking methods. Biometrics Bulletin, 1(6), 80–83. record · 6 pages
Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 9 revisions