Five people are measured before and after a change, and their differences, after minus before, are , , , and units. With five values there is little to check a normal model against, so it is natural to ask a question that needs less, using only the direction of each change or the direction together with the order of the sizes. The first idea gives the sign test and the second gives the Wilcoxon signed-rank test. This lesson builds both, shows that they test different null hypotheses under different conditions, and settles how zero differences and tied magnitudes are handled.
Key terms
Sign test
Definition Let be independent observations from one population of differences . In paired data each is a within-pair difference such as after minus before. For a one-sample question about a value , use . The sign test of
drops the zero differences and counts the positive ones. If of the differences are nonzero and of them are positive, then under , conditional on ,
The p-value is computed from this binomial distribution, with the rule for what counts as extreme fixed in advance. For a two-sided test it is the probability of a count at least as far from as the observed one. When has a continuous distribution, and says exactly that , so is a median of . This is why the sign test is used as a test about a population median.
In plain words Each nonzero difference is like a coin toss between up and down. If ups and downs are equally likely in the population, the number of ups behaves like the number of heads in fair tosses. The test never looks at how large the differences are.
Example For the differences , , , and there are nonzero differences and positive ones. Under the expected count is . The observed count is away from it, and every possible count from to is at least that far away, so
The count is as close to the center as a count out of five can be. The p-value of does not mean that has probability . The sample median is and the sample mean is , and neither size enters the test.
Signed rank
Definition Take the nonzero differences and rank their absolute values from for the smallest to for the largest. The signed rank of is that rank with the sign of attached. The positive rank sum adds the ranks of the positive differences, and adds the ranks of the negative ones. Every rank goes into exactly one of the two sums, and the ranks add to , so
In plain words A rank keeps the order of the sizes and forgets the gaps between them. The largest difference gets rank whether it is slightly or enormously larger than the next one, so a single extreme value cannot dominate .
Example For , , , and the absolute values , , , and have ranks , , , and . Ranks and sizes agree here only because the sizes happen to be the whole numbers to . The signed ranks are , , , and , so
and the two sums add to . If the largest difference were instead of , the mean would jump from to , but every rank and the value would stay the same.
Wilcoxon signed-rank test
Definition Let be independent observations from a continuous distribution, so that zero differences and tied absolute values occur with probability . The Wilcoxon signed-rank test uses the statistic to test the null hypothesis that and have the same distribution, which says that the distribution of is symmetric about . Under , given the absolute values, the signs are independent and each is positive or negative with probability . So all ways of attaching signs to the ranks are equally likely, and computing for each of them gives its exact null distribution, with
If the differences are assumed to be symmetric about some center , under the null and the alternative alike, the test is a test of . The center is then a median of , and it is also the mean when the mean exists.
In plain words Symmetry about means that every interval of values is exactly as likely as its mirror image on the other side of . Then each rank is equally likely to carry either sign, and should land near half the total rank sum. Symmetry is a stronger condition than a median of . If the median is but the positive differences are typically larger in size than the negative ones, the positive differences collect the high ranks and tends to exceed its null center. So the usual signed-rank test is not a test of the median alone.
Example For there are equally likely sign patterns, and the null center is . The observed lies above it, so the two-sided rule counts the patterns with or . The low values arise as follows.
| Sign patterns |
That is patterns, and by symmetry another give , so
Some software reports the smaller sum instead, which gives the same p-value. The sign test gave for the same data. The two tests use different information and rest on different conditions, so the test should be chosen for its question before either p-value is seen. With five nonzero differences the smallest possible two-sided p-value is for both tests, so neither two-sided test can reject at the percent level, whatever the data.
Zero differences
Definition A zero difference has no sign, so each procedure needs a stated convention for it. The sign test and the usual Wilcoxon procedure drop the zeros and use the number of nonzero differences in place of . Pratt’s method instead ranks the zeros together with the nonzero absolute values, so that the zeros take the smallest ranks, and then leaves those ranks out of both and . The two conventions can give different statistics and different reference distributions. For the sign test with zeros dropped, the binomial reference rests on the null . When equals with positive probability, a median of does not imply this null.
In plain words Dropping a zero from the test does not erase it from the data. Report how many zeros there were and which convention was used. With discrete or rounded measurements zeros can be common, and the null of the sign test then has to be stated as a comparison of the chances of a positive and a negative difference, not as a median of .
Example For the differences , and , dropping the zero leaves the ranks and for the sizes and , so and . Pratt’s method ranks the sizes , and as , and and discards the rank of the zero, so and . Now take a discrete difference with
Its median is , because and are both at least . Yet a nonzero difference is positive with probability , so the sign test rejects with probability approaching as the sample grows. It correctly rejects , which is false here, but the rejection is not evidence against a median of .
Tied ranks
Definition When several nonzero absolute differences are equal, each of them gets the average of the rank positions the group occupies, called a midrank. Midranks keep the total rank sum at . If the signs are independent and each is positive with probability given the absolute values, as under the signed-rank null, then with midranks
which is smaller than the untied value whenever a tie occurs. Ties also change which values of are possible and how likely each one is. An exact reference therefore attaches all sign patterns to the actual midranks, and a normal approximation uses the variance above. A table built for the ranks no longer applies.
In plain words Tied sizes share their positions evenly. The sum of the ranks does not change, but the possible values of do, so the p-value has to come from a calculation that knows about the ties. A p-value that software labels exact is worth checking for how it treated ties and zeros.
Example For the differences , , and the absolute values are , , and . The two values occupy positions and , so each gets rank , and the others get ranks and . Then and , which add to . Attaching all sign patterns to the ranks , , and never produces , a value that occurs in of the patterns for the untied ranks , , and . The squared midranks , , and add to , so the null variance is
below the untied . Every attainable value is at least from the center , so the observed gives a two-sided p-value of .
Distribution-free method
Definition A test is distribution-free over a stated class of null distributions if its test statistic has the same null distribution for every distribution in that class. The reference distribution can then be computed without knowing the shape of the population. Given the number of nonzero differences, the sign count is distribution-free over all distributions with , for independent observations. The signed-rank statistic is distribution-free over all continuous distributions symmetric about , for independent observations. Methods of this kind are often called nonparametric. Distribution-free does not mean assumption-free, since independence, the class of distributions that defines the null, and a convention for zeros and ties remain conditions of the method.
In plain words The null calculation needs no normal curve, but that does not mean anything goes. If the observations are dependent, or if the differences are skewed and the signed-rank test is read as a test of a median of , the reference distribution need not match how the statistic behaves when the null of interest is true, even though no normal model was used.
Example For five untied differences, has the same -pattern null distribution whether the differences come from a normal, a uniform or any other continuous distribution symmetric about . The paired t test instead takes its reference, the t distribution with degrees of freedom, from a normal model for the differences. Both rank methods still need independence. If two of the five pairs were the same person measured twice, the five signs need not behave like independent coin tosses, and both the binomial reference and the equally likely patterns would lose their justification.
Check yourself
- Twelve pairs give positive differences, negative difference and zero differences. Find the two-sided sign test p-value with zeros dropped.
Show the answer
Dropping the zeros leaves nonzero differences with positive. Under the count follows , so
The counts at least as far from as the observed are , , and , and the distribution is symmetric, so the two-sided p-value is . The report should also say that of the differences were zero and were left out of the test.
- Paired differences are , , , and . Find and the exact two-sided signed-rank p-value, compare it with the two-sided sign test p-value, and name the condition the signed-rank analysis needs.
Show the answer
The absolute values , , , and have ranks , , , and . The only negative difference has rank , so and . The null center is and the observed value is above it. Among the sign patterns, happens for of them (all positive, or all positive except rank ) and for another , so
The sign test sees positive signs out of . Counts at least from are , , and , with probability . The signed-rank p-value is smaller because it also uses the fact that the one negative difference is the smallest. Using that information is justified by the condition that, under , the differences are independent and symmetric about . Neither test rejects at the percent level, and the choice between them belongs before the data are seen.
- Paired changes come from a skewed population. With probability a change is uniform on , and with probability it is uniform on . Is the population median? Is the usual signed-rank test a valid test of a median of here, and which test fits that question better?
Show the answer
Yes. Exactly half of the probability lies on each side of , and the density is positive just below and just above , so is the unique median. The distribution is not symmetric, though. A positive change is uniform on and the size of a negative change is uniform on , so a positive change is larger in size than a negative one with probability . Positive changes therefore tend to take the high ranks, and is pushed above its null center although the median is .
The symmetry condition of the signed-rank test fails, so it is not a valid test of a median of here. In a simulation of samples of changes from this population, the exact two-sided signed-rank test at the percent level rejected in about percent of the samples. The sign test needs only , which holds, and it rejected in about percent of the samples, matching its exact size of about for differences. The sign test fits the median question, at the cost of ignoring the sizes of the changes.