The Wilcoxon signedrank test is a nonparametric rank test for statistical hypothesis testing used either to test the location of a population based on a sample of data, or to compare the locations of two populations using two matched samples.^{[1]} The onesample version serves a purpose similar to that of the onesample Student's ttest.^{[2]} For two matched samples, it is a paired difference test like the paired Student's ttest (also known as the "ttest for matched pairs" or "ttest for dependent samples"). The Wilcoxon test is a good alternative to the ttest when the normal distribution of the differences between paired individuals cannot be assumed. Instead, it assumes a weaker hypothesis that the distribution of this difference is symmetric around a central value and it aims to test whether this center value differs significantly from zero. The Wilcoxon test is a more powerful alternative to the sign test because it considers the magnitude of the differences, but it requires this moderately strong assumption of symmetry.
The test is named after Frank Wilcoxon (1892–1965) who, in a single paper, proposed both it and the ranksum test for two independent samples.^{[3]} The test was popularized by Sidney Siegel (1956) in his influential textbook on nonparametric statistics.^{[4]} Siegel used the symbol T for the test statistic, and consequently, the test is sometimes referred to as the Wilcoxon Ttest.
There are two variants of the signedrank test. From a theoretical point of view, the onesample test is more fundamental because the paired sample test is performed by converting the data to the situation of the onesample test. However, most practical applications of the signedrank test arise from paired data.
For a paired sample test, the data consists of samples . Each sample is a pair of measurements. In the simplest case, the measurements are on an interval scale. Then they may be converted to real numbers, and the paired sample test is converted to a onesample test by replacing each pair of numbers by its difference .^{[5]} In general, it must be possible to rank the differences between the pairs. This requires that the data be on an ordered metric scale, a type of scale that carries more information than an ordinal scale but may have less than an interval scale.^{[6]}
The data for a onesample test is a set of real number samples . Assume for simplicity that the samples have distinct absolute values and that no sample equals zero. (Zeros and ties introduce several complications; see below.) The test is performed as follows:^{[7]}^{[8]}
The ranks are defined so that is the number of for which . Additionally, if is such that , then for all .
The signedrank sum is closely related to two other test statistics. The positiverank sum and the negativerank sum are defined by^{[9]} Because equals the sum of all the ranks, which is , these three statistics are related by:^{[10]} Because , , and carry the same information, any of them may be used as the test statistic.
The positiverank sum and negativerank sum have alternative interpretations that are useful for the theory behind the test. Define the Walsh average to be . Then:^{[11]}
The onesample Wilcoxon signedrank test can be used to test whether data comes from a symmetric population with a specified center (which corresponds to median, mean and pseudomedian).^{[12]} If the population center is known, then it can be used to test whether data is symmetric about its center.^{[13]}
To explain the null and alternative hypotheses formally, assume that the data consists of independent and identically distributed samples from a distribution . If can be assumed symmetric, then the null and alternative hypotheses are the following:^{[14]}
If in addition , then is a median of . If this median is unique, then the Wilcoxon signedrank sum test becomes a test for the location of the median.^{[15]} When the mean of is defined, then the mean is , and the test is also a test for the location of the mean.^{[16]}
The restriction that the alternative distribution is symmetric is highly restrictive, but for onesided tests it can be weakened. Say that is stochastically smaller than a distribution symmetric about zero if an distributed random variable satisfies for all . Similarly, is stochastically larger than a distribution symmetric about zero if for all . Then the Wilcoxon signedrank sum test can also be used for the following null and alternative hypotheses:^{[17]}^{[18]}
The hypothesis that the data are IID can be weakened. Each data point may be taken from a different distribution, as long as all the distributions are assumed to be continuous and symmetric about a common point . The data points are not required to be independent as long as the conditional distribution of each observation given the others is symmetric about .^{[19]}
Because the paired data test arises from taking paired differences, its null and alternative hypotheses can be derived from those of the onesample test. In each case, they become assertions about the behavior of the differences .
Let be the joint cumulative distribution of the pairs . In this case, the null and alternative hypotheses are:^{[20]}^{[21]}
These can also be expressed more directly in terms of the original pairs:^{[22]}
The null hypothesis of exchangeability can arise from a matched pair experiment with a treatment group and a control group. Randomizing the treatment and control within each pair makes the observations exchangeable. For an exchangeable distribution, has the same distribution as , and therefore, under the null hypothesis, the distribution is symmetric about zero.^{[23]}
Because the onesample test can be used as a onesided test for stochastic dominance, the paired difference Wilcoxon test can be used to compare the following hypotheses:^{[24]}
In real data, it sometimes happens that there is a sample which equals zero or a pair with . It can also happen that there are tied samples. This means that for some , we have (in the onesample case) or (in the paired sample case). This is particularly common for discrete data. When this happens, the test procedure defined above is usually undefined because there is no way to uniquely rank the data. (The sole exception is if there is a single sample which is zero and no other zeros or ties.) Because of this, the test statistic needs to be modified.
Wilcoxon's original paper did not address the question of observations (or, in the paired sample case, differences) that equal zero. However, in later surveys, he recommended removing zeros from the sample.^{[25]} Then the standard signedrank test could be applied to the resulting data, as long as there were no ties. This is now called the reduced sample procedure.
Pratt^{[26]} observed that the reduced sample procedure can lead to paradoxical behavior. He gives the following example. Suppose that we are in the onesample situation and have the following thirteen observations:
The reduced sample procedure removes the zero. To the remaining data, it assigns the signed ranks:
This has a onesided pvalue of , and therefore the sample is not significantly positive at any significance level . Pratt argues that one would expect that decreasing the observations should certainly not make the data appear more positive. However, if the zero observation is decreased by an amount less than 2, or if all observations are decreased by an amount less than 1, then the signed ranks become:
This has a onesided pvalue of . Therefore the sample would be judged significantly positive at any significance level . The paradox is that, if is between and , then decreasing an insignificant sample causes it to appear significantly positive.
Pratt therefore proposed the signedrank zero procedure. This procedure includes the zeros when ranking the samples. However, it excludes them from the test statistic, or equivalently it defines . Pratt proved that the signedrank zero procedure has several desirable behaviors not shared by the reduced sample procedure:^{[27]}
Pratt remarks that, when the signedrank zero procedure is combined with the average rank procedure for resolving ties, the resulting test is a consistent test against the alternative hypothesis that, for all , and differ by at least a fixed constant that is independent of and .^{[28]}
The signedrank zero procedure has the disadvantage that, when zeros occur, the null distribution of the test statistic changes, so tables of pvalues can no longer be used.
When the data is on a Likert scale with equally spaced categories, the signedrank zero procedure is more likely to maintain the Type I error rate than the reduced sample procedure.^{[29]}
From the viewpoint of statistical efficiency, there is no perfect rule for handling zeros. Conover found examples of null and alternative hypotheses that show that neither Wilcoxon's and Pratt's methods are uniformly better than the other. When comparing a discrete uniform distribution to a distribution where probabilities linearly increase from left to right, Pratt's method outperforms Wilcoxon's. When testing a binomial distribution centered at zero to see whether the parameter of each Bernoulli trial is , Wilcoxon's method outperforms Pratt's.^{[30]}
When the data does not have ties, the ranks are used to calculate the test statistic. In the presence of ties, the ranks are not defined. There are two main approaches to resolving this.
The most common procedure for handling ties, and the one originally recommended by Wilcoxon, is called the average rank or midrank procedure. This procedure assigns numbers between 1 and n to the observations, with two observations getting the same number if and only if they have the same absolute value. These numbers are conventionally called ranks even though the set of these numbers is not equal to (except when there are no ties). The rank assigned to an observation is the average of the possible ranks it would have if the ties were broken in all possible ways. Once the ranks are assigned, the test statistic is computed in the same way as usual.^{[31]}^{[32]}
For example, suppose that the observations satisfy In this case, is assigned rank 1, and are assigned rank , is assigned rank 4, and , , and are assigned rank . Formally, suppose that there is a set of observations all having the same absolute value , that observations have absolute value less than , and that observations have absolute value less than or equal to . If the ties among the observations with absolute value were broken, then these observations would occupy ranks through . The average rank procedure therefore assigns them the rank .
Under the average rank procedure, the null distribution is different in the presence of ties.^{[33]}^{[34]} The average rank procedure also has some disadvantages that are similar to those of the reduced sample procedure for zeros. It is possible that a sample can be judged significantly positive by the average rank procedure; but increasing some of the values so as to break the ties, or breaking the ties in any way whatsoever, results in a sample that the test judges to be not significant.^{[35]}^{[36]} However, increasing all the observed values by the same amount cannot turn a significantly positive result into an insignificant one, nor an insignificant one into a significantly negative one. Furthermore, if the observations are distributed symmetrically, then the values of which the test does not reject form an interval.^{[37]}^{[38]}
The other common option for handling ties is a tiebreaking procedure. In a tiebreaking procedure, the observations are assigned distinct ranks in the set . The rank assigned to an observation depends on its absolute value and the tiebreaking rule. Observations with smaller absolute values are always given smaller ranks, just as in the standard ranksum test. The tiebreaking rule is used to assign ranks to observations with the same absolute value. One advantage of tiebreaking rules is that they allow the use of standard tables for computing pvalues.^{[39]}
Random tiebreaking breaks the ties at random. Under random tiebreaking, the null distribution is the same as when there are no ties, but the result of the test depends not only on the data but on additional random choices. Averaging the ranks over the possible random choices results in the average rank procedure.^{[40]} One could also report the probability of rejection over all random choices.^{[41]} Random tiebreaking has the advantage that the probability that a sample is judged significantly positive does not decrease when some observations are increased.^{[42]} Conservative tiebreaking breaks the ties in favor of the null hypothesis. When performing a onesided test in which negative values of tend to be more significant, ties are broken by assigning lower ranks to negative observations and higher ranks to positive ones. When the test makes positive values of significant, ties are broken the other way, and when large absolute values of are significant, ties are broken so as to make as small as possible. Pratt observes that when ties are likely, the conservative tiebreaking procedure "presumably has low power, since it amounts to breaking all ties in favor of the null hypothesis."^{[43]}
The average rank procedure can disagree with tiebreaking procedures. Pratt gives the following example.^{[44]} Suppose that the observations are:
The average rank procedure assigns these the signed ranks
This sample is significantly positive at the onesided level . On the other hand, any tiebreaking rule will assign the ranks
At the same onesided level , this is not significant.
Two other options for handling ties are based around averaging the results of tiebreaking. In the average statistic method, the test statistic is computed for every possible way of breaking ties, and the final statistic is the mean of the tiebroken statistics. In the average probability method, the pvalue is computed for every possible way of breaking ties, and the final pvalue is the mean of the tiebroken pvalues.^{[45]}
Computing pvalues requires knowing the distribution of under the null hypothesis. There is no closed formula for this distribution.^{[46]} However, for small values of , the distribution may be computed exactly. Under the null hypothesis that the data is symmetric about zero, each is exactly as likely to be positive as it is negative. Therefore the probability that under the null hypothesis is equal to the number of sign combinations that yield divided by the number of possible sign combinations . This can be used to compute the exact distribution of under the null hypothesis.^{[47]}
Computing the distribution of by considering all possibilities requires computing sums, which is intractable for all but the smallest . However, there is an efficient recursion for the distribution of .^{[48]}^{[49]} Define to be the number of sign combinations for which . This is equal to the number of subsets of which sum to . The base cases of the recursion are , for all , and for all or . The recursive formula is The formula is true because every subset of which sums to either does not contain , in which case it is also a subset of , or it does contain , in which case removing from the subset produces a subset of which sums to . Under the null hypothesis, the probability mass function of satisfies . The function is closely related to the integer partition function.^{[50]}
If is the probability that under the null hypothesis when there are samples, then satisfies a similar recursion:^{[51]} with similar boundary conditions. There is also a recursive formula for the cumulative distribution function .^{[52]}
For very large , even the above recursion is too slow. In this case, the null distribution can be approximated. The null distributions of , , and are asymptotically normal with means and variances:^{[53]}
Better approximations can be produced using Edgeworth expansions. Using a fourthorder Edgeworth expansion shows that:^{[54]}^{[55]} where The technical underpinnings of these expansions are rather involved, because conventional Edgeworth expansions apply to sums of IID continuous random variables, while is a sum of nonidentically distributed discrete random variables. The final result, however, is that the above expansion has an error of , just like a conventional fourthorder Edgeworth expansion.^{[54]}
The moment generating function of has the exact formula:^{[56]}
When zeros are present and the signedrank zero procedure is used, or when ties are present and the average rank procedure is used, the null distribution of changes. Cureton derived a normal approximation for this situation.^{[57]}^{[58]} Suppose that the original number of observations was and the number of zeros was . The tie correction is where the sum is over all the sizes of each group of tied observations. The expectation of is still zero, while the expectation of is If then
Wilcoxon^{[59]} originally defined the Wilcoxon ranksum statistic to be . Early authors such as Siegel^{[60]} followed Wilcoxon. This is appropriate for twosided hypothesis tests, but it cannot be used for onesided tests.
Instead of assigning ranks between 1 and n, it is also possible to assign ranks between 0 and . These are called modified ranks.^{[61]} The modified signedrank sum , the modified positiverank sum , and the modified negativerank sum are defined analogously to , , and but with the modified ranks in place of the ordinary ranks. The probability that the sum of two independent distributed random variables is positive can be estimated as .^{[62]} When consideration is restricted to continuous distributions, this is a minimum variance unbiased estimator of .^{[63]}

order by absolute difference 

is the sign function, is the absolute value, and is the rank. Notice that pairs 3 and 9 are tied in absolute value. They would be ranked 1 and 2, so each gets the average of those ranks, 1.5.
To compute an effect size for the signedrank test, one can use the rankbiserial correlation.
If the test statistic T is reported, the rank correlation r is equal to the test statistic T divided by the total rank sum S, or r = T/S. ^{[64]} Using the above example, the test statistic is T = 9. The sample size of 9 has a total rank sum of S = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) = 45. Hence, the rank correlation is 9/45, so r = 0.20.
If the test statistic T is reported, an equivalent way to compute the rank correlation is with the difference in proportion between the two rank sums, which is the Kerby (2014) simple difference formula.^{[64]} To continue with the current example, the sample size is 9, so the total rank sum is 45. T is the smaller of the two rank sums, so T is 3 + 4 + 5 + 6 = 18. From this information alone, the remaining rank sum can be computed, because it is the total sum S minus T, or in this case 45 − 18 = 27. Next, the two ranksum proportions are 27/45 = 60% and 18/45 = 40%. Finally, the rank correlation is the difference between the two proportions (.60 minus .40), hence r = .20.
wilcox.test(x,y, paired=TRUE)
, where x and y are vectors of equal length.^{[65]}wilcoxon_test
function.[p,h] = signrank(x,y)
also returns a logical value indicating the test decision. The result h = 1 indicates a rejection of the null hypothesis, and h = 0 indicates a failure to reject the null hypothesis at the 5% significance level.value(SignedRankTest(x, y))
.((citation))
: CS1 maint: DOI inactive as of June 2024 (link)