University of Minnesota, Twin Cities     School of Statistics     Stat 5601     Rweb

Stat 5601 (Geyer) Examples (Wilcoxon Signed Rank Test and Related Procedures)

Contents

General Instructions

To do each example, just click the "Submit" button. You do not have to type in any R instructions or specify a dataset. That's already done for you.

The Wilcoxon Signed Rank Test

Example 3.1 in Hollander and Wolfe.

External Data Entry

Enter a dataset URL :

Summary

Comments

The Associated Point Estimate (Median of the Walsh Averages)

The Hodges-Lehmann estimator associated with the signed rank test is the median of the Walsh averages, which are the n (n + 1) / 2 averages of pairs of differences

(Zi + Zj) / 2,     i ≤ j
The following somewhat tricky code computes the Walsh averages and their median.

Example 3.3 in Hollander and Wolfe.

External Data Entry

Enter a dataset URL :

Summary

Comments

The Associated Confidence Interval

Very similar to the confidence interval associated with the sign test, the confidence interval has the form

(W(k), W(m + 1 - k))
where m = n (n + 1) / 2 is the number of Walsh averages, and, as always, parentheses on subscripts indicates order statistics, in this case, of the Walsh averages Wk. That is, one counts in k from each end in the list of sorted Walsh averages to find the confidence interval.

Example 3.4 in Hollander and Wolfe.

External Data Entry

Enter a dataset URL :

Summary

Comments

The R Function wilcox.test

All of the above can be done in one shot with the R function wilcox.test (on-line help). This function comes with R. It was not written especially for this course.

External Data Entry

Enter a dataset URL :

Comments

Ties and Zeros

What if the continuity assumption is false and there are tied absolute Z values or zero Z values?

First, neither ties nor zeros should make any difference in calculating point estimators or confidence intervals.

This is another bit of PBD in the implementation of the wilcox.test function. It does change the way it calculates point estimates and confidence intervals when there are ties or zeros. But it shouldn't.

The Zero Fudge

What we called the "zero fudge" in the context of the sign test (because it is fairly bogus there) makes much more sense in the context of the signed rank test. Zero values in the vector Z = Y - X of paired differences should get the smallest possible absolute rank because zero is smaller in absolute value than any other number. We might as well give them rank zero, starting counting at zero rather than at one. Then they make no contribution to the sum of ranks statistic.

Here's another way to see the same thing. Let's compare three procedures: Student t, signed rank, and sign.

This analysis explains why the Wilcoxon should treat differences of zero size just like the Student t, that is, they don't count at all.

There is another issue about the zero fudge. As explained in the section about the zero fudge for the sign test, there is an additional condition

pr(Zi < μ) = pr(Zi > μ).
which generally is not true under the usual assumptions for the sign test but which generally is true under the usual assumptions for the Wilcoxon signed rank test. We are already assuming the distribution of the differences is symmetric, and that implies the probability to either side of the population median μ is the same.

Thus we won't argue with the zero fudge for the signed rank test. We will start our hypothesis test calculations (don't do this for point estimates or confidence intervals) with

z <- y - z
z <- z - mu
z < z[z != 0]

Tied Ranks

The preceding section takes care of one kind of violation of the continuity assumption. But there's a second kind of violation that causes another problem.

If there are ties among the magnitudes of the Z values, then

So there are really two issues to be resolved.

  1. What test statistic?
  2. What is the sampling distribution of the test statistic under the null hypothesis.

The standard solution to the first problem is to use so-called "tied ranks" in which each of a set of tied magnitudes is assigned the average of the ranks they otherwise would have gotten if they had been slightly different (and untied). The R rank function automatically does this. So the ranks are done the same as before. And the test statistic is calculated from the ranks the same as before.

r <- rank(abs(z))
tplus <- sum(r[z > 0])

The Null Sampling Distribution of the Test Statistic

Now we have to deal with the fact that the distribution of the test statistic is no longer the one that holds under the continuity assumption (so no ties).

There are now three ways to proceed.

The Wrong Thing

The Wrong Thing (with a capital "W" and a capital "T") is to just ignore the fact that tied ranks change the sampling distribution and just use tables in books or computer functions that are based on the assumption of no ties.

This is not quite as bad as it sounds, because tied ranks were thought up in the first place with the idea of not changing the sampling distribution much. So this does give wrong answers, but not horribly wrong.

Example 3.2 in Hollander and Wolfe.

External Data Entry

Enter a dataset URL :
Summary
Comments

The Right Thing

As long as you have a computer, why not use it? There are only 2n points in the sample space of the sampling distribution of the test statistic under the null hypothesis corresponding to all possible choices of signs to the ranks. In this case, 212 = 4096, not a particularly big number for a computer (although out of the question for hand calculation). So just do it.

Example 3.2 in Hollander and Wolfe.

External Data Entry

Enter a dataset URL :
Summary
Comments

The Large Sample Approximation

We have been ignoring up to now, large sample (also called "asymptotic") approximations to sampling distributions of test statistics. Why use an approximation when the computer can do it exactly?

However, the computer can't do it exactly for really large n. The functions psignrank and qsignrank crash when n is larger than about 50. The code in the preceding section is worse. It will crash when n is larger than about 20.

Thus the need for large sample approximation.

It is a fact, which Hollander and Wolfe derive on pp. 44-45 that the mean and variance of the sampling distribution of T+ are

E(T+) = n (n + 1) / 4
var(T+) = n (n + 1) (2 n + 1) / 24
under the assumption of continuity (hence no ties).

When there are ties, the mean stays the same but the variance is reduced by a quantity that, because it has a summation sign in it, doesn't look good in web pages. Just see equation (3.13) in Hollander and Wolfe.

Here's how R uses this approximation.

Example 3.2 in Hollander and Wolfe.

External Data Entry

Enter a dataset URL :
Summary
Comments

The wilcox.test Thing

Example 3.2 in Hollander and Wolfe.

External Data Entry

Enter a dataset URL :
Summary