When the requirements for the t-test for two independent samples are not satisfied, the Wilcoxon Rank-Sum non-parametric test can often be used provided the two independent samples are drawn from populations with an ordinal distribution.
For this test we use the following null hypothesis:
H0: the observations come from the same population
From a practical point of view, this implies:
H0: if one observation is made at random from each population (call them x0 and y0), then the probability that x0 > y0 is the same as the probability that x0 < y0, and so the populations for each sample have the same medians.
We illustrate the technique with the following examples.
Example 1: Repeat Example 2 from Two Sample t Test with Unequal Variances to test whether a new hay fever drug is effective, but this time using the data from Figure 1.
Figure 1 – Data for Example 1
When we look at the QQ Plot for the Control group we see that it is not very normal, but more concerning is that the Box Plot for the group that took the drug shows that the data is not very symmetric (see Figure 2). We therefore decide to use the Wilcoxon Sign-Rank test instead of the t-test.
Figure 2 – QQ Plot and Box Plots for data in Example 1
The results of the Wilcoxon Rank-Sum test are displayed in Figure 3.
Figure 3 – Wilcoxon Rank-Sum Test for Example 1
We begin by calculating the ranks of the combined 24 raw scores using the supplemental RANK_AVG function (or the standard RANK.AVG function in Excel 2010). See Ranking for details. E.g., the contents of cell D6 is the rank of the first participant in the Control group, namely RANK_AVG(A6,$A$6:$B$17,1) which is the same as
=RANK(A6,$A$6:$B$17,1) + (COUNTIF($A$6:$B$17,A6)-1)/2.
using the standard Excel 2007 rank function (see Ranking).
We then calculate the sum of the ranks for each group to arrive at the rank sums R1 = 119.5 and R2 = 180.5. Since the sample sizes are equal, the value of the test statistic W = the smaller of R1 and R2, which for this example means that W = 119.5 (cell H10).
We next compare W with the critical value Wcrit, which can be found in the Wilcoxon Rank-Sum Table. Since the sample sizes are both 12, we look up the critical value in the table for α = .05 (two-tail) where n1 = n2 = 12, and find that Wcrit = 115. This represents the smallest value we could expect to obtain for W if the null hypothesis were true. Since W = 119.5 > 115 = Wcrit, we cannot reject the null hypothesis, and so conclude there is no significant difference between the effectiveness of the drug and the control.
Example 2: Repeat Example 1 with the last data element for the group that took the drug removed.
We again use the Wilcoxon Rank-Sum test, but this time the sample sizes are unequal. The test is as in Figure 4.
Figure 4 – Wilcoxon Rank-Sum Test for Example 2
The rank sums are calculated as in the previous example, although since some of the data may be blank, we need to use a formula such as
Since the sample sizes are different, a bit more care is required. Essentially W represents the left tail statistic and so we need to also evaluate the right tail statistic W′, which can be obtained by using reverse ranking as described in Figure 5:
Figure 5 – Calculation of W′ using reverse ranks
The value of W′ is therefore the sum of the ranks for the smaller sample, i.e. 105.5. Fortunately, because of symmetry, W’ can more easily be obtained via the formula
where (the smaller sample size) and (the larger sample size). Thus we obtain
W′ = 11(11+12+1) –158.5 = 105.5 (the value in cell H11)
For the two tailed test, which is what we usually require, we compare the smaller of W and W′ with Wcrit. To find the value of Wcrit, we again use the Wilcoxon Rank-Sum Table for α = .05 (two-tail) where n1 = 11 and n2 = 12 to obtain Wcrit = 99. Since min(W,W′) = min(158.5,105.5) = 105.5 > 99 = Wcrit , once again we cannot reject the null hypothesis.
Observation: When n1 = n2, then W′ = R2, i.e. the rank sum of the larger sample. Thus in Example 1, W′ = 180.5
Property 1: Suppose sample 1 has size n1 and rank sum R1 and sample 2 has size n2 and rank sum R2, then R1 + R2 = n(n+1)/2 where n = n1 + n2.
Property 2: When the two samples are sufficiently large (say of size > 10, although some say 20), then the W statistic is approximately normal N(μ, σ) where
Observation: Click here for a proof of Property 1 or 2.
Observation: Using Property 2, for samples sufficiently large, we can test W using the techniques from Sampling Distributions. Note that the result is the same whether we use W or W′.
Observation: Since it compares rank sums, the Wilcoxon Rank-Sum test is more robust than the t-test as it is less likely to indicate spurious results based on the presence of outliers. Even for large samples where the assumptions for the t-test are met, the Wilcoxon Rank-Sum test is only a little less efficient than the t-test.
Example 3: The objective of a study was to determine whether there is a significant difference in the median life expectancy between smokers and non-smokers. 38 smokers and 40 non-smokers were chosen at random and their age at death recorded in Figure 6.
Figure 6 – Life expectancy for both groups
A table of ranks is created and the values of W and W′ are calculated as in Examples 1 and 2. Since the sample sizes are sufficiently large, we can test W (or W′) using the normal distribution as described in Figure 7.
Figure 7 – Wilcoxon rank-sum test using normal approximation
Since there are fewer smokers than non-smokers, W = the rank sum for the smokers = 1227 (cell U8). We calculate the mean (cell U14) and variance (cell U15) for W using the formulas =U6*(T6+U6+1)/2 and =U14*T6/6 respectively. The standard deviation (cell U16) is then given by the formula =SQRT(U15) as usual.
We now calculate the p-value (cell U17) using the formula =NORMDIST(U8, U14, U16, TRUE) since W < W̄. If W > W̄, as usual we would use the formula =1 – NORMDIST(U8, U14, U16, TRUE). Alternatively, we could have created the z-score and calculated the p-value using NORMSDIST.
Since p-value = .003081 < .05 = α, we reject the null hypothesis (one tail test) and conclude that there is a significant difference between the life expectancy of smokers and non-smokers.
Note that if we had used W′ (column T of Figure 7), we would get the same p-value and come to the same conclusion.
Real Statistics Excel Functions: The following functions are provided in the Real Statistics Pack:
RANK_COMBINED(x, R1, R2, d) = the ranging of element x in the combination of ranges R1 and R2. If d = 0 (or is omitted), then the ranking is in decreasing order; otherwise it is in increasing order. The rank is corrected for ties as in RANK.AVG or RANK_AVG (see Ranking).
RANK_SUM(R1, R2, d) = sum of the ranks of all the elements in range R1 based on the combination of ranges R1 and R2. If d = 0 (or is omitted), then the ranking is in decreasing order; otherwise it is in increasing order. Rankings are corrected for ties as in RANK.AVG or RANK_AVG (see Ranking).
RANK_SUM(R1, k, d) = sum of the ranks of all the elements in the kth column of range R1. If d = 0 (or is omitted), then the ranking is in decreasing order; otherwise it is in increasing order. Rankings are corrected for ties as in RANK.AVG or RANK_AVG (see Ranking).
WILCOXON(R1, R2) = minimum of W and W′ for the samples contained in ranges R1 and R2
WILCOXON(R1, n) = minimum of W and W′ for the samples contained in the first n columns of range R1 and the remaining columns of range R1. If the second argument is omitted it defaults to 1.
WTEST(R1, R2, tails) = p-value of the Wilcoxon rank-sum test for the samples contained in ranges R1 and R2; tails = the # of tails: 1 (default) or 2.
WTEST(R1, n, tails) = p-value of the Wilcoxon rank-sum test for the samples contained in the first n columns of range R1 and the remaining columns of range R1. If the second argument is omitted it defaults to 1. tails = the # of tails: 1 (default) or 2.
WCRIT(n1, n2, α, tails, h) = critical value of the Wilcoxon Rank-Sum test for samples of size n1 and n2 for the given value of alpha (default α = .05) and tails = 1 (one tail) or 2 (two tails, default) based on the Wilcoxon Rank Sum Table. If h = TRUE (default) harmonic interpolation is used; otherwise linear interpolation is used.
WPROB(x, n1, n2, tails, iter) = an approximate p-value for Wilcoxon rank-sum test x (= the minimum of W and W′) for samples of size n1 and n2 and tails = 1 (one tail) or 2 (two tails, default) based on a linear interpolation of the values in the Wilcoxon Rank Sum Table using iter number of iterations (default = 40).
Note that the values for α in Wilcoxon Rank Sum Table range from .01 to .2 for tails = 2 and .005 to .1 for tails = 1. If the p-value is less than .01 (tails = 2) or .005 (tails = 1) then the p-value is given as 0 and if the p-value is greater than .2 (tails = 2) or .1 (tails = 1) then the p-value is given as 1.
Any empty or non-numeric cells in R1 or R2 are ignored.
Observation: If R1 represents the first n columns of range R and R2 represents the remaining columns in range R, then WILCOXON(R, n) = WILCOXON(R1, R2) and WTEST(R, n) = WTEST(R1, R2). Of course, WILCOXON(R1, R2) and WTEST(R1, R2) can also be used when the two ranges are not contiguous.
Similarly, if R1 represents the first n columns of range R and R2 represents the remaining columns in range R, then RANK_COMBINED(x, R1, R2, d) = RANK_AVG(x, R, d). The RANK_COMBINED function is especially useful, however, when R1 and R2 are not contiguous.
Observation: In Example 2, we can use the supplemental function to arrive at the same value for the minimum of W and W′, namely WILCOXON(A6:B17) = 105.5. Also RANK_COMBINED(34, A6:A17, B6:B7, 1) = 21.5, RANK_SUM(A6:A17, B6:B17) = 170.5 and RANK_SUM(B6:B17, A6:A17) = 105.5.
Also WCRIT(H5,I5,H8,H9) = WCRIT(12, 11, .05, 2) = 99 (the value in cell H12 of Figure 4). Finally note that the p-value = WPROB(H11,I5,H5,H9) = WPROB(105.5, 11, 12, 2) = .125 > .05 = α, and so once again we can’t reject the null hypothesis.
Similarly in Example 3, we can use the WILCOXON function to arrive at the same value for the minimum of W and W′, namely WILCOXON(A6:H15, 4) = WILCOXON(A6:D15, E6:H15) = 1227, as well as the same p-value (assuming a normal approximation), namely WTEST(A6:H15, 4) = WTEST(A6:D15, E6:H15) = 0.003081. Also RANK_COMBINED(72, A6:D15,E6:H15,1) = 37, RANK_SUM(A6:D15,E6:H15,1) = 1854 and RANK_SUM(E6:H15, A6:D15,1) = 1227.
Observation: The effect size for the Wilcoxon Rank Sum test is given by the correlation coefficient (see Basic Concepts of Correlation). The correlation coefficient for the Wilcoxon Rank Sum test is given by the formula
where the z-score is
For Example 3,
As described in Correlation in Relation to t-test, a rough estimate of effect size is that r = .5 represents a large effect size, r = .3 represents a medium effect size and r = .1 represents a small effect. Thus, for Example 3 we have a medium sized effect.
Also see Mann-Whitney Test (including Figure 2) for more information about how to calculate the effect size r in Excel.
Click here for a description of the exact version of the Wilcoxon Rank-Sum Exact Test using the permutation function.