Wilcoxon signed-rank test
The Wilcoxon signed-rank test is a non-parametric statistical hypothesis test 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. The one-sample version serves a purpose similar to that of the one-sample Student's "t"-test. For two matched samples, it is a paired difference test like the paired Student's "t"-test (also known as the ""t"-test for matched pairs" or ""t"-test for dependent samples"). The Wilcoxon test can be a good alternative to the "t"-test  when population means are not of interest; for example, when one wishes to test whether a population's median is nonzero, or whether there is a better than 50% chance that a sample from one population is greater than a sample from another population. History. The test is named for Frank Wilcoxon (1892–1965) who, in a single paper, proposed both it and the rank-sum test for two independent samples. The test was popularized by Sidney Siegel (1956) in his influential textbook on non-parametric statistics. Siegel used the symbol "T" for the test statistic, and consequently, the test is  sometimes referred to as the Wilcoxon "T"-test. Test procedure. There are two variants of the signed-rank test. From a theoretical point of view, the one-sample test is more fundamental because the paired sample test is performed by converting the data to the situation of the one-sample test. However, most practical applications of the signed-rank test arise from paired data. For a paired sample test, the data consists of samples formula_1. 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 one-sample test by replacing each pair of numbers formula_2 by its difference formula_3. 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. The data for a one-sample test is a set of real number samples formula_4. 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: The ranks are defined so that formula_17 is the number of formula_18 for which formula_19. Additionally, if formula_20 is such that formula_21, then formula_22 for all formula_23. The signed-rank sum formula_13 is closely related to two other test statistics. The "positive-rank sum" formula_25 and the "negative-rank sum" formula_26 are defined by formula_27 Because formula_28 equals the sum of all the ranks, which is formula_29, these three statistics are related by: formula_30 Because formula_13, formula_25, and formula_26 carry the same information, any of them may be  used as the test statistic. The positive-rank sum and negative-rank sum have alternative interpretations that are useful for the theory behind the test. Define the "Walsh average" formula_34 to be formula_35. Then: formula_36 Null and alternative hypotheses. One-sample test. The one-sample Wilcoxon signed-rank test can be used to test whether data comes from a symmetric population with a specified median. If the population median is known, then it can be used to test whether data is symmetric about its center. To explain the null and alternative hypotheses formally, assume that the data consists of independent  and identically distributed samples from a distribution formula_37. If formula_38 and formula_39 are IID formula_37-distributed random variables, define formula_41 to be the cumulative distribution function of formula_42. Set formula_43 Assume that formula_37 is continuous. The one-sample Wilcoxon signed-rank sum test is a test for the following null hypothesis against one of the following alternative hypotheses: The alternative hypothesis being tested depends on whether the test statistic is used to compute a one-sided or two-sided "p"-value (and if one-sided, which side). If formula_49 is a fixed, predetermined quantity, then the test can also be used  as a test for the value of formula_50 by subtracting formula_49 from every data point. The above null and alternative hypotheses are derived from the fact that formula_52 is a consistent estimator of formula_53. It can also be derived from the description of formula_25 and formula_26 in terms of Walsh averages, since that description shows that the Wilcoxon test is the same as the sign test applied to the set of Walsh averages. Restricting the distributions of interest can lead to more interpretable null and alternative hypotheses. One mildly restrictive assumption is that formula_41 has a unique median. This median  is called the pseudomedian of formula_37; in general it is different from the mean and the median, even when all three exist. If the existence of a unique pseudomedian can be assumed true under both the null and alternative hypotheses, then these hypotheses can be restated as: Most often, the null and alternative hypotheses are stated under the assumption of symmetry. Fix a real number formula_49. Define formula_37 to be "symmetric about formula_49" if a random variable formula_68 with distribution formula_37 satisfies formula_70 for all formula_71. If formula_37 has a density function formula_73, then formula_37 is symmetric about formula_49 if  and only if formula_76 for every formula_71. If the null and alternative distributions of formula_37 can be assumed symmetric, then the null and alternative hypotheses simplify to the following: If in addition formula_87, then formula_49 is a median of formula_37. If this median is unique, then the Wilcoxon signed-rank sum test becomes a test for the location of the median. When the mean of formula_37 is defined, then the mean is formula_49, and the test is also a test for the location of the mean. The restriction that the alternative distribution is symmetric is highly restrictive, but for one -sided tests it can be weakened. Say that formula_37 is "stochastically smaller than a distribution symmetric about zero" if an formula_37-distributed random variable formula_68 satisfies formula_95 for all formula_96. Similarly, formula_37 is "stochastically larger than a distribution symmetric about zero" if formula_98 for all formula_96. Then the Wilcoxon signed-rank sum test can also be used for the following null and alternative hypotheses: 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 formula_104. The data points are not required to be independent as long as the conditional distribution of each observation given the others is symmetric about formula_104. Paired data test. Because the paired data test arises from taking paired differences, its null and alternative hypotheses can be derived from those of the one-sample test. In each case, they become assertions about the behavior of the differences formula_3. Let formula_107 be the joint cumulative distribution of the pairs formula_2. If formula_37 is continuous, then the most general null and alternative hypotheses are expressed in terms of formula_110 and are identical  to the one-sample case: Like the one-sample case, under some restrictions the test can be interpreted as a test for whether the pseudomedian of the differences is located at zero. A common restriction is to symmetric distributions of differences. In this case, the null and alternative hypotheses are: These can also be expressed more directly in terms of the original pairs: 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, formula_3  has the same distribution as formula_137, and therefore, under the null hypothesis, the distribution is symmetric about zero. Because the one-sample test can be used as a one-sided test for stochastic dominance, the paired difference Wilcoxon test can be used to compare the following hypotheses: Zeros and ties. In real data, it sometimes happens that there is a sample formula_145 which equals zero or a pair formula_2 with formula_147. It can also happen that there are tied samples. This means that for some formula_148, we have formula_149 (in the one-sample case) or formula_150 (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 formula_145 which is zero and no other zeros or ties.) Because of this, the test statistic needs to be modified. Zeros. 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. Then the standard signed-rank test could be  applied to the resulting data, as long as there were no ties. This is now called the "reduced sample procedure." Pratt observed that the reduced sample procedure can lead to paradoxical behavior. He gives the following example. Suppose that we are in the one-sample 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 one-sided "p"-value of formula_152, and therefore the sample is not significantly positive at any significance level formula_153. 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 one-sided "p"-value of formula_154. Therefore the sample would be judged significantly positive at any significance level formula_155. The paradox is that, if formula_156 is between formula_154 and formula_152, then "decreasing" an insignificant sample causes it to appear significantly "positive". Pratt therefore proposed the "signed-rank zero procedure." This procedure includes the zeros when ranking the samples. However, it  excludes them from the test statistic, or equivalently it defines formula_159. Pratt proved that the signed-rank zero procedure has several desirable behaviors not shared by the reduced sample procedure: Pratt remarks that, when the signed-rank 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 formula_148, formula_164 and formula_165 differ by at least a fixed constant that is independent of formula_23 and formula_18. The signed-rank zero procedure has the disadvantage that, when zeros occur, the null distribution of the test statistic  changes, so tables of "p"-values can no longer be used. When the data is on a Likert scale with equally spaced categories, the signed-rank zero procedure is more likely to maintain the Type I error rate than the reduced sample procedure. 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 formula_168, Wilcoxon's method outperforms Pratt's. Ties. When the data does not have ties, the ranks formula_17 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 formula_170 (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. For example, suppose that the observations satisfy formula_171 In this case, formula_172 is assigned rank 1, formula_39 and formula_174 are assigned  rank formula_175, formula_176 is assigned rank 4, and formula_38, formula_178, and formula_179 are assigned rank formula_180. Formally, suppose that there is a set of observations all having the same absolute value formula_181, that formula_182 observations have absolute value less than formula_181, and that formula_184 observations have absolute value less than or equal to formula_181. If the ties among the observations with absolute value formula_181 were broken, then these observations would occupy ranks formula_187 through formula_184. The average rank procedure therefore assigns them the rank formula_189. Under the average rank procedure, the null distribution is different in the presence of ties . 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. 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 formula_49 which the test does not reject form an interval. The other common option for handling ties is a tiebreaking procedure. In a tiebreaking procedure, the observations are assigned distinct ranks in the set formula_170. 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 rank-sum 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 "p"-values. "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. One could also report the probability of rejection over all random choices. Random tiebreaking has the advantage that the probability that a sample is judged significantly positive does not decrease when some observations are increased. "Conservative tiebreaking" breaks  the ties in favor of the null hypothesis. When performing a one-sided test in which negative values of formula_13 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 formula_13 significant, ties are broken the other way, and when large absolute values of formula_13 are significant, ties are broken so as to make formula_195 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." The average rank procedure can disagree with tiebreaking procedures. Pratt gives the following example. Suppose that the observations are: The average rank procedure assigns these the signed ranks This sample is significantly positive at the one-sided level formula_196. On the other hand, any tiebreaking rule will assign the ranks At the same one-sided level formula_196, 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 formula_13 is computed for every possible way of breaking ties, and the  final statistic is the mean of the tie-broken statistics. In the "average probability" method, the "p"-value is computed for every possible way of breaking ties, and the final "p"-value is the mean of the tie-broken "p"-values. Computing the null distribution. Computing "p"-values requires knowing the distribution of formula_13 under the null hypothesis. There is no closed formula for this distribution. However, for small values of formula_200, the distribution may be computed exactly. Under the null hypothesis that the data is symmetric about zero, each formula_145 is exactly as likely to be positive as it is negative. Therefore the  probability that formula_202 under the null hypothesis is equal to the number of sign combinations that yield formula_202 divided by the number of possible sign combinations formula_204. This can be used to compute the exact distribution of formula_13 under the null hypothesis. Computing the distribution of formula_13 by considering all possibilities requires computing formula_204 sums, which is intractable for all but the smallest formula_200. However, there is an efficient recursion for the distribution of formula_25. Define formula_210 to be the number of sign combinations for which formula_211. This is equal to the number of subsets of formula_170 which sum to  formula_213. The base cases of the recursion are formula_214, formula_215 for all formula_216, and formula_217 for all formula_218 or formula_219. The recursive formula is formula_220 The formula is true because every subset of formula_170 which sums to formula_213 either does not contain formula_200, in which case it is also a subset of formula_224, or it does contain formula_200, in which case removing formula_200 from the subset produces a subset of formula_224 which sums to formula_228. Under the null hypothesis, the probability mass function of formula_25 satisfies formula_230. The function formula_231 is closely related to the integer partition function. If formula_232  is the probability that formula_211 under the null hypothesis when there are formula_200 samples, then formula_232 satisfies a similar recursion: formula_236 with similar boundary conditions. There is also a recursive formula for the cumulative distribution function formula_237. For very large formula_200, even the above recursion is too slow. In this case, the null distribution can be approximated. The null distributions of formula_13, formula_25, and formula_26 are asymptotically normal with means and variances: formula_242 Better approximations can be produced using Edgeworth expansions. Using a fourth-order Edgeworth expansion shows that: formula_243 where formula_244 The technical underpinnings of these expansions are rather  involved, because conventional Edgeworth expansions apply to sums of IID continuous random variables, while formula_25 is a sum of non-identically distributed discrete random variables. The final result, however, is that the above expansion has an error of formula_246, just like a conventional fourth-order Edgeworth expansion. The moment generating function of formula_13 has the exact formula: formula_248 When zeros are present and the signed-rank zero procedure is used, or when ties are present and the average rank procedure is used, the null distribution of formula_13 changes. Cureton derived a normal approximation for this situation. Suppose that the original  number of observations was formula_200 and the number of zeros was formula_251. The tie correction is formula_252 where the sum is over all the size formula_253 of each group of tied observations. The expectation of formula_13 is still zero, while the expectation of formula_25 is formula_256 If formula_257 then formula_258 Alternative statistics. Wilcoxon originally defined the Wilcoxon rank-sum statistic to be formula_259. Early authors such as Siegel followed Wilcoxon. This is appropriate for two-sided hypothesis tests, but it cannot be used for one-sided tests. Instead of assigning ranks between 1 and "n", it is also possible  to assign ranks between 0 and formula_260. These are called "modified ranks". The modified signed-rank sum formula_261, the modified positive-rank sum formula_262, and the modified negative-rank sum formula_263 are defined analogously to formula_13, formula_25, and formula_26 but with the modified ranks in place of the ordinary ranks. The probability that the sum of two independent formula_37-distributed random variables is positive can be estimated as formula_268. When consideration is restricted to continuous distributions, this is a minimum variance unbiased estimator of formula_53. Example. formula_8 is the sign function, formula_271 is the absolute value, and formula_17 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. Effect size. To compute an effect size for the signed-rank test, one can use the rank-biserial 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". 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. 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 rank-sum 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.