Lecture notes · Introduction to Mathematical Statistics · Chapter 14

Chapter 14. Nonparametric Statistics: Lecture Notes

Every test so far rested on a model for the data: normal samples for \(t\) and \(F\), Bernoulli trials for proportions. When the model is doubtful, the nominal level of a test is no longer its true level. This chapter takes the other road: replace the data by their signs or their ranks. Under the null hypothesis the signs and ranks have a distribution that does not depend on the population at all, so the level is exact whatever the data look like. The book gives the sign test, the Wilcoxon signed-rank and rank-sum tests, the Kruskal–Wallis and Friedman tests and a test for randomness, proves the exact law of the signed-rank statistic with a generating function, and then states most of the rest without proof. These notes prove it: why ranks are distribution free, the exact laws and their recursions, the means and variances with and without ties, the normal approximations, the chi-square limits of the Kruskal–Wallis and Friedman statistics, the moments of the number of runs, and the price of using ranks, measured by the asymptotic relative efficiencies \(2/\pi\) (sign test) and \(3/\pi\) (Wilcoxon) against the \(t\) test for normal data.

Course home Ch. 1 Introduction Ch. 2 Probability Ch. 3 Random variables Ch. 4 Special distributions Ch. 5 Estimation Ch. 6 Hypothesis testing Ch. 7 Normal-based inference Ch. 8 Types of data Ch. 9 Two-sample inference Ch. 10 Goodness of fit Ch. 11 Regression Ch. 12 Analysis of variance Ch. 13 Randomized blocks Ch. 14 Nonparametric statistics

How to use the gap boxes and selected questions

Each Filling the gap box completes a step or a proof the book leaves out, and each selected question asks you to apply the chapter. Try it yourself first. When you are stuck, open Hint 1; the next hint unlocks one minute after you open the previous one, so take one hint at a time and think about it before moving on: the key idea first, then the tools, then the steps, with intermediate results to aim for. The full proof or solution appears after the last hint and unlocks two minutes later: use it to check your own argument. If you use a generative AI assistant, use it the same way: ask for a hint or for the next step only, then check what it says against these notes (why I teach this way). Spotted a mistake? Use the Report an error link at the end of each box: confirmed errors are corrected and listed, with thanks, in the errata.

How to read these notes

They follow the book. Sections carry the book's numbers (14.1 to 14.7) and numbered items keep theirs (Theorem 14.3.1, Case Study 14.4.1). Everything is written in new words; the book is cited for each result, example and figure, and displayed equations that the book numbers keep their number, e.g. \((14.3.1)\). The book writes \(z_\alpha\) for the upper \(\alpha\) point of the standard normal and \(\chi^2_{p,\,\nu}\) for the \(p\)-th quantile of the chi-square distribution with \(\nu\) degrees of freedom; these notes do the same.

Filling the gaps. Wherever the book says "for a proof see", "will not be derived", or works an example too fast to follow, an orange Filling the gap box gives the full argument. The central ones are 14.1 (why ranks are distribution free), 14.4 to 14.6 (the signed-rank statistic), 14.8 and 14.9 (the rank-sum statistic), 14.11 and 14.13 (the chi-square limits) and 14.17, 14.18 (efficiency). Proofs start hidden: open one with its bar, or use the button below. Each gap box and each selected question offers graded hints, one at a time, before the full solution.

Figures and demonstrations. Eight figures of the chapter are reproduced: 14.2.1, 14.4.1 and the six Monte Carlo figures 14.7.1 to 14.7.6 (with 10,000 replications instead of 100). Three own figures (x14.1 to x14.3) show the exact null laws of the signed-rank and rank-sum statistics, the power of the \(t\), sign and signed-rank tests, and the exact null law of the number of runs up and down. The chapter-opening power curves (computed in an outside study for populations described only by two cumulants), the drawing of two base paths (Figure 14.5.1) and the schematic of a sign sequence (Figure 14.6.1) are not redrawn. All are computed by the Python code. The ▶ Demo boxes open an interactive demonstration already set to the case being discussed.

Main reference

R. J. Larsen and M. L. Marx, An Introduction to Mathematical Statistics and Its Applications, 6th edition, Pearson (2018), Chapter 14, pages 638–673. Section, case-study, figure, equation and question numbers below refer to this book. Further reading is listed in the references.

The explanations, derivations, figures and code are my own; equations are cited by their numbers in the book.

Companion courses

Distribution-free inference appears, at other levels and in other words, in companion courses of this site. Where a proof there is complete, these notes give the statement and a short argument and link to it.

  • First-year statistics, First-Year Statistics: Estimation and Hypothesis Testing; its advanced version proves the central limit theorem (Theorem 0.7) and that a P-value of a discrete statistic still controls the Type I error (Theorem 4.1), which is what makes the exact sign and signed-rank tests valid.
  • Probability and Statistical Inference (graduate course): the permutation test and why it is exact (Section 10.5, Filling the gap 10.11), of which every rank test of this chapter is a special case; asymptotic relative efficiency and the asymptotic law of the sample median, with \(\are(\text{median},\text{mean})=2/\pi\) (Section 9.8, Filling the gap 9.11); Spearman's and Kendall's rank correlations (Filling the gap 15.9); Slutsky's theorem and the multivariate central limit theorem (Theorem 5.5, Theorem 5.12).
  • Nonparametric Statistical Inference (graduate course), Chapter 2: a distribution-free confidence band for the whole cdf (Theorem 2.6) and the asymptotic normality of sample quantiles (Filling the gap 2.8), the large-sample theory behind the sign test.
  • Statistical Methods for Modern Biology: a simulation of the power of the Wilcoxon rank-sum test against the Welch test, with the efficiency 1.5 for Laplace noise (Exercise 13.1).

New here: the distribution-free property in full (Filling the gap 14.1); what the paired sign test really tests (14.3); the asymptotic normality of the signed-rank statistic by moment-generating functions (14.6) and of the rank-sum statistic by a projection (14.9); exact laws with ties (14.7); the chi-square limits of the Kruskal–Wallis and Friedman statistics (14.11, 14.13); the moments of the number of runs up and down, with a correction for \(n=3\) (14.14); and the Pitman efficiencies with the Hodges–Lehmann bound 0.864 (14.17, 14.18).

The chapter at a glance

  • 14.2 The sign test counts the observations above \(\tilde\mu_0\): under \(H_0\) the count is \(\Bin(n,\frac12)\) for every continuous population (Theorem 14.2.1, Filling the gap 14.1).
  • 14.3 The signed-rank statistic \(W\) adds the ranks of the positive deviations. Its exact law is read off \(\prod_{i=1}^n(1+e^{it})/2^n\) (Theorem 14.3.1), with mean \(n(n+1)/4\), variance \(n(n+1)(2n+1)/24\) and a normal limit (Theorem 14.3.2, Filling the gap 14.6). The rank-sum statistic \(W'\) of two samples has mean \(n(n+m+1)/2\) and variance \(nm(n+m+1)/12\) (Theorem 14.3.4, 14.8, 14.9).
  • 14.4 The Kruskal–Wallis statistic \(B\) is the analysis of variance of the ranks; under \(H_0\) its mean is exactly \(k-1\) and its limit is \(\chi^2_{k-1}\) (Theorem 14.4.1, 14.10, 14.11).
  • 14.5 The Friedman statistic \(G\) does the same with ranks within blocks (Theorem 14.5.1, 14.12, 14.13); with two treatments it is the sign test.
  • 14.6 The number \(W\) of runs up and down in \(n\) observations has mean \((2n-1)/3\) and variance \((16n-29)/90\) (Theorem 14.6.1, 14.14, 14.15).
  • 14.7 Rank tests keep their level for any continuous data; for normal data they lose little power: the Wilcoxon test needs about \(\pi/3\approx1.05\) times as many observations as the \(t\) test, the sign test \(\pi/2\approx1.57\) times (14.16–14.18).

Notation. \(\tilde\mu\) is a median: \(P(Y\le\tilde\mu)=P(Y\ge\tilde\mu)=\frac12\). For a continuous cdf \(F\), \(f\) is its density. \(D_i=Y_i-\mu_0\) are deviations; \(r_i\) is the rank of \(|D_i|\) (or of an observation in a pooled sample) and \(z_i\in\{0,1\}\) an indicator, as in the book. \(\convd\) denotes convergence in distribution and \(\convp\) convergence in probability. \(\Phi\) is the standard normal cdf.

Prerequisites. The binomial law and moment-generating functions (Section 3.12, Theorems 3.12.2 and 3.12.3), the central limit theorem and its proof by moment-generating functions (Theorem 4.3.2, Filling the gap 4.9), exact binomial tests (Filling the gap 6.5), the \(t\) test and its robustness (Section 7.4), the chi-square law as a squared length (Filling the gap 10.6), and the analysis of variance of Chapters 12 and 13.

Derivations start hidden: click any bar to open one.

14.1 Introduction

pp. 638–639 A test with statistic \(W\) and critical region \(C\) is designed so that \(P(W\in C\given H_0)=\alpha\), computed from the null density of \(W\) under the model. If the model is wrong, the true null density of \(W\) is a different function, and

\[ \text{true }\alpha=\int_Cf_W(w\given H_0)\,\d w \]

need not equal the nominal \(\alpha\). There are two remedies. One is robustness: show that the usual statistic is not much affected by a violation (the one-sample \(t\) ratio is fairly insensitive to non-normality, Section 7.4, Figure 7.4.6). The other is to use statistics whose null distribution is the same for every population in a large class: distribution-free (or nonparametric) procedures. The chapter builds nonparametric versions of tests already met: the one-sample location problem, paired data, two samples, and the two analysis of variance designs of Chapters 12 and 13.

Two devices make a statistic distribution free: replacing each observation by its sign relative to a hypothesised centre, and replacing it by its rank in a sample. The next box proves why both work.

Filling the gap 14.1: why signs and ranks are distribution free pp. 639, 645, 655, 658

Let \(Y_1,\dots,Y_n\) be independent, each with a continuous cdf.

(a) Ties have probability zero: \(P(Y_i=Y_j)=0\) for \(i\ne j\), and \(P(Y_i=c)=0\) for every constant \(c\).

(b) If every \(Y_i\) has median \(\tilde\mu_0\), the number \(K\) of \(Y_i\) above \(\tilde\mu_0\) is \(\Bin(n,\frac12)\), whatever the (possibly different) distributions.

(c) If \(Y_1,\dots,Y_n\) are iid, the vector of ranks \((R_1,\dots,R_n)\) is uniformly distributed over the \(n!\) permutations of \(\{1,\dots,n\}\). In particular each \(R_i\) is uniform on \(\{1,\dots,n\}\), and

\[ \E(R_i)=\frac{n+1}2,\qquad \V(R_i)=\frac{n^2-1}{12},\qquad \Cov(R_i,R_j)=-\frac{n+1}{12}\quad(i\ne j). \]
Hint 1 of 5: the key idea

A continuous cdf puts no mass on single points, so ties cannot happen. For iid data, what does permuting the observations do to their joint density, and what does that say about the probability of each ordering?

Hint 2 of 5: tools you will need
  • Quantiles of a continuous cdf: intervals of probability exactly \(1/M\).
  • Independence; Theorem 3.2.1 (sums of Bernoulli variables).
  • Exchangeability of iid observations.
Hint 3 of 5: step 1

For (a), cut the line into \(M\) intervals each of probability \(1/M\) under \(F_i\) and bound \(P(Y_i=Y_j)\) by the chance both fall in one interval. Aim for: \(P(Y_i=Y_j)\le1/M\).

Hint 4 of 5: step 2

For (b), the indicators \(\one\{Y_i>\tilde\mu_0\}\) are independent; compute their success probability using (a). Aim for: each is \(\Bern(\frac12)\).

Hint 5 of 5: step 3

For (c), show that the \(n!\) orderings have equal probability, then get the moments of one rank. Aim for: \(\V R_i=(n^2-1)/12\); for the covariance use that \(\sum_iR_i\) is constant.

Proof

(a) A continuous cdf has no jumps, so \(P(Y_i=c)=F_i(c)-F_i(c^-)=0\). For two observations fix \(\varepsilon=1/M\) and cut the line into the \(M\) intervals \(I_k=(q_{k-1},q_k]\), where \(q_k\) is a \(k/M\) quantile of \(F_i\) (\(q_0=-\infty\), \(q_M=+\infty\)); then \(P(Y_i\in I_k)=1/M\). If \(Y_i=Y_j\), both lie in the same interval, so by independence

\[ P(Y_i=Y_j)\le\sum_{k=1}^MP(Y_i\in I_k)\,P(Y_j\in I_k)=\frac1M\sum_{k=1}^MP(Y_j\in I_k)=\frac1M. \]

As \(M\) is arbitrary, \(P(Y_i=Y_j)=0\).

(b) The indicators \(\one\{Y_i>\tilde\mu_0\}\) are independent (functions of independent variables) and \(P(Y_i>\tilde\mu_0)=1-F_i(\tilde\mu_0)=\frac12\), using (a) to ignore \(Y_i=\tilde\mu_0\). A sum of \(n\) independent \(\Bern(\frac12)\) variables is \(\Bin(n,\frac12)\) (Theorem 3.2.1).

(c) For iid observations the joint density \(f(y_1)\cdots f(y_n)\) is unchanged when the arguments are permuted, so for every permutation \(\pi\) the vector \((Y_{\pi(1)},\dots,Y_{\pi(n)})\) has the same law as \((Y_1,\dots,Y_n)\) (the observations are exchangeable). The event "the ranks are \(\rho\)" is the event that the observations, listed in the order given by \(\rho\), are increasing; applying a permutation maps it onto the event for any other rank vector. Hence all \(n!\) events have the same probability; they are disjoint and, by (a), their union has probability 1, so each has probability \(1/n!\). Then \(R_i\) is uniform on \(\{1,\dots,n\}\): \(\E R_i=\frac1n\sum_kk=\frac{n+1}2\) and \(\E R_i^2=\frac{(n+1)(2n+1)}6\), so \(\V R_i=\frac{(n+1)(2n+1)}6-\frac{(n+1)^2}4=\frac{n^2-1}{12}\). Finally \(\sum_iR_i=n(n+1)/2\) is a constant, so

\[ 0=\V\Big(\sum_iR_i\Big)=n\,\frac{n^2-1}{12}+n(n-1)\Cov(R_1,R_2),\qquad\text{so}\qquad \Cov(R_1,R_2)=-\frac{n+1}{12}. \]

∎ Every rank test of this chapter is therefore a permutation test: its null law is computed from the uniform distribution of the ranks, never from the population. The graduate course proves the general statement for any statistic (Filling the gap 10.11).

14.2 The Sign Test

pp. 639–640 The simplest nonparametric test concerns a median. If \(H_0\colon\tilde\mu=\tilde\mu_0\) holds for a continuous population, each observation exceeds \(\tilde\mu_0\) with probability \(\frac12\), so the number \(X\) of observations above \(\tilde\mu_0\) is \(\Bin(n,\frac12)\) (Filling the gap 14.1(b)) with mean \(n/2\) and variance \(n/4\). Too many or too few observations above \(\tilde\mu_0\) are evidence against \(H_0\).

Theorem 14.2.1 (the large-sample sign test) p. 640

Let \(y_1,\dots,y_n\) be a random sample from a continuous distribution with median \(\tilde\mu\), with \(n\ge10\). Let \(k\) be the number of \(y_i\) greater than \(\tilde\mu_0\) and \(z=(k-n/2)/\sqrt{n/4}\). At level \(\alpha\):

(a) for \(H_1\colon\tilde\mu>\tilde\mu_0\), reject \(H_0\) if \(z\ge z_\alpha\); (b) for \(H_1\colon\tilde\mu<\tilde\mu_0\), reject if \(z\le-z_\alpha\); (c) for \(H_1\colon\tilde\mu\ne\tilde\mu_0\), reject if \(|z|\ge z_{\alpha/2}\).

For a symmetric population the median is the mean, so the test also concerns \(\mu\). The book's only assumption is continuity: nothing about shape, symmetry or variance.

Case Study 14.2.1 pp. 640–641 (synovial fluid pH). The median pH of synovial fluid in healthy adults is 7.39. Of \(n=43\) arthritis patients only \(k=4\) exceed 7.39, so \(z=(4-21.5)/\sqrt{10.75}=-5.34\), far below \(-z_{0.005}=-2.58\): reject \(H_0\colon\tilde\mu=7.39\) against the two-sided alternative. Synovial pH is lower in arthritis.

A small-sample sign test. pp. 641–642 For \(n<10\) the book uses the binomial law itself, and reports a P-value rather than a fixed level, because a discrete statistic attains only a few levels.

Case Study 14.2.2 (caffeine residue). For freeze-dried coffee the median residue is 3.55 g per 100 g; \(k=7\) of \(n=8\) spray-dried brands exceed it. The two-sided P-value is \(P(X\ge7)+P(X\le1)\)\({}=2(8+1)/256\)\({}=0.0703\) (Figure 14.2.1): reject \(H_0\) for any \(\alpha\ge0.07\).

Bar chart of the binomial probabilities for n equal 8 and p one half, from 0.003906 at 0 and 8 up to 0.273438 at 4. The bars at 0, 1, 7 and 8 are red (the critical region for k equal 7), the others blue; the title gives the P-value 0.0703.
Figure 14.2.1. The null law of the number of brands above 3.55 in Case Study 14.2.2. The two-sided P-value of \(k=7\) is the red area: the outcomes at least as far from 4 as 7 is. Reproduces Larsen and Marx (2018), Figure 14.2.1. Code: ch14_nonparametric_statistics.py, fig_14_2_1.

Filling the gap 14.2: the exact sign test, and how good the normal approximation is at \(n\approx10\) pp. 640–644, "provided n is sufficiently large"

(a) The exact sign test rejects when the P-value \(P(X\ge k)\) (or \(P(X\le k)\), or \(2\min\{P(X\le k),P(X\ge k)\}\) for two-sided alternatives), computed from \(\Bin(n,\frac12)\), is at most \(\alpha\); its size is at most \(\alpha\) for every continuous population. (b) The rule of Theorem 14.2.1 does not have size exactly \(\alpha\): for \(n=10\) the one-sided 0.05 rule rejects when \(k\ge8\), with true size \(56/1024=0.0547\), and the two-sided 0.05 rule rejects when \(k\le1\) or \(k\ge9\), with true size 0.0215. (c) The continuity correction \(z=(k-\frac12-n/2)/\sqrt{n/4}\) (upper tail) brings the approximate P-value much closer to the exact one.

Hint 1 of 5: the key idea

A rule written on the \(z\) scale is really a rule on the integer count \(k\). Which integers does it reject, and what is the exact binomial probability of those integers?

Hint 2 of 5: tools you will need
Hint 3 of 5: step 1

For \(n=10\), solve \((k-5)/\sqrt{2.5}\ge1.645\) for the integer \(k\). Aim for: \(k\ge8\) and size \(56/1024\).

Hint 4 of 5: step 2

Do the same for the two-sided rule \(|k-5|\ge1.96\sqrt{2.5}\). Aim for: \(k\le1\) or \(k\ge9\), size about 0.02.

Hint 5 of 5: step 3

For the case studies, compare exact binomial tails with normal tails computed at \(k\) and at \(k\mp\frac12\). Which is closer?

Proof

(a) Under \(H_0\) the count \(X\) is \(\Bin(n,\frac12)\) for every continuous population (Filling the gap 14.1(b)). For a statistic with a known discrete null law, the rule "reject if the P-value is at most \(\alpha\)" has size at most \(\alpha\) (first-year Theorem 4.1(b); the binomial case is Filling the gap 6.5). Since \(\Bin(n,\frac12)\) is symmetric about \(n/2\), the two-sided P-value equals \(P(|X-n/2|\ge|k-n/2|)\), the probability of an outcome at least as far from the centre as the one observed, which is how Case Study 14.2.2 computes it.

(b) For \(n=10\), \(\sqrt{n/4}=1.581\). One-sided: \(z\ge1.645\) means \(k\ge5+2.60=7.60\), i.e. \(k\ge8\), and \(P(X\ge8)=\big(\binom{10}8+\binom{10}9+\binom{10}{10}\big)/2^{10}=(45+10+1)/1024=0.0547\). Two-sided: \(|k-5|\ge1.96\times1.581=3.10\), i.e. \(k\le1\) or \(k\ge9\), with probability \(2(10+1)/1024=0.0215\). The binomial jumps in steps of \(1/\sqrt{n/4}\) in \(z\) units, 0.63 at \(n=10\), so a rule written on the \(z\) scale can be off by a whole step.

(c) The event \(X\ge k\) for an integer variable is the event \(X\ge k-\frac12\), and the normal curve approximates the bar at \(k\) by the area over \([k-\frac12,k+\frac12]\) (Filling the gap 4.7). Three examples from the case studies:

Case study\(n,\ k\)exact P-valuenormal, no correctionnormal, corrected
14.2.1 (two-sided)43, 4\(3.1\times10^{-8}\)\(9.4\times10^{-8}\)\(2.2\times10^{-7}\)
14.2.2 (two-sided)8, 70.07030.03390.0771
14.2.3 (one-sided)11, 90.03270.01740.0352

Without the correction the normal P-value of Case Study 14.2.3 is about half the exact one, although \(n=11\ge10\). The conclusions of the book do not change, but the exact binomial is always available and should be preferred for small \(n\). ∎

The sign test for paired data. pp. 642–643 For pairs \((x_i,y_i)\), \(i=1,\dots,b\), let \(p=P(X_i>Y_i)\) and \(U\) the number of pairs with \(x_i>y_i\). Under \(H_0\colon p=\frac12\), \(U\sim\Bin(b,\frac12)\); use \(U\) itself, or \((U-b/2)/\sqrt{b/4}\) when \(b\ge10\). The pairs may come from different distributions with different spreads; only continuity is assumed.

Case Study 14.2.3 pp. 643–644 (cyclandelate). Mean circulation time was measured before and after four months of treatment in \(b=11\) elderly subjects; \(u=9\) improved (\(x_i>y_i\)). With the one-sided alternative \(H_1\colon p>\frac12\), \(z=(9-5.5)/\sqrt{2.75}=2.11\ge1.64\): reject. The exact P-value is \(P(U\ge9)=67/2048=0.033\), still below 0.05.

Filling the gap 14.3: what the paired sign test tests p. 642, "equivalent to the null hypothesis H0: p = 1/2"

(a) If the \(b\) pairs are independent and \(P(X_i>Y_i)=\frac12\) with \(P(X_i=Y_i)=0\) for every \(i\), then \(U\sim\Bin(b,\frac12)\). (b) "\(X_i\) and \(Y_i\) have the same median" does not imply \(P(X_i>Y_i)=\frac12\): if \(X\sim\Unif(0,2)\) and, independently, \(Y\) is exponential with median 1, then \(P(X>Y)=1-\frac3{8\ln2}=0.459\). (c) \(P(X_i>Y_i)=\frac12\) does hold if \((X_i,Y_i)\) is exchangeable (has the same law as \((Y_i,X_i)\)), for example when the treatment has no effect and its order within each pair was randomised, or when \(X_i-Y_i\) is symmetric about 0.

Hint 1 of 5: the key idea

The sign test counts \(\one\{X_i>Y_i\}\); its null law needs \(P(X_i>Y_i)=\frac12\). Is that implied by equal medians of \(X\) and \(Y\)? Try two different shapes with the same median.

Hint 2 of 5: tools you will need
  • Conditioning on one variable: \(P(X>Y)=\int P(Y<x)f_X(x)\,\d x\).
  • The exponential cdf with median 1: rate \(\ln2\).
  • Exchangeable pairs: \((X,Y)\) has the law of \((Y,X)\).
Hint 3 of 5: part (a)

The indicators over independent pairs are independent Bernoulli variables. Aim for: \(U\sim\Bin(b,\frac12)\).

Hint 4 of 5: part (b)

Compute \(\frac12\int_0^2(1-2^{-x})\,\d x\). Aim for: \(1-3/(8\ln2)\approx0.459\).

Hint 5 of 5: part (c)

Use exchangeability to get \(P(X>Y)=P(Y>X)\), and remember ties have probability 0.

Proof

(a) The indicators \(\one\{X_i>Y_i\}\) are independent \(\Bern(\frac12)\) variables, so their sum is \(\Bin(b,\frac12)\).

(b) Both medians are 1: \(P(X\le1)=\frac12\), and an exponential with rate \(\lambda=\ln2\) has \(P(Y\le1)=1-e^{-\ln2}=\frac12\). By independence, conditioning on \(X=x\),

\[ P(X>Y)=\int_0^2\frac12\,P(Y<x)\,\d x=\frac12\int_0^2\big(1-2^{-x}\big)\d x=\frac12\Big(2-\frac{1-\frac14}{\ln2}\Big)=1-\frac3{8\ln2}=0.459. \]

So with many such pairs the sign test rejects "\(p=\frac12\)" with probability tending to 1, although the medians are equal. The test concerns the median of the differences \(X_i-Y_i\) (that median is 0 exactly when \(p=\frac12\)), not the difference of the medians.

(c) Exchangeability gives \(P(X_i>Y_i)=P(Y_i>X_i)\), and the two add to 1 since ties have probability 0. If \(D_i=X_i-Y_i\) is symmetric about 0, \(P(D_i>0)=P(D_i<0)=\frac12\) directly. ∎

See also (companion courses): the first-year course on exact binomial tests (Theorem 4.1); Statistical Methods for Modern Biology, the binomial test demo (rejection regions and discrete P-values).

14.3 Wilcoxon Tests

pp. 645–646 The sign test uses only the direction of each deviation. The Wilcoxon signed-rank test also uses its size, through ranks. Let \(y_1,\dots,y_n\) be independent observations from continuous densities that are symmetric about a common centre \(\mu\) (not necessarily identical), and test \(H_0\colon\mu=\mu_0\). Rank the absolute deviations \(|y_i-\mu_0|\) from 1 (smallest) to \(n\) (largest), calling the rank \(r_i\); tied values share the average of their ranks. Let \(z_i=1\) if \(y_i-\mu_0>0\) and \(z_i=0\) otherwise. The signed-rank statistic is

\[ w=\sum_{i=1}^nr_iz_i, \]

the sum of the ranks of the positive deviations. Under \(H_0\) positive and negative deviations should share the ranks evenly. For example, with \(\mu_0=10\) and \(y=(6.0,\,4.9,\,11.2)\) the absolute deviations 4.0, 5.1, 1.2 have ranks 2, 3, 1 and only the third is positive, so \(w=1\). The statistic depends on the data only through ranks and signs: \(y_2=4.9\), \(3.6\) or \(-10{,}000\) give the same \(w\).

Theorem 14.3.1 (the exact null law of the signed-rank statistic) p. 646

Let \(y_1,\dots,y_n\) be independent observations from continuous densities, each symmetric about \(\mu\). If \(H_0\colon\mu=\mu_0\) is true, then

\[ p_W(w)=P(W=w)=\frac{c(w)}{2^n},\qquad w=0,1,\dots,\frac{n(n+1)}2, \]

where \(c(w)\) is the coefficient of \(e^{wt}\) in the expansion of \(\prod_{i=1}^n(1+e^{it})\). Equivalently, the moment-generating function of \(W\) is

\[ M_W(t)=\Big(\frac12\Big)^n\prod_{i=1}^n\big(1+e^{it}\big). \tag{14.3.1} \]

The book's proof says that under \(H_0\), \(W\) has the same law as \(U=\sum_iU_i\), where \(U_1,\dots,U_n\) are independent and \(U_i\) equals 0 or \(i\) with probability \(\frac12\) each. It does not say why; this is the heart of the matter, and the next box proves it.

Filling the gap 14.4: why the signs are fair coins independent of the ranks p. 646, proof of Theorem 14.3.1

Let \(D_i=Y_i-\mu_0\) be independent, each with a continuous density symmetric about 0. Then (a) \(\one\{D_i>0\}\) and \(|D_i|\) are independent, with \(P(D_i>0)=\frac12\); (b) the sign indicators \(Z_1,\dots,Z_n\) are iid \(\Bern(\frac12)\) and independent of \((|D_1|,\dots,|D_n|)\); (c) if \(Z_{(j)}\) is the sign indicator of the observation whose absolute deviation has rank \(j\), then \(Z_{(1)},\dots,Z_{(n)}\) are iid \(\Bern(\frac12)\) and

\[ W=\sum_{j=1}^nj\,Z_{(j)}, \]

which has the law of \(U=\sum_jU_j\). Hence \((14.3.1)\) and the formula for \(p_W(w)\).

Hint 1 of 6: the key idea

For a deviation symmetric about 0, does knowing its size tell you anything about its sign? If not, the signs are fair coins that can be attached to the ranks 1, ..., n in any order.

Hint 2 of 6: tools you will need
  • Symmetry: \(D\) and \(-D\) have the same law.
  • Independence of functions of independent variables.
  • Moment-generating functions of independent sums, Theorem 3.12.3.
Hint 3 of 6: step 1

Show \(P(D>0,|D|\le a)=\frac12P(|D|\le a)\) for every \(a\). Aim for: the event \(\{D>0\}\) is independent of \(|D|\), with probability \(\frac12\).

Hint 4 of 6: step 2

Conclude that \(Z_1,\dots,Z_n,|D_1|,\dots,|D_n|\) are all independent.

Hint 5 of 6: step 3

Condition on the absolute deviations (so the ranks are fixed) and regroup \(\sum r_iz_i\) by rank. Aim for: \(W=\sum_jjZ_{(j)}\) with iid fair \(Z_{(j)}\).

Hint 6 of 6: step 4

Compute \(\E e^{tW}\) as a product and compare coefficients of the polynomial in \(x=e^t\).

Proof

(a) Symmetry about 0 means \(D_i\) and \(-D_i\) have the same law. For \(a>0\), \(P(0<D_i\le a)=P(-a\le D_i<0)\), and these two add to \(P(|D_i|\le a)\) because \(P(D_i=0)=0\). So

\[ P\big(D_i>0,\ |D_i|\le a\big)=\tfrac12P(|D_i|\le a)\quad\text{for every }a. \]

Letting \(a\to\infty\) gives \(P(D_i>0)=\frac12\), and then the display says \(P(D_i>0,|D_i|\le a)=P(D_i>0)P(|D_i|\le a)\): the event \(\{D_i>0\}\) is independent of every event \(\{|D_i|\le a\}\), hence of \(|D_i|\) (the joint law of a binary variable and a real variable is determined by these probabilities).

(b) The pairs \((Z_i,|D_i|)\), \(i=1,\dots,n\), are independent (functions of independent \(D_i\)), and within each pair the two parts are independent by (a). So all \(2n\) variables \(Z_1,\dots,Z_n,|D_1|,\dots,|D_n|\) are mutually independent, which gives (b).

(c) The ranks are a function of \((|D_1|,\dots,|D_n|)\) alone; with probability 1 there are no ties (Filling the gap 14.1(a)), so they define a permutation \(j\mapsto i(j)\). Condition on \((|D_1|,\dots,|D_n|)\): the permutation is then fixed, and by (b) the \(Z_i\) are still iid \(\Bern(\frac12)\), so \(Z_{(j)}=Z_{i(j)}\), \(j=1,\dots,n\), are iid \(\Bern(\frac12)\). This conditional law is the same whatever we conditioned on, so it is also the unconditional law. Regrouping the sum by ranks, \(w=\sum_ir_iz_i=\sum_jj\,z_{(j)}\). Each term \(jZ_{(j)}\) equals 0 or \(j\) with probability \(\frac12\), so \(W\) has the law of \(U\), and by independence (Theorem 3.12.3)

\[ M_W(t)=\prod_{j=1}^n\E\,e^{tjZ_{(j)}}=\prod_{j=1}^n\frac{1+e^{jt}}2. \]

Finally \(M_W(t)=\sum_wp_W(w)e^{wt}\) is a polynomial in \(x=e^t\) with coefficients \(p_W(w)\), and so is \(2^{-n}\prod_j(1+x^j)\); two polynomials that agree for all \(x>0\) have the same coefficients, so \(p_W(w)=c(w)/2^n\). (The book's sum starts at \(w=1\); it must start at \(w=0\), the value when every deviation is negative.) ∎

The symmetry assumption is used exactly once, in (a). Without it the signs need not be fair or independent of the sizes, and \(W\) loses its distribution-free law. The sign test needs only \(P(D_i>0)=\frac12\); the signed-rank test needs the whole of (a).

Calculating \(p_W(w)\). pp. 647–648 For \(n=4\),

\[ M_W(t)=\frac1{16}\big(1+e^t+e^{2t}+2e^{3t}+2e^{4t}+2e^{5t}+2e^{6t}+2e^{7t}+e^{8t}+e^{9t}+e^{10t}\big), \]

so \(P(W=2)=\frac1{16}\), \(P(W=7)=\frac2{16}\), and so on (Table 14.3.1 of the book lists the sign patterns behind each value; Figure x14.1(a)). The book's Table A.6 lists the tails \(P(W\le w_1^*)\) and \(P(W\ge w_2^*)\) for \(n=4\) to 12; for \(n=7\) and a two-sided 0.05 test it gives \(C=\{w\le2\text{ or }w\ge26\}\), of exact size \(0.023+0.023\approx0.05\).

Filling the gap 14.5: computing the exact law by a recursion, its symmetry, and the critical values pp. 647–649, Table A.6

Write \(c_n(w)\) for the coefficient of \(x^w\) in \(\prod_{i=1}^n(1+x^i)\): the number of subsets of \(\{1,\dots,n\}\) with sum \(w\). Then

\[ c_n(w)=c_{n-1}(w)+c_{n-1}(w-n),\qquad c_n(w)=c_n\Big(\frac{n(n+1)}2-w\Big), \]

with \(c_0(0)=1\) and \(c_{n-1}(v)=0\) outside \(0\le v\le n(n-1)/2\). So \(W\) is symmetric about \(n(n+1)/4\), \(P(W\le w)=P(W\ge n(n+1)/2-w)\), and two-sided critical regions are symmetric. For \(n=7\): \(P(W\le2)=3/128=0.0234\) and \(P(W\le3)=5/128=0.039\); for \(n=10\): \(P(W\le8)=25/1024=0.0244\) and \(P(W\le9)=0.032\). These are the book's critical values \(\{\le2,\ge26\}\) (size 0.047) and \(\{\le8,\ge47\}\) (size 0.049).

Hint 1 of 5: the key idea

\(c_n(w)\) counts subsets of \(\{1,\dots,n\}\) with sum \(w\). Split them according to whether they contain \(n\); and pair each subset with its complement.

Hint 2 of 5: tools you will need
  • Multiplying a polynomial by \(1+x^n\).
  • Complementation of subsets.
  • Cumulative sums for tail probabilities.
Hint 3 of 5: step 1

Read the recursion off \(\prod_{i\le n}(1+x^i)=\prod_{i<n}(1+x^i)\cdot(1+x^n)\). Aim for: \(c_n(w)=c_{n-1}(w)+c_{n-1}(w-n)\).

Hint 4 of 5: step 2

Show complementation maps sum \(w\) to sum \(n(n+1)/2-w\). Aim for: symmetry of the law about \(n(n+1)/4\).

Hint 5 of 5: step 3

Build the counts for \(n=7\) and \(n=10\) and accumulate. Aim for: \(P(W\le2)=3/128\) and \(P(W\le8)=25/1024\).

Proof

Recursion. \(\prod_{i=1}^n(1+x^i)=\big(\prod_{i=1}^{n-1}(1+x^i)\big)(1+x^n)\); the coefficient of \(x^w\) on the right is \(c_{n-1}(w)\) (take the 1) plus \(c_{n-1}(w-n)\) (take \(x^n\)). In words: a subset of \(\{1,\dots,n\}\) with sum \(w\) either omits \(n\) or contains it.

Symmetry. Complementation \(S\mapsto\{1,\dots,n\}\setminus S\) is a bijection between subsets with sum \(w\) and subsets with sum \(n(n+1)/2-w\). In terms of the test: changing every sign (\(z_i\to1-z_i\)) maps \(W\) to \(n(n+1)/2-W\).

Numbers. Building the table with the recursion gives, for \(n=7\), \(c_7(0),\dots,c_7(3)=1,1,1,2\) out of \(2^7=128\), and for \(n=10\), \(c_{10}(0),\dots,c_{10}(9)=1,1,1,2,2,3,4,5,6,8\) out of 1024. For small \(w\) (\(w\le n\)) the counts do not depend on \(n\): they count partitions of \(w\) into distinct parts. The cumulative sums give the tails quoted above; the largest \(w^*\) with \(P(W\le w^*)\le0.025\) is 2 for \(n=7\) and 8 for \(n=10\), and by symmetry the upper critical values are \(28-2=26\) and \(55-8=47\). ∎

The recursion needs about \(n^3/6\) additions (stage \(i\) updates at most \(i(i+1)/2\) coefficients), so exact tables are easy far beyond \(n=12\): for \(n=50\) the 1275 coefficients take a fraction of a second. The null-distribution demo builds them in the browser.

▶ DemoThe generating function at work: \(n=4\)Preset 1 of the null-distribution demo: the coefficients of \((1+x)(1+x^2)(1+x^3)(1+x^4)\) and Table 14.3.1; preset 2 shows \(n=7\) and the region \(\{w\le2\text{ or }w\ge26\}\).

Case Study 14.3.1 pp. 648–650 (swell sharks). The ratio of total length to the height of the first dorsal fin was recorded for ten male sharks caught near Santa Catalina; the coastal mean is 14.60. Nine ratios fall below 14.60; the only one above, 15.43, has absolute deviation 0.83, tied with 13.77 for ranks 4 and 5, so both get 4.5 and \(w=4.5\). Table A.6 gives the two-sided 0.05 region \(\{w\le8\text{ or }w\ge47\}\), so \(H_0\colon\mu=14.60\) is rejected: the Santa Catalina sharks look different. The book's "About the Data" warns that ratios of measurements can behave badly (the ratio of two independent standard normals is Cauchy, with no mean at all), which is why a test that needs only symmetry is attractive here.

Theorem 14.3.2 (mean, variance and normal approximation) p. 651

Under \(H_0\colon\mu=\mu_0\),

\[ \E(W)=\frac{n(n+1)}4,\qquad \V(W)=\frac{n(n+1)(2n+1)}{24}, \]

and for \(n>12\) the law of \(\big(W-n(n+1)/4\big)\big/\sqrt{n(n+1)(2n+1)/24}\) is adequately approximated by \(\N(0,1)\).

The book derives the mean and variance from the representation of Filling the gap 14.4: \(\E U_i=i/2\) and \(\V U_i=i^2/4\), and \(\sum i=n(n+1)/2\), \(\sum i^2=n(n+1)(2n+1)/6\). For the normal limit it refers to another text. The \(U_i\) are independent but not identically distributed, so the central limit theorem of Chapter 4 does not apply directly; the moment-generating function does the job.

Filling the gap 14.6: the signed-rank statistic is asymptotically normal p. 651, "for a proof of the asymptotic normality, see (88)"

Let \(\mu_n=n(n+1)/4\), \(\sigma_n^2=n(n+1)(2n+1)/24\) and \(W_n^*=(W-\mu_n)/\sigma_n\). Then for every real \(t\), \(M_{W_n^*}(t)\to e^{t^2/2}\), so \(W_n^*\convd\N(0,1)\).

Hint 1 of 5: the key idea

The terms of \(W\) are independent but not identically distributed, so use the moment-generating function directly. Each factor \((1+e^x)/2\) is \(e^{x/2}\cosh(x/2)\): what does that do to the logarithm?

Hint 2 of 5: tools you will need
  • \(\frac{1+e^x}2=e^{x/2}\cosh\frac x2\).
  • Taylor bounds for \(\ln\cosh x\) from \(h''=1-\tanh^2\).
  • \(\sum i^2=n(n+1)(2n+1)/6\), \(\sum i^4\le n^5\).
  • The continuity theorem, Filling the gap 4.9.
Hint 3 of 5: step 1

Write \(\ln M_{W_n^*}(t)\) as a sum of \(\ln\cosh x_i\) with \(x_i=it/(2\sigma_n)\).

Hint 4 of 5: step 2

Prove \(x^2/2-x^4/12\le\ln\cosh x\le x^2/2\) by integrating bounds on \(h''\) twice.

Hint 5 of 5: step 3

Sum the quadratic terms and bound the quartic ones. Aim for: exactly \(t^2/2\), plus an error at most \(144t^4/(192n)\).

Proof

Step 1 (a cosh form). Since \(\frac{1+e^{x}}2=e^{x/2}\cosh\frac x2\), \((14.3.1)\) gives \(\ln M_W(s)=\sum_{i=1}^n\big(\frac{is}2+\ln\cosh\frac{is}2\big)=s\mu_n+\sum_i\ln\cosh\frac{is}2\). Putting \(s=t/\sigma_n\) and subtracting \(t\mu_n/\sigma_n\),

\[ \ln M_{W_n^*}(t)=\sum_{i=1}^n\ln\cosh x_i,\qquad x_i=\frac{it}{2\sigma_n}. \]

Step 2 (two bounds). Let \(h(x)=\ln\cosh x\). Then \(h(0)=h'(0)=0\) and \(h''(x)=1-\tanh^2x\). Since \(0\le\tanh^2x\le x^2\), we have \(1-x^2\le h''(x)\le1\), and integrating twice from 0,

\[ \frac{x^2}2-\frac{x^4}{12}\ \le\ \ln\cosh x\ \le\ \frac{x^2}2\qquad\text{for all real }x. \]

Step 3 (the limit). The quadratic terms add up exactly: \(\sum_ix_i^2/2=\frac{t^2}{8\sigma_n^2}\sum_ii^2=\frac{t^2}{8\sigma_n^2}\cdot\frac{n(n+1)(2n+1)}6=\frac{t^2}2\), because \(\sigma_n^2=\frac14\sum i^2\). The quartic terms are small: \(\sum_ix_i^4/12\le\frac{t^4}{192\sigma_n^4}\sum_ii^4\le\frac{t^4n^5}{192\sigma_n^4}\), and \(\sigma_n^2\ge n^3/12\), so the bound is at most \(\frac{144\,t^4}{192\,n}\to0\). Hence \(\ln M_{W_n^*}(t)\to t^2/2\) for every \(t\).

Step 4. By the continuity theorem for moment-generating functions (used to prove the central limit theorem in Filling the gap 4.9), \(W_n^*\convd\N(0,1)\). ∎

The rate is fast: \(W\) is symmetric, so the first correction to the normal curve is of order \(1/n\), not \(1/\sqrt n\). For \(n=14\) and \(w=95\) (next case study) the exact tail is 0.0026 and the normal one 0.0038 (0.0042 with a continuity correction): so far out, the normal curve is a little too heavy, because \(W\) cannot exceed \(n(n+1)/2=105\) (Figure x14.1(b)).

Theorem 14.3.3 (the large-sample signed-rank test) p. 652

For \(n>12\) independent observations from continuous symmetric densities, let

\[ z=\frac{w-n(n+1)/4}{\sqrt{n(n+1)(2n+1)/24}}. \]

Reject \(H_0\colon\mu=\mu_0\) in favour of \(\mu>\mu_0\) if \(z\ge z_\alpha\), of \(\mu<\mu_0\) if \(z\le-z_\alpha\), and of \(\mu\ne\mu_0\) if \(|z|\ge z_{\alpha/2}\).

Case Study 14.3.2 pp. 652–653 (cyclazocine). Fourteen heroin addicts treated with cyclazocine scored between 21 and 55 on a dependence questionnaire (higher is better); the untreated mean is 28. The histogram is not convincingly normal, symmetry is more believable. With \(\mu_0=28\), the ten positive deviations have rank sum \(w=95.0\) (deviations 15 and 27 occur three and two times and receive midranks). \(\E W=52.5\), \(\V W=253.75\), \(z=(95-52.5)/\sqrt{253.75}=2.67\ge z_{0.05}=1.64\): reject \(H_0\colon\mu=28\) in favour of \(\mu>28\).

Three panels. Left: bars of height 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1 at w equal 0 to 10, the coefficients for n equal 4. Middle: spikes of the exact signed-rank probabilities for n equal 14, a bell shape centred at 52.5, with a red normal curve almost on top, and a dashed orange line at w equal 95 labelled with the exact tail 0.0026. Right: the same for the rank-sum statistic with n equal 14 and m equal 12, centred at 189, with a dashed line at 240.5 and exact tail 0.0032.
Figure x14.1. Exact null laws from the generating functions. (a) The coefficients \(c(w)\) for \(n=4\) (Table 14.3.1). (b) The signed-rank law for \(n=14\) with the normal curve of Theorem 14.3.2 and the observed \(w=95\) of Case Study 14.3.2. (c) The rank-sum law for \(n=14\), \(m=12\) (Filling the gap 14.8) with the normal curve of Theorem 14.3.4 and the observed \(w'=240.5\) of Case Study 14.3.4. Own figure. Code: ch14_nonparametric_statistics.py, fig_x14_1.

Filling the gap 14.7: ties and zeros, the exact conditional law, and the variance correction pp. 645, 649, 653, "each is assigned the average of the ranks"

Suppose zero deviations are dropped (as in Question 14.3.4) and tied absolute deviations receive midranks \(r_1,\dots,r_n\). Under \(H_0\), and conditionally on the absolute deviations,

\[ W=\sum_{i=1}^nr_iZ_i,\quad Z_i\text{ iid }\Bern(\tfrac12),\qquad \E W=\frac{n(n+1)}4,\qquad \V W=\frac14\sum_ir_i^2=\frac{n(n+1)(2n+1)}{24}-\frac{1}{48}\sum_{\text{ties}}(t^3-t), \]

where the last sum runs over groups of \(t\) tied values. The exact conditional law is read off \(2^{-n}\prod_i(1+x^{r_i})\), a polynomial in \(x^{1/2}\). For the sharks (\(w=4.5\)) it gives \(P(W\le4.5)=0.0078\), so the exact two-sided P-value is 0.0156 (the untied table, which treats 4.5 like 4, gives 0.0137); for the cyclazocine data the variance is 253.125 instead of 253.75 and \(P(W\ge95)=0.0026\).

Hint 1 of 5: the key idea

Given the absolute deviations, the signs are still fair coins, so \(W=\sum r_iZ_i\) with fixed midranks. What do midranks do to \(\sum r_i\) and to \(\sum r_i^2\)?

Hint 2 of 5: tools you will need
  • Filling the gap 14.4(a), used conditionally.
  • Mean and variance of a sum of independent \(r_iZ_i\).
  • \(\sum_{j=1}^t(j-\frac{t+1}2)^2=t(t^2-1)/12\).
Hint 3 of 5: step 1

Compute \(\E W\) and \(\V W\) given the midranks. Aim for: \(\frac12\sum r_i\) and \(\frac14\sum r_i^2\).

Hint 4 of 5: step 2

Show a tie group of size \(t\) keeps \(\sum r_i\) and lowers \(\sum r_i^2\) by \(t(t^2-1)/12\). Aim for: the correction \(\sum(t^3-t)/48\).

Hint 5 of 5: step 3

For the cyclazocine data, find the tie groups among \(|y_i-28|\). Aim for: \(\sum(t^3-t)=30\), variance 253.125.

Proof

Ties arise in practice from rounding, so the data are not exactly continuous; but the argument of Filling the gap 14.4(a) needs only symmetry: for a deviation symmetric about 0 and every \(a>0\), \(P(D>0\given|D|=a)=\frac12\). So given the absolute deviations (hence the midranks), the signs are still iid fair coins, and \(W=\sum r_iZ_i\) with the \(r_i\) fixed. Then \(\E W=\frac12\sum r_i\) and \(\V W=\frac14\sum r_i^2\).

A group of \(t\) tied values occupying ranks \(a+1,\dots,a+t\) receives the midrank \(a+\frac{t+1}2\) each. This keeps the sum, so \(\sum r_i=n(n+1)/2\) and the mean is unchanged. The sum of squares falls by \(\sum_{j=1}^t\big(j-\frac{t+1}2\big)^2=\frac{t(t^2-1)}{12}\) (the variance of a uniform variable on \(t\) points, times \(t\)), hence

\[ \sum_ir_i^2=\frac{n(n+1)(2n+1)}6-\frac1{12}\sum_{\text{ties}}(t^3-t), \]

and the variance formula follows on dividing by 4. The generating function is \(\E x^W=\prod_i\frac{1+x^{r_i}}2\) by independence; doubling every midrank makes all exponents integers, and the coefficients give the exact law. For Case Study 14.3.2, \(|y_i-28|=15\) three times and 27 twice, so \(\sum(t^3-t)=24+6=30\) and \(\V W=253.75-30/48=253.125\), \(z=2.67\) either way. ∎

The book's Table A.6 assumes no ties. With ties it is only approximate, and the conditional law above is the exact replacement. In practice a few ties hardly matter, as both examples show.

▶ DemoSharks: the exact law, the table and the tiesPreset 3 of the null-distribution demo: the exact signed-rank law for \(n=10\), the region \(\{w\le8\text{ or }w\ge47\}\), and the exact conditional P-value with the midranks of the data. Preset 4: cyclazocine, exact against normal.

Paired data. pp. 653–655 For pairs, apply the signed-rank test to the differences \(d_i=x_i-y_i\) to test \(H_0\colon\mu_D=0\) (the centre of the distribution of the differences). Use Table A.6 for \(n\le12\) and the \(Z\) ratio of Theorem 14.3.2 for \(n>12\).

Case Study 14.3.3 pp. 654–655 (online course evaluations). Fifteen instructors were rated in class one year and online the next. The positive differences (in-class higher) have rank sum \(w=70\); \(z=(70-60)/\sqrt{310}=0.57\), so \(H_0\colon\mu_D=0\) is not rejected (two-sided P-value 0.57; the exact one is 0.60).

The Wilcoxon rank-sum test. p. 655 For two independent samples \(x_1,\dots,x_n\) and \(y_{n+1},\dots,y_{n+m}\) from continuous densities of the same shape that may differ by a shift, rank the combined sample from 1 to \(n+m\), and let \(w'=\sum_ir_iz_i\) with \(z_i=1\) for the \(x\)'s: the sum of the ranks of the \(x\)'s. A shift of the \(x\)-population to the right makes \(w'\) large.

Theorem 14.3.4 (the rank-sum statistic) p. 655

If the two samples come from the same continuous distribution (no shift), then

\[ \E(W')=\frac{n(n+m+1)}2,\qquad \V(W')=\frac{nm(n+m+1)}{12}, \]

and \(\big(W'-\E W'\big)/\sqrt{\V W'}\) is approximately \(\N(0,1)\) when \(n>10\) and \(m>10\).

The book gives no proof ("See (109)"). The next two boxes give the exact law, the moments and the normal limit.

Filling the gap 14.8: the rank-sum statistic: exact law, mean, variance, ties, and the Mann–Whitney count p. 655, "Proof: See (109)"

Let \(N=n+m\) and assume the \(N\) observations are iid continuous (the null hypothesis). (a) The set of ranks of the \(x\)'s is uniformly distributed over the \(\binom Nn\) subsets of \(\{1,\dots,N\}\) of size \(n\). (b) \(\E W'=n(N+1)/2\) and \(\V W'=nm(N+1)/12\). (c) \(P(W'=w)=c_{N,n}(w)/\binom Nn\), where \(c_{N,n}(w)\) counts the \(n\)-subsets of \(\{1,\dots,N\}\) with sum \(w\); \(c_{N,n}(w)=c_{N-1,n}(w)+c_{N-1,n-1}(w-N)\), and the law is symmetric about \(n(N+1)/2\). (d) \(W'=U+\frac{n(n+1)}2\), where \(U=\#\{(i,j):x_i>y_j\}\) is the Mann–Whitney count, so \(U/(nm)\) estimates \(P(X>Y)\). (e) With midranks, the null variance (given the tie pattern) is \(\frac{nm}{12}\Big[N+1-\frac{\sum(t^3-t)}{N(N-1)}\Big]\).

Hint 1 of 6: the key idea

Under \(H_0\) the ranks of the \(x\)'s are a random \(n\)-subset of \(\{1,\dots,N\}\): \(W'\) is a sum drawn without replacement from a finite list.

Hint 2 of 6: tools you will need
Hint 3 of 6: step 1

Prove \(\V S=n\tau^2(N-n)/(N-1)\) for a sum of \(n\) draws without replacement. Aim for: covariance \(-\tau^2/(N-1)\).

Hint 4 of 6: step 2

Apply it to the list \(1,\dots,N\). Aim for: \(\V W'=nm(N+1)/12\).

Hint 5 of 6: step 3

Write the rank of each \(x_i\) as 1 plus the \(x\)'s and \(y\)'s below it, and sum. Aim for: \(W'=n(n+1)/2+U\).

Hint 6 of 6: step 4

For ties, recompute \(\tau^2\) for the list of midranks.

Proof

(a) The rank vector of the pooled sample is a uniform random permutation (Filling the gap 14.1(c)), so the ranks in the first \(n\) positions form a uniformly random \(n\)-subset: each subset arises from \(n!\,m!\) of the \(N!\) permutations.

A finite-population fact. Let \(S\) be the sum of \(n\) values drawn without replacement from a list \(a_1,\dots,a_N\) with mean \(\bar a\) and variance \(\tau^2=\frac1N\sum(a_k-\bar a)^2\). Each draw has mean \(\bar a\) and variance \(\tau^2\); two different draws have covariance \(c\), and drawing the whole list gives a constant sum, so \(0=N\tau^2+N(N-1)c\), \(c=-\tau^2/(N-1)\). Hence

\[ \E S=n\bar a,\qquad \V S=n\tau^2+n(n-1)c=n\tau^2\,\frac{N-n}{N-1}. \]

(b) With the list \(1,\dots,N\): \(\bar a=\frac{N+1}2\), \(\tau^2=\frac{N^2-1}{12}\), so \(\E W'=\frac{n(N+1)}2\) and \(\V W'=\frac{n(N^2-1)}{12}\cdot\frac{m}{N-1}=\frac{nm(N+1)}{12}\).

(c) By (a), \(P(W'=w)\) is the number of \(n\)-subsets with sum \(w\) divided by \(\binom Nn\). A subset of \(\{1,\dots,N\}\) either omits \(N\) (an \(n\)-subset of \(\{1,\dots,N-1\}\) with sum \(w\)) or contains it (an \((n-1)\)-subset with sum \(w-N\)): the recursion. Equivalently, \(\sum_wc_{N,n}(w)x^w\) is the coefficient of \(y^n\) in \(\prod_{j=1}^N(1+yx^j)\), the two-sample analogue of Theorem 14.3.1. The map \(j\mapsto N+1-j\) sends a subset with sum \(w\) to one with sum \(n(N+1)-w\): symmetry.

(d) The rank of \(x_i\) is 1 plus the number of \(x\)'s below it plus the number of \(y\)'s below it. Summing over \(i\): the \(x\)'s below each \(x\) contribute \(0+1+\dots+(n-1)=n(n-1)/2\) in total, and the \(y\)'s below the \(x\)'s contribute \(U\). So \(W'=n+\frac{n(n-1)}2+U=\frac{n(n+1)}2+U\). Each pair has \(P(X_i>Y_j)=\frac12\) under \(H_0\), so \(\E U=nm/2\), consistent with (b).

(e) Apply the finite-population fact to the list of midranks. A tied group of size \(t\) lowers \(N\tau^2\) by \(t(t^2-1)/12\) (as in Filling the gap 14.7), so \(\tau^2=\frac{N^2-1}{12}-\frac{\sum(t^3-t)}{12N}\) and \(\V W'=\frac{nm}{N-1}\tau^2\), which simplifies to the formula stated. ∎

Part (d) tells what the test detects: \(W'\) is a linear function of an unbiased estimate of \(P(X>Y)\), so the test is consistent against every alternative with \(P(X>Y)\ne\frac12\) (its null law above is exact only when the two distributions coincide). Under the book's shift model that is the same as \(\mu_X\ne\mu_Y\); without it the rank-sum test is a test of \(P(X>Y)=\frac12\), not of equal means.

Filling the gap 14.9: the rank-sum statistic is asymptotically normal (a projection argument) p. 655, "has approximately a standard normal pdf if n > 10 and m > 10"

Under \(H_0\), \((W'-\E W')/\sqrt{\V W'}\convd\N(0,1)\) as \(n\to\infty\) and \(m\to\infty\).

Hint 1 of 6: the key idea

\(U\) is a double sum of dependent indicators. Replace each indicator by its best approximation using one variable at a time; the leftover pieces are uncorrelated and their total is small.

Hint 2 of 6: tools you will need
Hint 3 of 6: step 1

Reduce to uniforms and decompose \(\one\{a>b\}-\frac12\) into \((a-\frac12)+(\frac12-b)+k(a,b)\).

Hint 4 of 6: step 2

Show the remainders \(k(A_i,B_j)\) are pairwise uncorrelated with \(\E k^2=\frac1{12}\). Aim for: variance \(nm/12\), negligible against \(\V U\).

Hint 5 of 6: step 3

Write the projection as \(\sum c_l\xi_l\) with bounded iid \(\xi_l\) and \(\max c_l\to0\), and expand its mgf. Aim for: \(t^2/2\).

Hint 6 of 6: step 4

Combine with Slutsky's theorem.

Proof

Step 1 (reduce to uniforms). Let \(F\) be the common continuous cdf and \(A_i=F(X_i)\), \(B_j=F(Y_j)\). These are iid \(\Unif(0,1)\) (probability integral transform, Section 3.8), and with probability 1, \(X_i>Y_j\) exactly when \(A_i>B_j\) (\(F\) is non-decreasing, and \(A_i=B_j\) has probability 0). By Filling the gap 14.8(d) it suffices to treat \(U=\sum_{i,j}\one\{A_i>B_j\}\), with \(\E U=nm/2\) and \(\V U=nm(N+1)/12\).

Step 2 (the projection). Write \(\one\{a>b\}-\frac12=(a-\frac12)+(\frac12-b)+k(a,b)\), which defines \(k\). For independent uniforms \(A,B\): \(\E[\one\{A>B\}\given A]=A\) and \(\E[\one\{A>B\}\given B]=1-B\), so \(\E[k(A,B)\given A]=0\) and \(\E[k(A,B)\given B]=0\). Then

\[ U-\frac{nm}2=\hat U+\sum_{i,j}k(A_i,B_j),\qquad \hat U=m\sum_{i=1}^n\big(A_i-\tfrac12\big)-n\sum_{j=1}^m\big(B_j-\tfrac12\big). \]

Step 3 (the remainder is small). For two different pairs \((i,j)\ne(i',j')\), \(\E[k(A_i,B_j)k(A_{i'},B_{j'})]=0\): if all four indices differ, the factors are independent with mean 0; if \(i=i'\) but \(j\ne j'\), conditionally on \(A_i\) the factors are independent with conditional mean 0 (and similarly if \(j=j'\)). Hence \(\E\big(\sum k\big)^2=nm\,\E k(A,B)^2\). Since the three pieces of the decomposition are uncorrelated (by the same conditional-mean argument), \(\E k^2=\V\one\{A>B\}-\V A-\V B=\frac14-\frac1{12}-\frac1{12}=\frac1{12}\). So the remainder has variance \(nm/12\), and divided by \(\sqrt{\V U}\) its variance is \(\frac{nm/12}{nm(N+1)/12}=\frac1{N+1}\to0\). By Chebyshev's inequality (Theorem 5.7.1) it tends to 0 in probability.

Step 4 (the projection is normal). \(\V\hat U=m^2\frac n{12}+n^2\frac m{12}=\frac{nmN}{12}\). Write \(\hat U/\sqrt{\V\hat U}=\sum_{l=1}^Nc_l\xi_l\), where the \(\xi_l=\sqrt{12}(A_i-\frac12)\) or \(-\sqrt{12}(B_j-\frac12)\) are iid, mean 0, variance 1 and bounded by \(\sqrt3\), and \(c_l^2=m/(nN)\) for the \(A\) terms and \(n/(mN)\) for the \(B\) terms, so \(\sum c_l^2=1\) and \(\max c_l^2\le\max(1/n,1/m)\to0\). For a variable with \(|\xi|\le\sqrt3\), mean 0 and variance 1, Taylor's theorem gives \(\ln\E e^{s\xi}=\frac{s^2}2+O(|s|^3)\) uniformly for \(|s|\le1\). Hence

\[ \ln\E\exp\Big(t\sum_lc_l\xi_l\Big)=\sum_l\Big(\frac{c_l^2t^2}2+O(|c_lt|^3)\Big)=\frac{t^2}2+O\big(|t|^3\max_lc_l\big)\to\frac{t^2}2, \]

and \(\hat U/\sqrt{\V\hat U}\convd\N(0,1)\) by the continuity theorem.

Step 5. \(\frac{U-nm/2}{\sqrt{\V U}}=\sqrt{\frac{N}{N+1}}\cdot\frac{\hat U}{\sqrt{\V\hat U}}+\frac{\sum k}{\sqrt{\V U}}\). The first term tends to \(\N(0,1)\), the second to 0 in probability, so the sum tends to \(\N(0,1)\) by Slutsky's theorem (graduate Theorem 5.5). ∎

The same projection, applied to one group against the rest, gives the chi-square limit of the Kruskal–Wallis statistic (Filling the gap 14.11).

Case Study 14.3.4 pp. 656–657 (game times, 1992). The fourteen American League teams (designated hitter) averaged 173.5 minutes per home game, the twelve National League teams 165.8. The American League ranks sum to \(w'=240.5\); \(\E W'=14\cdot27/2=189\), \(\V W'=14\cdot12\cdot27/12=378\), so \(z=(240.5-189)/\sqrt{378}=2.65>1.96\): the difference is significant. (The book says "the formulas in Theorem 14.3.3"; it means Theorem 14.3.4.) With the tie correction of Filling the gap 14.8(e) the variance is 374.5 and \(z=2.66\); the exact conditional two-sided P-value is 0.0065. The Mann–Whitney count is \(U=240.5-105=135.5\) of 168 pairs: in about 81% of AL–NL pairs the American League team had the longer games.

▶ DemoGame times: the exact rank-sum law for \(n=14\), \(m=12\)Preset 5 of the null-distribution demo: all \(\binom{26}{14}=9{,}657{,}700\) splits counted by the recursion, the normal curve of Theorem 14.3.4, and the exact P-value with the data's midranks.

See also (companion courses): the graduate course's permutation test demo (exact permutation laws and their size) and Statistical Methods for Modern Biology's permutation test demo (all 184,756 relabellings of a small experiment): the rank-sum test is the permutation test applied to ranks.

14.4 The Kruskal-Wallis Test

pp. 658–659 For \(k\ge2\) independent samples of sizes \(n_1,\dots,n_k\) from continuous densities of the same shape, possibly shifted, test \(H_0\colon\mu_1=\dots=\mu_k\). Rank all \(n=\sum n_j\) observations together, let \(R_{ij}\) be the rank of \(Y_{ij}\) and \(R_{\cdot j}\) the rank sum of sample \(j\). The Kruskal–Wallis statistic is

\[ B=\frac{12}{n(n+1)}\sum_{j=1}^k\frac{R_{\cdot j}^2}{n_j}-3(n+1), \]

which plays the role of the treatment sum of squares of the one-way analysis of variance. The book announces that neither this test nor Friedman's "will be derived"; the boxes below derive both.

Theorem 14.4.1 (the Kruskal–Wallis test) p. 659

If the \(k\) samples come from continuous densities of the same shape and \(H_0\colon\mu_1=\dots=\mu_k\) holds, then \(B\) has approximately a \(\chi^2_{k-1}\) distribution, and \(H_0\) is rejected at level \(\alpha\) if \(b\ge\chi^2_{1-\alpha,\,k-1}\).

Filling the gap 14.10: the Kruskal–Wallis statistic is the analysis of variance of the ranks, its exact mean is \(k-1\), and with two samples it is the rank-sum test pp. 658–659, Question 14.4.8

Let \(\bar R_j=R_{\cdot j}/n_j\). Under \(H_0\) (all \(n\) observations iid continuous):

(a) \(\displaystyle B=\frac{12}{n(n+1)}\sum_{j=1}^kn_j\Big(\bar R_j-\frac{n+1}2\Big)^2\), the treatment sum of squares of the ranks divided by \(n(n+1)/12\), the variance of a single rank;

(b) \(\E\bar R_j=\frac{n+1}2\) and \(\V\bar R_j=\frac{(n+1)(n-n_j)}{12\,n_j}\);

(c) \(\E(B)=k-1\) exactly, the mean of \(\chi^2_{k-1}\);

(d) for \(k=2\), \(B=z^2\), where \(z\) is the standardised rank-sum statistic of Theorem 14.3.4, so the Kruskal–Wallis test with two samples is the two-sided rank-sum test.

Hint 1 of 6: the key idea

\(B\) is the treatment sum of squares of the ranks, divided by the variance of one rank. Its expectation needs only the variances of the mean ranks.

Hint 2 of 6: tools you will need
  • \(\sum_jR_{\cdot j}=n(n+1)/2\).
  • The finite-population variance of Filling the gap 14.8.
  • Theorem 14.3.4 for \(k=2\).
Hint 3 of 6: step 1

Expand \(\sum n_j(\bar R_j-c)^2\) with \(c=\frac{n+1}2\). Aim for: \(\sum R_{\cdot j}^2/n_j-n(n+1)^2/4\).

Hint 4 of 6: step 2

Find \(\V\bar R_j\) by sampling without replacement. Aim for: \((n+1)(n-n_j)/(12n_j)\).

Hint 5 of 6: step 3

Take expectations in (a). Aim for: \(\frac1n\sum_j(n-n_j)=k-1\).

Hint 6 of 6: step 4

For \(k=2\), use \(n_1(\bar R_1-c)=-n_2(\bar R_2-c)\) to write \(B\) in terms of \(R_{\cdot1}\) only.

Proof

(a) Put \(c=\frac{n+1}2\). Since \(\sum_jR_{\cdot j}=\frac{n(n+1)}2=nc\),

\[ \sum_jn_j(\bar R_j-c)^2=\sum_j\frac{R_{\cdot j}^2}{n_j}-2c\sum_jR_{\cdot j}+c^2n=\sum_j\frac{R_{\cdot j}^2}{n_j}-\frac{n(n+1)^2}4, \]

and multiplying by \(\frac{12}{n(n+1)}\) gives \(\frac{12}{n(n+1)}\sum R_{\cdot j}^2/n_j-3(n+1)=B\).

(b) \(R_{\cdot j}\) is the sum of \(n_j\) ranks drawn without replacement from \(\{1,\dots,n\}\) (Filling the gap 14.1(c)), so by the finite-population fact of Filling the gap 14.8, \(\E R_{\cdot j}=n_jc\) and \(\V R_{\cdot j}=n_j\frac{n^2-1}{12}\cdot\frac{n-n_j}{n-1}=\frac{n_j(n+1)(n-n_j)}{12}\). Divide by \(n_j\) and \(n_j^2\).

(c) By (a) and (b), \(\E B=\frac{12}{n(n+1)}\sum_jn_j\V\bar R_j=\frac{12}{n(n+1)}\sum_j\frac{(n+1)(n-n_j)}{12}=\frac1n\sum_j(n-n_j)=\frac{kn-n}n=k-1\).

(d) With two samples, \(n_1(\bar R_1-c)+n_2(\bar R_2-c)=0\), so \(\bar R_2-c=-\frac{n_1}{n_2}(\bar R_1-c)\) and

\[ B=\frac{12}{n(n+1)}\Big(n_1+\frac{n_1^2}{n_2}\Big)(\bar R_1-c)^2=\frac{12\,n_1}{n_2(n+1)}(\bar R_1-c)^2=\frac{(R_{\cdot1}-n_1c)^2}{n_1n_2(n+1)/12}, \]

which is \(\big(W'-\E W'\big)^2/\V W'\) with \(W'=R_{\cdot1}\), \(n=n_1\), \(m=n_2\) in the notation of Theorem 14.3.4. ∎

With ties, midranks keep (a) and (b) with \(\frac{n^2-1}{12}\) replaced by the variance of the midranks; dividing \(B\) by \(1-\sum(t^3-t)/(n^3-n)\) restores the exact mean \(k-1\). Question 14.4.8 writes \(B\) as a weighted sum of squared standardised mean ranks.

Filling the gap 14.11: why \(B\) is approximately \(\chi^2_{k-1}\) p. 659, Theorem 14.4.1 ("will not be derived")

Under \(H_0\), if \(n\to\infty\) with \(n_j/n\to\lambda_j>0\) for every \(j\), then \(B\convd\chi^2_{k-1}\).

Hint 1 of 6: the key idea

Each mean rank is, up to a small error, \(n\) times a mean of iid uniforms. Then \(B\) is the normal-theory treatment sum of squares of uniforms: a squared projection of a normal vector.

Hint 2 of 6: tools you will need
Hint 3 of 6: step 1

Write \(R_{\cdot j}=n_j(n_j+1)/2+U_j\) and project \(U_j\). Aim for: \(\bar R_j-\frac{n+1}2=n(\bar V_j-\bar V)+e_j/n_j\).

Hint 4 of 6: step 2

Show the error term of \(T_j\) has variance at most \(1/(n+1)\).

Hint 5 of 6: step 3

Express \(\sqrt{12n_j}(\bar V_j-\bar V)\) through independent \(G_j\to\N(0,1)\). Aim for: \((I-uu^\T)G\) with \(u_j=\sqrt{n_j/n}\).

Hint 6 of 6: step 4

Pass to the limit and use the squared length of a projected standard normal vector.

Proof

Step 1 (one sample against the rest). Let \(V_l=F(Y_l)\) be the uniforms of all \(n\) observations, \(\bar V_j\) their mean in sample \(j\) and \(\bar V\) the overall mean. The ranks of sample \(j\) add up to \(R_{\cdot j}=\frac{n_j(n_j+1)}2+U_j\), where \(U_j\) counts pairs (an observation of sample \(j\), an observation outside it) in which the first is larger (as in Filling the gap 14.8(d)). Applying Filling the gap 14.9 to sample \(j\) (size \(n_j\)) against the rest (size \(n-n_j\)),

\[ U_j-\frac{n_j(n-n_j)}2=(n-n_j)\sum_{i\in j}\big(V_i-\tfrac12\big)-n_j\sum_{l\notin j}\big(V_l-\tfrac12\big)+e_j=n\,n_j(\bar V_j-\bar V)+e_j, \]

with \(\E e_j=0\) and \(\E e_j^2=n_j(n-n_j)/12\). Dividing by \(n_j\) and using \(\frac{n_j+1}2+\frac{n-n_j}2=\frac{n+1}2\): \(\bar R_j-\frac{n+1}2=n(\bar V_j-\bar V)+e_j/n_j\).

Step 2 (the statistic as a squared length). By Filling the gap 14.10(a), \(B=\sum_jT_j^2\) with \(T_j=\sqrt{\frac{12n_j}{n(n+1)}}\big(\bar R_j-\frac{n+1}2\big)\), and by Step 1

\[ T_j=\sqrt{\tfrac n{n+1}}\;\sqrt{12n_j}\,(\bar V_j-\bar V)+\epsilon_j,\qquad \E\epsilon_j^2=\frac{12}{n_j\,n(n+1)}\cdot\frac{n_j(n-n_j)}{12}\le\frac1{n+1}\to0. \]

Step 3 (the limit is a projection of a normal vector). Put \(G_j=\sqrt{12n_j}(\bar V_j-\frac12)\). The \(G_j\) are independent (different samples) and each tends to \(\N(0,1)\) by the central limit theorem (\(\V V=\frac1{12}\)), so \(G=(G_1,\dots,G_k)^\T\convd Z\sim\N(0,I)\) (the joint moment-generating function factorises). Since \(\bar V=\sum_l\frac{n_l}n\bar V_l\),

\[ \sqrt{12n_j}(\bar V_j-\bar V)=G_j-\sqrt{\tfrac{n_j}n}\sum_l\sqrt{\tfrac{n_l}n}\,G_l=\big[(I-uu^\T)G\big]_j,\qquad u=\Big(\sqrt{\tfrac{n_1}n},\dots,\sqrt{\tfrac{n_k}n}\Big)^\T, \]

a unit vector tending to \(u^*=(\sqrt{\lambda_j})_j\). So \(T\convd(I-u^*u^{*\T})Z\) (the \(\epsilon_j\) tend to 0 in probability, Slutsky), and \(B=\|T\|^2\convd\|(I-u^*u^{*\T})Z\|^2\). The matrix \(I-u^*u^{*\T}\) is the orthogonal projection onto the \((k-1)\)-dimensional subspace orthogonal to \(u^*\), and the squared length of the projection of a standard normal vector onto a \((k-1)\)-dimensional subspace is \(\chi^2_{k-1}\): this is exactly the argument of Pearson's theorem (Filling the gap 10.6(iii)). ∎

In words: the ranks behave like \(n\) times iid uniforms, and \(B\) is the normal-theory treatment sum of squares of those uniforms divided by their variance \(\frac1{12}\). One degree of freedom is lost because the mean ranks are tied together by \(\sum n_j\bar R_j=n(n+1)/2\), just as the \(k\) group means lose one in the analysis of variance.

Case Study 14.4.1 pp. 659–661 (the 1969 draft lottery). The 366 birth dates were drawn one by one; the order of drawing is a ranking of the dates from 1 to 366, with no ties and no data other than ranks. If the lottery was fair, the ranks are a uniform random permutation and the twelve monthly rank totals should differ only by chance. The totals range from 7000 (March) to 3768 (December), with a clear downward trend (Figure 14.4.1). With \(n_j\) equal to the number of days in each month (31, 29, 31, 30, ...),

\[ b=\frac{12}{366\cdot367}\Big(\frac{6236^2}{31}+\frac{5886^2}{29}+\dots+\frac{3768^2}{31}\Big)-3\cdot367=25.95\ \ge\ \chi^2_{0.99,\,11}=24.725, \]

so randomness is rejected at \(\alpha=0.01\) (P-value 0.0066). Grouping into two half-years (rank totals 37,551 for 182 days and 29,610 for 184 days) gives \(b=16.85\) on one degree of freedom. The book gauges this by \((16.85-1)/\sqrt2=11.2\) "standard deviations"; the chi-square law is far from normal, and the honest measure is the P-value \(P(\chi^2_1\ge16.85)=4.0\times10^{-5}\). By Filling the gap 14.10(d) this is the two-sided rank-sum test with \(z=\pm\sqrt{16.85}=\pm4.10\). The likely cause, according to the book, is that the capsules went into the bowl month by month and were not mixed well.

Line plot of the average selection number by birth month, January to December, against a dashed horizontal line at 183.5. The averages start near 200 in January, peak at about 226 in March, and fall to about 157 in September, 149 in November and 122 in December.
Figure 14.4.1. Average draft-lottery selection number by birth month in 1969, from the rank totals of Table 14.4.2 divided by the number of days; under a fair lottery each average is \(183.5\pm\) chance. Reproduces Larsen and Marx (2018), Figure 14.4.1. Code: ch14_nonparametric_statistics.py, fig_14_4_1.

14.5 The Friedman Test

p. 662 For a randomised block design with \(k\) treatments in each of \(b\) blocks, rank the \(k\) responses within each block (1 to \(k\)) and let \(r_{\cdot j}\) be the rank sum of treatment \(j\) over the blocks.

Theorem 14.5.1 (Friedman's test) p. 662

If \(k\ge2\) treatments are ranked independently within \(b\) blocks, the hypothesis that the treatment medians are equal is rejected at (approximately) level \(\alpha\) if

\[ g=\frac{12}{bk(k+1)}\sum_{j=1}^kr_{\cdot j}^2-3b(k+1)\ \ge\ \chi^2_{1-\alpha,\,k-1}. \]

The exact null hypothesis behind the test is that within each block the \(k\) responses are exchangeable (for example iid, block effects allowed), so that every ordering of the treatments within a block is equally likely, independently across blocks.

Filling the gap 14.12: Friedman's statistic as a sum of squares, its exact mean, and two treatments pp. 662–665, Question 14.5.6

Let \(\bar r_j=r_{\cdot j}/b\) and \(\bar r_{\cdot\cdot}=\frac{k+1}2\) (the mean of all \(bk\) ranks). Then (a) \(g=\frac{12b}{k(k+1)}\sum_j(\bar r_j-\bar r_{\cdot\cdot})^2\), the analogue of the treatment sum of squares \(b\sum_j(\bar y_{\cdot j}-\bar y_{\cdot\cdot})^2\) of the randomised block analysis; (b) under \(H_0\), \(\E r_{\cdot j}=\frac{b(k+1)}2\), \(\V r_{\cdot j}=\frac{b(k^2-1)}{12}\), and \(\E(G)=k-1\) exactly; (c) for \(k=2\), \(g=\frac{(u-b/2)^2}{b/4}\), where \(u\) is the number of blocks in which treatment 1 has the larger response: Friedman's test with two treatments is the two-sided sign test.

Hint 1 of 5: the key idea

Within each block the ranks are a uniform permutation of \(1,\dots,k\), independently over blocks. Friedman's \(g\) is a sum of squared deviations of rank sums from their mean.

Hint 2 of 5: tools you will need
  • \(\sum_jr_{\cdot j}=bk(k+1)/2\).
  • Moments of a uniform rank, Filling the gap 14.1(c).
  • For \(k=2\): ranks are 1 or 2 in each block.
Hint 3 of 5: step 1

Expand \(\sum_j(r_{\cdot j}-c)^2\) with \(c=b(k+1)/2\). Aim for: \(\sum r_{\cdot j}^2-b^2k(k+1)^2/4\).

Hint 4 of 5: step 2

Compute \(\V r_{\cdot j}\) and take expectations. Aim for: \(\E G=k-1\).

Hint 5 of 5: step 3

With \(k=2\) put \(r_{\cdot1}=b+u\), \(r_{\cdot2}=2b-u\) and simplify. Aim for: \(\frac4b(u-\frac b2)^2\).

Proof

(a) Each block contributes \(1+\dots+k=\frac{k(k+1)}2\), so \(\sum_jr_{\cdot j}=\frac{bk(k+1)}2\). With \(c=\frac{b(k+1)}2\),

\[ \sum_j(r_{\cdot j}-c)^2=\sum_jr_{\cdot j}^2-2c\cdot\frac{bk(k+1)}2+kc^2=\sum_jr_{\cdot j}^2-\frac{b^2k(k+1)^2}4. \]

Multiplying by \(\frac{12}{bk(k+1)}\) gives \(g\). Since \(r_{\cdot j}-c=b(\bar r_j-\bar r_{\cdot\cdot})\), \(g=\frac{12}{bk(k+1)}b^2\sum(\bar r_j-\bar r_{\cdot\cdot})^2\), which is (a).

(b) Under \(H_0\) the within-block rank vectors are independent uniform permutations (Filling the gap 14.1(c) applied to each block), so the rank of treatment \(j\) in a block has mean \(\frac{k+1}2\) and variance \(\frac{k^2-1}{12}\); summing over the \(b\) independent blocks gives the moments of \(r_{\cdot j}\), and

\[ \E G=\frac{12}{bk(k+1)}\sum_j\V r_{\cdot j}=\frac{12}{bk(k+1)}\cdot k\cdot\frac{b(k^2-1)}{12}=k-1. \]

(c) With \(k=2\), \(r_{\cdot1}=b+u\) (rank 2 in \(u\) blocks, rank 1 in the others) and \(r_{\cdot2}=2b-u\). Then

\[ g=\frac{2}{b}\big[(b+u)^2+(2b-u)^2\big]-9b=\frac2b\big(5b^2-2bu+2u^2\big)-9b=b-4u+\frac{4u^2}b=\frac4b\Big(u-\frac b2\Big)^2. \]

∎

Case Study 14.5.1 pp. 663–664 (rounding first base). Twenty-two players ran from home to second base along a narrow-angle and a wide-angle path. The rank sums are 39 (narrow) and 27 (wide), so

\[ g=\frac{12}{22\cdot2\cdot3}\big(39^2+27^2\big)-3\cdot22\cdot3=6.54\ \ge\ \chi^2_{0.95,\,1}=3.84: \]

the wide-angle path is faster. By Filling the gap 14.12(c) this is the sign test: the wide path was faster for \(u=17\) of 22 players, \(z=(17-11)/\sqrt{5.5}=2.56\), \(z^2=6.54\). The exact binomial two-sided P-value is 0.017 (the chi-square one is 0.011).

Filling the gap 14.13: why \(G\) is approximately \(\chi^2_{k-1}\) as the number of blocks grows p. 662, Theorem 14.5.1 ("will not be derived")

Under \(H_0\), with \(k\) fixed and \(b\to\infty\), \(G\convd\chi^2_{k-1}\).

Hint 1 of 5: the key idea

The vector of rank sums is a sum of \(b\) iid random permutation vectors, so the multivariate central limit theorem applies; the limit covariance is a scaled projection.

Hint 2 of 5: tools you will need
Hint 3 of 5: step 1

Write the covariance of one block's rank vector with \(J=\mathbf1\mathbf1^\T\). Aim for: \(\frac{k+1}{12}(kI-J)\).

Hint 4 of 5: step 2

Scale the centred rank sums by \(\sqrt{12/(bk(k+1))}\). Aim for: limit covariance \(I-\frac1kJ\).

Hint 5 of 5: step 3

Recognise \(I-\frac1kJ\) as a projection of rank \(k-1\) and conclude.

Proof

Let \(\rho_1,\dots,\rho_b\in\R^k\) be the within-block rank vectors: iid uniform random permutations of \((1,\dots,k)\). By Filling the gap 14.1(c) each has mean \(\frac{k+1}2\mathbf1\) and covariance matrix

\[ \Sigma=\frac{k^2-1}{12}I-\frac{k+1}{12}(J-I)=\frac{k+1}{12}\,(kI-J), \]

where \(J=\mathbf1\mathbf1^\T\) (diagonal \(\frac{k^2-1}{12}\), off-diagonal \(-\frac{k+1}{12}\)). The vector of rank sums is \(r=\sum_l\rho_l\), a sum of \(b\) iid vectors, so by the multivariate central limit theorem (graduate Theorem 5.12; the moment-generating-function proof of Filling the gap 10.5 works the same way) \((r-b\frac{k+1}2\mathbf1)/\sqrt b\convd\N(0,\Sigma)\). Scale by \(\sqrt{12/(k(k+1))}\): the vector

\[ T=\sqrt{\frac{12}{bk(k+1)}}\Big(r-\frac{b(k+1)}2\mathbf1\Big)\convd\N\Big(0,\ I-\tfrac1kJ\Big), \]

and \(g=\|T\|^2\) by Filling the gap 14.12(a). The matrix \(I-\frac1kJ=I-uu^\T\) with \(u=\mathbf1/\sqrt k\) is the projection onto the \((k-1)\)-dimensional subspace orthogonal to \(\mathbf1\), so, as in Filling the gap 10.6(iii), \(\|T\|^2\convd\chi^2_{k-1}\). ∎

The lost degree of freedom is the constraint \(\sum_jr_{\cdot j}=bk(k+1)/2\). Unlike Kruskal–Wallis, here the asymptotics need many blocks; the number of treatments stays fixed.

14.6 Testing for Randomness

pp. 665–666 Every test assumes the observations are a random sample: the value of one does not influence another. Measurements made in time order may instead drift (a machine slipping out of calibration) or alternate (two operators). For time-ordered measurements \(y_1,\dots,y_n\) from a continuous distribution, write down the signs of the successive differences, \(\sgn(y_2-y_1),\dots,\sgn(y_n-y_{n-1})\): \(n-1\) pluses and minuses. A run up is a maximal block of pluses, a run down a block of minuses, and \(W\) is the total number of runs up and down. For \(14.2,\ 10.6,\ 11.2,\ 12.1,\ 9.3\) the signs are \(-\,+\,+\,-\) and \(W=3\). A trend gives few long runs; alternation gives many short ones.

Theorem 14.6.1 (runs up and down) p. 666

If \(y_1,\dots,y_n\) (\(n>2\)) are iid from a continuous distribution, the number \(W\) of runs up and down has

\[ \E(W)=\frac{2n-1}3,\qquad \V(W)=\frac{16n-29}{90}, \]

and \((W-\E W)/\sqrt{\V W}\) is approximately \(\N(0,1)\) for \(n\ge20\).

Filling the gap 14.14: the mean and variance of the number of runs, through turning points p. 666, "Proof: See (133) and (216)"

Call \(y_i\) (\(2\le i\le n-1\)) a turning point if it is larger than both neighbours or smaller than both, and let \(T_i\) be its indicator. Then \(W=1+\sum_{i=2}^{n-1}T_i\), and

\[ P(T_i=1)=\tfrac23,\qquad P(T_i=T_{i+1}=1)=\tfrac5{12},\qquad P(T_i=T_{i+2}=1)=\tfrac9{20}, \]

while \(T_i\) and \(T_j\) are independent for \(|i-j|\ge3\). Hence \(\E W=\frac{2n-1}3\) for \(n\ge2\) and \(\V W=\frac{16n-29}{90}\) for \(n\ge4\). (For \(n=3\) the formula gives \(\frac{19}{90}\), but \(W=1+T_2\) has variance \(\frac23\cdot\frac13=\frac{20}{90}\).)

Hint 1 of 6: the key idea

A new run starts exactly at a turning point (a local maximum or minimum), so \(W=1+\sum T_i\). Indicators far apart are independent; only neighbours and next-neighbours interact.

Hint 2 of 6: tools you will need
  • Equally likely orderings of iid continuous values.
  • Counting zigzag permutations of 4 values.
  • Conditioning on a shared middle value; \(\V(\sum T_i)\) from variances and covariances.
Hint 3 of 6: step 1

Find \(P(T_i=1)\) from the 6 orderings of three values. Aim for: \(\frac23\) and \(\E W=(2n-1)/3\).

Hint 4 of 6: step 2

Count up-down-up and down-up-down orderings of four values. Aim for: \(\frac{10}{24}\).

Hint 5 of 6: step 3

For \(T_i,T_{i+2}\), condition on the shared value \(s\). Aim for: \(g(s)=\frac12+s-s^2\) and \(\int g^2=\frac9{20}\).

Hint 6 of 6: step 4

Add up the covariance terms, counting \(n-2\), \(n-3\) and \(n-4\) of each kind. What changes when \(n=3\)?

Proof

Runs and turning points. A new run starts exactly where the sign sequence changes, and the sign changes between \(\sgn(y_i-y_{i-1})\) and \(\sgn(y_{i+1}-y_i)\) exactly when \(y_i\) is a turning point. The first run is always there, so \(W=1+\sum T_i\).

One turning point. By Filling the gap 14.1(c) the relative order of \(y_{i-1},y_i,y_{i+1}\) is one of 6 equally likely orderings, and \(y_i\) is extreme (largest or smallest of the three) in 4 of them: \(P(T_i=1)=\frac23\). So \(\E W=1+\frac23(n-2)=\frac{2n-1}3\).

Neighbours. \(T_i=T_{i+1}=1\) means \(y_{i-1},\dots,y_{i+2}\) zigzag: up-down-up or down-up-down. Of the 24 orderings of four values, 5 are up-down-up (1324, 1423, 2314, 2413, 3412 in the notation "positions of the ranks") and 5 are down-up-down by reversal, so the probability is \(\frac{10}{24}=\frac5{12}\).

Distance two. \(T_i\) depends on \((y_{i-1},y_i,y_{i+1})\) and \(T_{i+2}\) on \((y_{i+1},y_{i+2},y_{i+3})\); they share \(y_{i+1}\). Use uniforms (apply \(F\), which keeps all orderings) and condition on \(y_{i+1}=s\). For \(T_i\), \(y_i\) must exceed both \(y_{i-1}\) and \(s\), or be below both:

\[ g(s)=P(T_i=1\given y_{i+1}=s)=\int_s^1x\,\d x+\int_0^s(1-x)\,\d x=\frac12+s-s^2. \]

By symmetry \(T_{i+2}\) has the same conditional probability, and given \(s\) the two are independent (they use disjoint other variables). Hence

\[ P(T_i=T_{i+2}=1)=\int_0^1g(s)^2\,\d s=\int_0^1\Big(\frac14+s-2s^3+s^4\Big)\d s=\frac14+\frac12-\frac12+\frac15=\frac9{20}. \]

(As a check, \(\int_0^1g=\frac12+\frac12-\frac13=\frac23\).) For \(|i-j|\ge3\) the two triples are disjoint, so \(T_i\) and \(T_j\) are independent.

The variance. \(\V T_i=\frac23\cdot\frac13=\frac29\), \(\Cov(T_i,T_{i+1})=\frac5{12}-\frac49=-\frac1{36}\), \(\Cov(T_i,T_{i+2})=\frac9{20}-\frac49=\frac1{180}\). There are \(n-2\) indicators, \(n-3\) neighbouring pairs and \(n-4\) pairs at distance two (when \(n\ge4\)), so

\[ \V W=(n-2)\frac29-2(n-3)\frac1{36}+2(n-4)\frac1{180}=\frac{20(n-2)-5(n-3)+(n-4)}{90}=\frac{16n-29}{90}. \]

For \(n=3\) there is no pair at distance two; the term \(2(n-4)/180\) would be \(-\frac2{180}\), which is the source of the discrepancy. ∎

Filling the gap 14.15: the exact null law of \(W\), and why it is asymptotically normal p. 666, Theorem 14.6.1(c)

(a) The exact law of \(W\) can be computed by a recursion that adds one observation at a time and tracks only the relative rank of the last observation among those so far, the direction of the last step and the number of runs. (b) \((W-\E W)/\sqrt{\V W}\convd\N(0,1)\) as \(n\to\infty\).

Hint 1 of 5: the key idea

For the exact law, only the relative rank of the last observation, the last direction and the run count matter. For normality, the turning-point indicators are independent beyond distance 2: cut the sequence into long blocks separated by short gaps.

Hint 2 of 5: tools you will need
  • Uniform relative rank of a new observation.
  • The central limit theorem for iid block sums.
  • Chebyshev's inequality, Theorem 5.7.1.
Hint 3 of 5: step 1

Write the transition: a new observation of relative rank \(j'\) is a step up exactly when \(j'>j\). Aim for: the two update sums.

Hint 4 of 5: step 2

Show the block sums are iid and the gap sums independent of each other. Aim for: gap variance at most \(q\), against \(\V W\approx16n/90\).

Hint 5 of 5: step 3

Let the block length grow and use the approximation lemma to conclude.

Proof

(a) Under \(H_0\) the relative rank of the new observation among the first \(i+1\) is uniform on \(\{1,\dots,i+1\}\) and independent of the relative order of the first \(i\) (this is Filling the gap 14.1(c) again: each of the \((i+1)!\) orderings is equally likely). If the last of the first \(i\) has relative rank \(j\) and the new one has relative rank \(j'\), the step is up exactly when \(j'>j\); the old last element's rank among \(i+1\) becomes \(j\) or \(j+1\), but only the new last element's rank \(j'\) matters for the future. So the probabilities \(f_i(j,d,w)\) of "last rank \(j\), last direction \(d\), \(w\) runs so far" satisfy

\[ f_{i+1}(j',\text{up},\cdot)=\frac1{i+1}\sum_{j<j'}f_i(j,\cdot,\cdot)\ \ \text{(a new run if the last step was down)},\qquad f_{i+1}(j',\text{down},\cdot)=\frac1{i+1}\sum_{j\ge j'}f_i(j,\cdot,\cdot)\ \ \text{(similarly)}. \]

This needs about \(n^3\) operations. For \(n=25\) it returns exactly the mean \(16.333\) and variance \(4.122\) of Theorem 14.6.1 (Figure x14.3).

(b) The \(T_i\) form a 2-dependent stationary sequence: \(T_i\) and \(T_j\) are independent when \(|i-j|\ge3\). Fix a block length \(L\ge3\) and cut \(2,\dots,n-1\) into consecutive stretches of \(L\) indices followed by gaps of 2 indices. The block sums \(S_1,\dots,S_q\) (\(q\approx n/(L+2)\)) use disjoint sets of observations, so they are iid; by the central limit theorem their total, standardised, tends to \(\N(0,1)\). The gap sums are also independent of one another (gaps are \(L\ge3\) apart), each has variance at most 1 (two indicators), so their total has variance at most \(q\), while \(\V W\approx\frac{16n}{90}\approx\frac{16q(L+2)}{90}\). By Chebyshev's inequality the gap part, divided by \(\sqrt{\V W}\), exceeds \(\varepsilon\) with probability at most \(\frac{90}{16(L+2)\varepsilon^2}\) in the limit, which is small for large \(L\), and the block part has limiting variance \(\to1\) as \(L\to\infty\). A standard approximation lemma (Billingsley, 1968, Theorem 4.2) turns "approximately normal for each \(L\), with an error that vanishes as \(L\to\infty\)" into \(W^*\convd\N(0,1)\). This is the central limit theorem for \(m\)-dependent sequences (Hoeffding and Robbins, 1948). ∎

The normal approximation is coarse at the sizes of the case studies because \(W\) takes few values: for \(n=25\) the central bar alone has probability 0.19, so a continuity correction matters (Figure x14.3).

Case Study 14.6.1 pp. 666–667 (strikes 1881–1905). The percentage of successful strikes over 25 years has \(w=18\) runs up and down. \(\E W=\frac{49}3=16.33\) and \(\V W=\frac{371}{90}=4.12\), so \(z=(18-16.33)/2.03=0.82\) (the book rounds \(\E W\) to 16.3 first and prints 0.84); either way \(|z|<1.96\) and randomness is not rejected. The exact two-sided P-value from the recursion (twice the smaller tail) is 0.57. The book's "About the Data" notes a weak negative relation with the number of strikes (slope \(-0.0047\) per strike, P-value 0.047): a test of randomness against runs says nothing about such a relation.

Bar chart of the exact probabilities of 7 to 24 runs up and down for n equal 25, peaking at 16 with probability 0.19, with a red normal curve of mean 16.33 and variance 4.12 drawn over it and a dashed orange line at w equal 18.
Figure x14.3. The exact null law of the number of runs up and down for \(n=25\) (Filling the gap 14.15(a)) with the normal approximation of Theorem 14.6.1 and the observed \(w=18\) of Case Study 14.6.1. The law is discrete and slightly skewed; its mean and variance agree with the theorem. Own figure. Code: ch14_nonparametric_statistics.py, fig_x14_3.

14.7 Taking a Second Look at Statistics (Comparing Parametric and Nonparametric Procedures)

pp. 669–673 Almost every parametric test has a nonparametric analogue: the two-sample \(t\) test and the rank-sum test, the paired \(t\) test and the signed-rank test, the analysis of variance and the Kruskal–Wallis or Friedman test. Which to use depends on (1) the power of each when the parametric assumptions hold and (2) the robustness of each when they fail. If the assumptions hold, the parametric test is best (compare the power curves of Section 6.4); if they fail, the parametric test's actual level and power depend on how robust it is.

The book closes with a Monte Carlo experiment: \(k=4\) groups of \(n_j=5\) observations, analysed by the one-way \(F\) test (3 and 16 degrees of freedom) and by the Kruskal–Wallis test (3 degrees of freedom), each with 100 replications. The figures below repeat it with 10,000 replications.

Histogram of 10,000 F ratios for normal data with H0 true, following closely the curve of the F density with 3 and 16 degrees of freedom; the title reports 4.7 percent above the 0.05 cut-off and 1.1 percent above the 0.01 cut-off.
Figure 14.7.1. \(F\) ratios, normal data, \(H_0\) true: the histogram follows the \(F_{3,16}\) density, and 4.7% of the ratios exceed \(F_{0.95,3,16}=3.24\). Reproduces Larsen and Marx (2018), Figure 14.7.1 (10,000 replications instead of 100). Code: ch14_nonparametric_statistics.py, fig_14_7_1.
Histogram of 10,000 Kruskal-Wallis values for the same normal data sets, against the chi-square density with 3 degrees of freedom; the histogram is jagged because b takes finitely many values, and 3.7 percent exceed 7.815.
Figure 14.7.2. Kruskal–Wallis values for the same data sets against the \(\chi^2_3\) density. The fit is good, slightly short in the tail: only 3.7% exceed \(\chi^2_{0.95,3}=7.815\) and 0.3% exceed \(\chi^2_{0.99,3}=11.345\), so with groups of five the chi-square test is conservative. Reproduces Larsen and Marx (2018), Figure 14.7.2 (10,000 replications). Code: fig_14_7_2.
Histogram of 10,000 Kruskal-Wallis values for exponential data with H0 true, against the chi-square density with 3 degrees of freedom; it looks the same as the previous histogram, with 3.9 percent above 7.815.
Figure 14.7.3. Kruskal–Wallis values for exponential data, \(H_0\) true. The histogram is the same as in Figure 14.7.2 up to simulation noise (3.9% above 7.815), as it must be (Filling the gap 14.16). Reproduces Larsen and Marx (2018), Figure 14.7.3 (10,000 replications). Code: fig_14_7_3.
Histogram of 10,000 F ratios for exponential data with H0 true against the F density with 3 and 16 degrees of freedom; it is more peaked near 0.5 and has a longer right tail than the curve; 4.0 percent exceed the 0.05 cut-off.
Figure 14.7.4. \(F\) ratios for the exponential data sets of Figure 14.7.3. The shape differs from \(F_{3,16}\) (more mass near the centre, a longer far tail), although with equal group sizes the rejection rate at the 0.05 cut-off stays close to nominal (4.0%; 1.0% at 0.01). Reproduces Larsen and Marx (2018), Figure 14.7.4 (10,000 replications). Code: fig_14_7_4.

Filling the gap 14.16: the Kruskal–Wallis null law does not depend on the population at all pp. 671–672, "violates the symmetry assumption underlying the Kruskal-Wallis test"

If all \(n\) observations are iid from any continuous distribution (normal, exponential, Cauchy, ...), the null law of \(B\) is the same: the law of the statistic computed from a uniformly random assignment of the ranks \(1,\dots,n\) to the groups. In particular Figures 14.7.2 and 14.7.3 are two samples from one and the same distribution; exponential data violate no assumption of Theorem 14.4.1, which asks for continuity and a common shape, not symmetry. For \(k=4\), \(n_j=5\), the null probabilities (estimated by Monte Carlo over random rank assignments) are \(P(B\ge7.815)\approx0.038\) and \(P(B\ge11.345)\approx0.0026\).

Hint 1 of 4: the key idea

The statistic is computed from ranks alone. Under \(H_0\), does the law of the rank vector depend on the population?

Hint 2 of 4: tools you will need
Hint 3 of 4: step 1

Argue that the law of \(B\) is the same for normal, exponential or Cauchy data.

Hint 4 of 4: step 2

Estimate \(P(B\ge7.815)\) for four groups of five by random permutations. Aim for: about 0.038, below the nominal 0.05.

Proof

\(B\) is a function of the ranks only, and under \(H_0\) the rank vector is uniform over the \(n!\) permutations whatever the continuous population (Filling the gap 14.1(c)). So the law of \(B\) is computed from the uniform distribution on permutations alone. Only the chi-square approximation of that law introduces any error, and it is the same error for every population. These null probabilities for groups of five were estimated from 200,000 random rank assignments (Monte Carlo standard error about 0.0004); they agree with the rejection rates of the figures, 3.7% to 3.9% and 0.3% (Monte Carlo error about 0.2 points with 10,000 data sets). ∎

Symmetry matters for the signed-rank test (Filling the gap 14.4(a)), not for tests that rank a pooled sample. What matters for Kruskal–Wallis is that under \(H_0\) all groups have the same distribution; if the groups have the same median but different spreads or shapes, \(H_0\) of exchangeability fails and the level is no longer exact.

Under alternatives the comparison changes. In Figures 14.7.5 and 14.7.6 the fourth group is shifted by one standard deviation (normal data, \(\mu_4=1\)). The book reports, from 100 replications, that 26% of the \(b\) values exceed 7.815 and 1% exceed 11.345, against 8% of the \(F\) ratios above \(F_{0.99,3,16}=5.29\). With 10,000 replications: Kruskal–Wallis rejects 20.2% of the time at 0.05 and 2.5% at 0.01; the \(F\) test 25.6% and 8.7%. When normality holds the \(F\) test is more powerful, and the advantage is largest at small \(\alpha\) with small groups, partly because the chi-square approximation makes the Kruskal–Wallis test conservative there (actual size 0.3% at the nominal 1%). These rates are Monte Carlo estimates with standard errors of about 0.4 points; the exact power of the \(F\) test against this alternative (non-central \(F\), non-centrality 3.75) is 27.1% at 0.05 and 9.6% at 0.01, so this run of 10,000 data sets came out a little low.

Histogram of 10,000 Kruskal-Wallis values when the fourth group is shifted by one, spread out to the right of the chi-square density with 3 degrees of freedom; dashed red lines at 7.815 and 11.345; 20.2 percent and 2.5 percent of the values exceed them.
Figure 14.7.5. Kruskal–Wallis values with the fourth mean shifted to 1 (normal data, \(\sigma=1\)): 20.2% exceed 7.815 and 2.5% exceed 11.345. Reproduces Larsen and Marx (2018), Figure 14.7.5 (10,000 replications). Code: fig_14_7_5.
Histogram of 10,000 F ratios for the same shifted data sets, spread to the right of the F density with 3 and 16 degrees of freedom; dashed red lines at 3.24 and 5.29; 25.6 percent and 8.7 percent of the ratios exceed them.
Figure 14.7.6. \(F\) ratios for the same shifted data sets: 25.6% exceed \(F_{0.95,3,16}=3.24\) and 8.7% exceed \(F_{0.99,3,16}=5.29\). Reproduces Larsen and Marx (2018), Figure 14.7.6 (10,000 replications). Code: fig_14_7_6.
▶ DemoThe book's experiment, 4 groups of 5: exponential data under \(H_0\)Preset 4 of the power demo: the histograms of \(B\) and \(F\) side by side, with rejection rates at 0.05 and 0.01. Preset 5 shifts the fourth group by one standard deviation (Figures 14.7.5 and 14.7.6).

How much power does a rank test cost? The book's conclusion is qualitative: nonparametric tests make more Type II errors when the parametric assumptions hold. The classical way to put a number on it is Pitman's asymptotic relative efficiency (ARE): the limiting ratio of the sample sizes two tests need for the same power against the same, ever closer, alternative. It turns out that the price of the Wilcoxon tests is tiny (\(3/\pi=0.955\) for normal data), that of the sign test is larger (\(2/\pi=0.637\)), and that both can win by a wide margin when the tails are heavy (Figure x14.2).

Filling the gap 14.17: local power, Pitman efficiency, and \(\are(\text{sign},t)=2/\pi\) for normal data pp. 638, 670, 672, power comparison of the sign and \(t\) tests

Let \(Y_i=\theta+X_i\), \(X_i\) iid with a density \(f\) symmetric about 0, continuous at 0, with variance \(\sigma^2\). Test \(H_0\colon\theta=0\) against \(\theta>0\) at level \(\alpha\), and look at the alternatives \(\theta_n=h/\sqrt n\) (\(h>0\) fixed). Then

\[ \text{power of the }t\text{ test}\to1-\Phi\Big(z_\alpha-\frac h\sigma\Big),\qquad \text{power of the sign test}\to1-\Phi\big(z_\alpha-2f(0)\,h\big). \]

So to have equal power the sign test needs \(n_S\) and the \(t\) test \(n_t\) observations with \(n_t/n_S\to4f(0)^2\sigma^2\), the asymptotic relative efficiency of the sign test with respect to the \(t\) test. For normal data, \(f(0)=1/(\sigma\sqrt{2\pi})\) and \(\are(\text{sign},t)=2/\pi=0.637\); for the Laplace (double exponential) law it is 2.

Hint 1 of 5: the key idea

At alternatives \(\theta_n=h/\sqrt n\) each standardised statistic tends to a normal with variance 1 and a mean shifted by \(h\) times a constant \(c\). Equal power means equal \(\sqrt n\,c\).

Hint 2 of 5: tools you will need
Hint 3 of 5: step 1

Split \((K-n/2)/\sqrt{n/4}\) into a standardised binomial and a drift. Aim for: drift \(2hf(0)\).

Hint 4 of 5: step 2

Do the same for \(t=\sqrt n\bar Y/S\). Aim for: drift \(h/\sigma\).

Hint 5 of 5: step 3

Equate \(\sqrt{n_1}c_1=\sqrt{n_2}c_2\) and evaluate \(4f(0)^2\sigma^2\) for the normal density. Aim for: \(2/\pi\).

Proof

The sign test. \(K=\#\{Y_i>0\}\sim\Bin(n,p_n)\) with \(p_n=P(X>-\theta_n)=F(\theta_n)\) by symmetry, so \(p_n=\frac12+\theta_nf(0)+o(\theta_n)\) and \(2\sqrt n(p_n-\frac12)\to2hf(0)\). Write

\[ \frac{K-n/2}{\sqrt{n/4}}=\frac{K-np_n}{\sqrt{np_n(1-p_n)}}\cdot\sqrt{4p_n(1-p_n)}+2\sqrt n\big(p_n-\tfrac12\big). \]

The first factor tends to \(\N(0,1)\): the moment-generating function proof of the De Moivre–Laplace theorem (Filling the gap 4.9) goes through unchanged when \(p\) varies with \(n\) inside \([\frac14,\frac34]\), because its Taylor remainders are bounded uniformly there. The second factor tends to 1 and the last term to \(2hf(0)\). So the statistic tends to \(\N(2hf(0),1)\), and the rule "reject if it exceeds \(z_\alpha\)" (which has asymptotic level \(\alpha\) under \(H_0\)) has power \(\to P(Z+2hf(0)>z_\alpha)=1-\Phi(z_\alpha-2hf(0))\).

The \(t\) test. \(t=\frac{\sqrt n\bar Y}{S}=\frac{\sqrt n\bar X}{S}+\frac{h}{S}\). The sample mean of the \(X\)'s obeys the central limit theorem and \(S\convp\sigma\) (the \(X\)'s do not depend on \(n\)), so by Slutsky's theorem \(t\convd\N(h/\sigma,1)\), and \(t_{\alpha,n-1}\to z_\alpha\): power \(\to1-\Phi(z_\alpha-h/\sigma)\).

Efficiency. At a fixed small alternative \(\theta\), a test whose statistic drifts by \(\sqrt n\,\theta\,c\) has power about \(1-\Phi(z_\alpha-\sqrt n\theta c)\). Equal power for two tests means \(\sqrt{n_1}c_1=\sqrt{n_2}c_2\), i.e. \(n_2/n_1=c_1^2/c_2^2\). With \(c_S=2f(0)\) and \(c_t=1/\sigma\), \(n_t/n_S\to4f(0)^2\sigma^2\). For \(\N(0,\sigma^2)\), \(4f(0)^2\sigma^2=4\sigma^2/(2\pi\sigma^2)=2/\pi\); for the Laplace density \(\frac1{2\beta}e^{-|x|/\beta}\), \(f(0)=\frac1{2\beta}\), \(\sigma^2=2\beta^2\) and the ratio is 2. ∎

This is the same number as the efficiency of the sample median against the sample mean as estimators (graduate Filling the gap 9.11): the sign test is the test that goes with the median.

Filling the gap 14.18: the Wilcoxon efficiency \(12\sigma^2\big(\int f^2\big)^2\), the value \(3/\pi\), and the Hodges–Lehmann bound 0.864 pp. 670, 672; Question 14.3.7

In the setting of Filling the gap 14.17, the signed-rank test has local power \(1-\Phi\big(z_\alpha-\sqrt{12}\,h\int f^2\big)\), so

\[ \are(\text{signed rank},t)=12\,\sigma^2\Big(\int_{-\infty}^\infty f(x)^2\,\d x\Big)^2,\qquad \are(\text{sign},\text{signed rank})=\frac{f(0)^2}{3\big(\int f^2\big)^2}. \]

For normal data \(\int f^2=1/(2\sigma\sqrt\pi)\) and the efficiency is \(3/\pi=0.955\). For every symmetric density with finite variance it is at least \(108/125=0.864\) (Hodges and Lehmann, 1956), and it is unbounded above (infinite for Cauchy data, where the \(t\) test fails). The same efficiency holds for the rank-sum test against the two-sample \(t\) test and for Kruskal–Wallis against the \(F\) test.

Hint 1 of 6: the key idea

Write \(W\) as a count of pairs \(i\le j\) with \(D_i+D_j>0\); then its mean under a shift is easy to differentiate. For the lower bound, compare \(f\) with a parabola.

Hint 2 of 6: tools you will need
  • The density of \(X_1+X_2\) at 0 is \(\int f^2\) for symmetric \(f\).
  • \(\V_0W\approx n^3/12\).
  • \(\int(f-q)^2\ge0\), then optimise over \(\lambda\) and \(c\).
Hint 3 of 6: step 1

Prove the pair-count form by looking at which member of a pair has the larger absolute value.

Hint 4 of 6: step 2

Differentiate \(\E_\theta W=nF(\theta)+\binom n2H(2\theta)\) at 0. Aim for: \(n^2\int f^2\) to leading order, so \(c_W=\sqrt{12}\int f^2\).

Hint 5 of 6: step 3

Compute \(\int f^2\) for \(\N(0,\sigma^2)\). Aim for: \(1/(2\sigma\sqrt\pi)\) and \(3/\pi\).

Hint 6 of 6: step 4

With \(\sigma=1\), show \(\int f^2\ge2\lambda(c^2-1)-\frac{16c^5}{15}\lambda^2\) and optimise. Aim for: \(c^2=5\) and the bound \(108/125\).

Proof

A pair-count form of \(W\). Let \(D_i=Y_i\). For \(i\ne j\), \(D_i+D_j>0\) exactly when the one with the larger absolute value is positive. So a positive \(D_i\) of rank \(r_i\) makes \(D_i+D_j>0\) with each of the \(r_i-1\) observations of smaller absolute value, and with itself (\(2D_i>0\)); a negative one with none of them. Counting pairs \(i\le j\) by their larger member,

\[ W=\sum_{i\le j}\one\{D_i+D_j>0\}. \]

The drift. Hence \(\E_\theta W=n\,P(D_1>0)+\binom n2P(D_1+D_2>0)\). Now \(P(D_1>0)=F(\theta)\) and \(P(D_1+D_2>0)=P(X_1+X_2>-2\theta)=H(2\theta)\), where \(H\) is the cdf of \(X_1+X_2\), whose density at 0 is \(\int f(x)f(-x)\,\d x=\int f^2\) by symmetry. Differentiating at 0,

\[ \frac{\d}{\d\theta}\E_\theta W\Big|_{\theta=0}=nf(0)+\binom n2\cdot2\int f^2=n^2\int f^2\,(1+o(1)). \]

Since \(\V_0W=\frac{n(n+1)(2n+1)}{24}=\frac{n^3}{12}(1+o(1))\), the standardised statistic drifts by \(\theta_n\cdot n^2\int f^2\big/\sqrt{n^3/12}=h\sqrt{12}\int f^2\). That the standardised statistic is still asymptotically normal with variance 1 under \(\theta_n\) follows from the projection method of Filling the gap 14.9 applied to the pair count (Hoeffding, 1948); we take this step for granted. So \(c_W=\sqrt{12}\int f^2\), and with \(c_t=1/\sigma\) and \(c_S=2f(0)\) from Filling the gap 14.17 the two ratios follow. For \(\N(0,\sigma^2)\), \(\int f^2=\frac1{2\pi\sigma^2}\int e^{-x^2/\sigma^2}\d x=\frac{\sqrt\pi\sigma}{2\pi\sigma^2}=\frac1{2\sigma\sqrt\pi}\), so \(12\sigma^2(\int f^2)^2=\frac{12}{4\pi}=\frac3\pi\).

The lower bound. Scale so that \(\sigma^2=1\). For \(\lambda>0\) and \(c>0\) let \(q(x)=\lambda(c^2-x^2)^+\). Since \(\int(f-q)^2\ge0\) and \((c^2-x^2)^+\ge c^2-x^2\),

\[ \int f^2\ \ge\ 2\int fq-\int q^2\ \ge\ 2\lambda\int f(x)(c^2-x^2)\,\d x-\lambda^2\int_{-c}^c(c^2-x^2)^2\d x=2\lambda(c^2-1)-\frac{16c^5}{15}\lambda^2. \]

The best \(\lambda\) is \(\frac{15(c^2-1)}{16c^5}\), giving \(\int f^2\ge\frac{15(c^2-1)^2}{16c^5}\), and the best \(c\) is \(c^2=5\), giving \(\int f^2\ge\frac{15\cdot16}{16\cdot5^{5/2}}=\frac3{5\sqrt5}\). Hence \(12(\int f^2)^2\ge12\cdot\frac9{125}=\frac{108}{125}=0.864\), with equality for the parabolic density \(f=q\) (with \(c=\sqrt5\)). ∎

population (variance 1)\(f(0)\)\(\int f^2\)sign vs \(t\)signed rank vs \(t\)sign vs signed rank
uniform0.2890.2890.3331.0000.333
normal0.3990.2820.637 (\(2/\pi\))0.955 (\(3/\pi\))0.667
logistic0.4530.3020.8221.0970.750
Laplace0.7070.3542.0001.5001.333
\(t\), 3 df0.6370.3981.6211.9000.853
Cauchy (no variance)  \(\infty\)\(\infty\)1.333

So the signed-rank test is not always more powerful than the sign test: for Laplace and Cauchy data the sign test needs only 3/4 of the observations (see Question 14.3.7).

Three panels of power against the shift theta from 0 to 1 for n equal 20: blue t test, red sign test, green signed-rank test, dots from simulation and curves from the asymptotic formula. Normal data: t and signed rank nearly coincide, the sign test is lower. Laplace data: the sign and signed-rank tests beat the t test. Uniform data: the t and signed-rank tests coincide and the sign test is far lower.
Figure x14.2. Power of the one-sided \(t\), sign and signed-rank tests of exact size 0.05 for \(n=20\) observations from a symmetric population with variance 1 shifted by \(\theta\) (dots: 20,000 simulated samples per point; the sign and signed-rank tests are randomised at the boundary so that every test has size exactly 0.05). Curves: the local power \(1-\Phi(z_{0.05}-\sqrt n\,\theta\,c)\) of Filling the gaps 14.17 and 14.18. The panel titles give the efficiencies. Own figure. Code: ch14_nonparametric_statistics.py, fig_x14_2.
▶ DemoSign, signed rank or \(t\): power curves and efficiencyPreset 1 of the power demo: normal data, \(n=20\); preset 2: Laplace data, where the sign test wins; preset 3: Cauchy data, where the \(t\) test fails. Choose the population, \(n\) and the shift yourself.

The book's conclusion stands, with numbers attached: if the parametric assumptions are believable, use the parametric test; if not, the Wilcoxon and Kruskal–Wallis tests cost at most about 14% of the sample size and nothing like the sign test's 36% under normality, and they keep their level exactly. The chapter-opening figure of the book shows the same comparison for the sign test at \(n=10\) for some non-normal populations.

See also (companion courses): the graduate course's efficiency demo (preset 1: mean against median for normal data, the estimation side of \(2/\pi\)); this course's \(t\) test robustness demo (Section 7.4: how far the \(t\) test's level moves for non-normal data); Statistical Methods for Modern Biology, Exercise 13.1 (Wilcoxon against Welch by simulation).

Notes on the book

The paired sign test does not test equal medians p. 642

The book says that the hypothesis that \(X_i\) and \(Y_i\) have the same median "is equivalent to" \(H_0\colon p=P(X_i>Y_i)=\frac12\). It is not: \(X\sim\Unif(0,2)\) and an independent exponential \(Y\) with median 1 have equal medians but \(P(X>Y)=1-3/(8\ln2)=0.459\) (Filling the gap 14.3). The test concerns the median of the differences, which is 0 exactly when \(p=\frac12\), for example when the pair is exchangeable.

The signed-rank test is about the centre of symmetry, not the mean pp. 645–650

Section 14.3 states the hypotheses in terms of "the (common) mean \(\mu\)" of symmetric densities, then recommends the test in Case Study 14.3.1 because the data might be Cauchy-like, a law without a mean. The test needs only symmetry about \(\mu_0\) (Filling the gap 14.4), so \(\mu\) should be read as the centre of symmetry (the median), which exists for every symmetric law.

Theorem 14.6.1(b) fails for \(n=3\) p. 666

The theorem is stated for \(n>2\). For \(n=3\), \(W\) is 1 or 2 with probabilities \(\frac13\) and \(\frac23\), so \(\V W=\frac29=\frac{20}{90}\), while \((16n-29)/90=\frac{19}{90}\). The variance formula holds for \(n\ge4\) (Filling the gap 14.14); the mean formula holds for all \(n\ge2\).

Exponential data violate no assumption of the Kruskal–Wallis test pp. 671–672

The book calls the exponential law of Figure 14.7.3 "a sharply skewed pdf that violates the symmetry assumption underlying the Kruskal-Wallis test" and finds the histogram "not much different" from Figure 14.7.2. Theorem 14.4.1 assumes no symmetry, and under \(H_0\) the null law of \(B\) is identical for every continuous population, so the two histograms differ only by simulation noise (Filling the gap 14.16).

The signed-rank test is not always more powerful than the sign test p. 658 and the answer to Question 14.3.7

The book's answer to Question 14.3.7 says the signed-rank test "should have more power since it uses more of the information in the data". For normal data it does (asymptotic efficiency of the sign test relative to the signed-rank test 2/3), but for the Laplace and Cauchy laws the sign test is the more efficient one (4/3), and for any symmetric law the ratio is \(f(0)^2/(3(\int f^2)^2)\) (Filling the gap 14.18).

Smaller slips pp. 647, 653, 656, 660–661, 667, 672–673

(1) Proof of Theorem 14.3.1: the sums \(\sum_wp_W(w)e^{wt}\) start at \(w=0\), not \(w=1\). (2) Paired signed-rank test: the text uses Table A.6 "if \(n<12\)" and the normal approximation "if \(n>12\)", leaving out \(n=12\), which Table A.6 covers. (3) Case Study 14.3.4 refers to "the formulas in Theorem 14.3.3" for the rank-sum moments; they are in Theorem 14.3.4. (4) Case Study 14.6.1: with \(\E W=16.33\) unrounded, \(z=0.82\) (printed 0.84). (5) Case Study 14.4.1: "more than 11 standard deviations away from its mean" treats \(\chi^2_1\) as if it were normal; the P-value \(4.0\times10^{-5}\) is the right measure. (6) Section 14.7: the percentages come from 100 replications and carry a standard error of about 4 points at 26%; with 10,000 replications the Kruskal–Wallis power is 20.2% at 0.05 and 2.5% (not 1%) at 0.01, which is eight times its null rate of 0.3%, not "the same percentage expected if \(H_0\) were true". None changes a conclusion.

Selected questions

Twelve of the book's questions, restated in my own words and covering Sections 14.2 to 14.6, with complete solutions (hidden). Numbers were cross-checked with the book's answers to the odd-numbered questions.

  1. Question 14.2.4 (the power of a sign test). \(Y_1,\dots,Y_{22}\) are normal with unknown mean \(\mu\) and known variance 6. Construct a large-sample sign test of \(H_0\colon\mu=10\) against \(H_1\colon\mu>10\) with Type I error probability 0.05. What is its power when \(\mu=11\)?

    Hint 1 of 5: the key idea

    For a normal population the median is \(\mu\), so a sign test applies. Its power at \(\mu=11\) is a binomial tail with a new success probability.

    Hint 2 of 5: tools you will need
    • Theorem 14.2.1.
    • \(P(Y>10)\) for \(\N(11,6)\).
    • The normal approximation to the binomial.
    Hint 3 of 5: step 1

    Find the integer rejection rule. Aim for: reject when \(K\ge15\).

    Hint 4 of 5: step 2

    Compute \(p=P(Y>10)\) when \(\mu=11\). Aim for: \(p\approx0.658\).

    Hint 5 of 5: step 3

    Evaluate \(P(K\ge14.86)\) for \(\Bin(22,p)\) by the normal approximation, and compare with the \(z\) test's power.

    Solution

    For a normal population the median is \(\mu\), so test \(\tilde\mu=10\) with \(K=\#\{Y_i>10\}\). By Theorem 14.2.1 reject if \((K-11)/\sqrt{5.5}\ge1.645\), i.e. \(K\ge11+1.645\sqrt{5.5}=14.86\), so reject when \(K\ge15\). (Its exact size is \(P(K\ge15)=0.067\) for \(\Bin(22,\frac12)\): the normal approximation is a little generous, Filling the gap 14.2.)

    If \(\mu=11\), each observation exceeds 10 with probability \(p=P(Z>-1/\sqrt6)=\Phi(0.408)=0.6585\), so \(K\sim\Bin(22,0.6585)\). By the normal approximation, with mean \(14.49\) and standard deviation \(\sqrt{22\cdot0.6585\cdot0.3415}=2.225\),

    \[ \text{power}=P(K\ge14.86)\approx1-\Phi\Big(\frac{14.86-14.49}{2.225}\Big)=1-\Phi(0.17)=0.43. \]

    The exact binomial power is \(P(K\ge15)=0.51\). For comparison the \(z\) test that uses the known variance has power \(\Phi(\sqrt{22/6}-1.645)=\Phi(0.27)=0.61\): the sign test throws away the sizes of the deviations and pays for it (asymptotic efficiency \(2/\pi\), Filling the gap 14.17).

  2. Question 14.2.5 (the whole null law for seven pairs). For \(n=7\) pairs \((X_i,Y_i)\) let \(Y_+\) be the number of positive differences \(Y_i-X_i\). Give the distribution of \(Y_+\) when \(p=P(Y_i>X_i)=\frac12\), and list the levels available for testing \(H_0\colon p=\frac12\) against \(H_1\colon p>\frac12\).

    Hint 1 of 4: the key idea

    Under \(H_0\) each difference is positive with probability \(\frac12\), independently: \(Y_+\) is binomial. A one-sided test can only reject on upper tails.

    Hint 2 of 4: tools you will need
    • \(\Bin(7,\frac12)\): \(\binom7y/128\).
    • Achievable levels are cumulative upper tails.
    Hint 3 of 4: step 1

    Write the eight probabilities. Aim for: 1, 7, 21, 35, 35, 21, 7, 1 over 128.

    Hint 4 of 4: step 2

    Accumulate from the top. Aim for: levels \(1/128,8/128,29/128,\dots\)

    Solution

    Under \(H_0\), \(Y_+\sim\Bin(7,\frac12)\): \(P(Y_+=y)=\binom7y/128\), i.e.

    \(y\)01234567
    \(128\,P(Y_+=y)\)172135352171

    A one-sided test rejects for large \(Y_+\), so its region is \(\{Y_+\ge c\}\) and its level is \(P(Y_+\ge c)\): \(\frac1{128}=0.0078\) (\(c=7\)), \(\frac8{128}=0.0625\) (\(c=6\)), \(\frac{29}{128}=0.227\) (\(c=5\)), \(\frac{64}{128}=0.5\) (\(c=4\)), and so on. No non-randomised test has level 0.05: one must choose 0.0078 or 0.0625 (or randomise at \(Y_+=6\)).

  3. Question 14.2.9 (razor blades). Twenty-eight men each shaved one side of the face with blade A and the other with blade B for a week; 19 preferred A. At level 0.05, is the difference in preference significant?

    Hint 1 of 4: the key idea

    Each man is a pair; preferring A is a 'plus'. Under no difference, the count of A preferences is \(\Bin(28,\frac12)\).

    Hint 2 of 4: tools you will need
    • The paired sign test of Section 14.2.
    • Two-sided \(z\) rule with \(z_{0.025}=1.96\).
    Hint 3 of 4: step 1

    Compute \(z=(19-14)/\sqrt{7}\). Aim for: about 1.89.

    Hint 4 of 4: step 2

    Compare with 1.96, and check the exact binomial P-value \(2P(X\ge19)\).

    Solution

    Let \(p\) be the probability that a man prefers A; test \(H_0\colon p=\frac12\) against \(H_1\colon p\ne\frac12\) with the paired sign test (each man is a pair). \(z=(19-14)/\sqrt{28/4}=5/\sqrt7=1.89\), and \(|z|<1.96\): do not reject (book: 1.89). The two-sided P-value is 0.059 by the normal approximation and \(2P(X\ge19)=0.087\) exactly for \(\Bin(28,\frac12)\). The data suggest a preference for A but do not establish it at the 5% level.

  4. Question 14.2.10 (a sign test for a percentile). A sample of 36 is drawn from \(\Unif(0,\theta)\), \(\theta\) unknown. Set up a large-sample sign test of whether the 25th percentile is 6, at \(\alpha=0.05\). What is the probability of a Type II error if the true 25th percentile is 7?

    Hint 1 of 5: the key idea

    The sign test works for any percentile: count observations below 6, which is \(\Bin(36,\frac14)\) if 6 is the 25th percentile.

    Hint 2 of 5: tools you will need
    • Mean and variance of \(\Bin(36,\frac14)\).
    • The uniform cdf on \((0,\theta)\).
    • The normal approximation to a binomial.
    Hint 3 of 5: step 1

    Set up the two-sided rule. Aim for: reject if \(X\le3\) or \(X\ge15\).

    Hint 4 of 5: step 2

    If the 25th percentile is 7, find \(\theta\) and \(P(Y<6)\). Aim for: \(\theta=28\), \(p=3/14\).

    Hint 5 of 5: step 3

    Compute the probability of landing in the acceptance region under the new \(p\). Aim for: about 0.93.

    Solution

    The sign test works for any percentile: if the 25th percentile is \(\xi_0=6\), each observation falls below 6 with probability \(\frac14\), so \(X=\#\{Y_i<6\}\sim\Bin(36,\frac14)\), with mean 9 and variance \(36\cdot\frac14\cdot\frac34=6.75\). For a two-sided test reject if \(|X-9|/\sqrt{6.75}\ge1.96\), i.e. \(X\le9-5.09=3.91\) or \(X\ge14.09\): reject when \(X\le3\) or \(X\ge15\) (exact size 0.032).

    If the 25th percentile is 7, then \(\theta/4=7\), \(\theta=28\), and \(P(Y<6)=6/28=\frac3{14}=0.214\). Now \(X\sim\Bin(36,0.214)\) with mean 7.71 and standard deviation 2.46, and

    \[ \beta=P(3.91<X<14.09)\approx\Phi\Big(\frac{14.09-7.71}{2.46}\Big)-\Phi\Big(\frac{3.91-7.71}{2.46}\Big)=\Phi(2.59)-\Phi(-1.55)=0.93. \]

    The exact binomial value is \(P(4\le X\le14)=0.96\). A change of the percentile from 6 to 7 shifts \(P(Y<6)\) only from 0.25 to 0.21, which 36 observations can hardly detect.

  5. Question 14.3.1 (energy expenditure, summer and winter). Eight elderly women had average daily energy expenditures (kcal) of 1458, 1353, 2209, 1804, 1912, 1366, 1598, 1406 in summer and 1424, 1501, 1495, 1739, 2031, 934, 1401, 1339 in winter. With \(\mu_D\) the location difference, use the signed-rank test on \(d_i=y_i-x_i\) (winter minus summer) to test \(H_0\colon\mu_D=0\) against \(\mu_D\ne0\) at \(\alpha=0.15\).

    Hint 1 of 4: the key idea

    Rank the absolute differences, add the ranks of the positive ones, and compare with the exact critical values for \(n=8\).

    Hint 2 of 4: tools you will need
    Hint 3 of 4: step 1

    Compute \(d_i=y_i-x_i\) and rank \(|d_i|\). Aim for: \(w=9\).

    Hint 4 of 4: step 2

    Find the largest \(w^*\) with \(P(W\le w^*)\le0.075\). Aim for: \(w^*=7\), level 0.148.

    Solution

    The differences are \(-34,\ 148,\ -714,\ -65,\ 119,\ -432,\ -197,\ -67\). Ranking the absolute values: 34 (1), 65 (2), 67 (3), 119 (4), 148 (5), 197 (6), 432 (7), 714 (8). The positive differences, 148 and 119, have ranks 5 and 4, so \(w=9\).

    For \(n=8\) the generating function gives \(c_8(0),\dots,c_8(7)=1,1,1,2,2,3,4,5\), so \(P(W\le7)=19/256=0.074\) and \(P(W\le8)=25/256=0.098\). The two-sided region with level at most 0.15 is \(\{w\le7\text{ or }w\ge29\}\) (\(36-7=29\)), of level \(0.148\). Since \(w=9\) is not in it, do not reject (book: critical values 7 and 29, \(\alpha=0.148\)). Most women spent more energy in summer, but the evidence is weak with eight subjects.

  6. Question 14.3.2 (the law of \(W\) for \(n=5\)). Expand \(\prod_{i=1}^5(1+e^{it})\) to find the distribution of \(W\) for \(n=5\). Which levels are available for \(H_0\colon\tilde\mu=\tilde\mu_0\) against \(\tilde\mu>\tilde\mu_0\)?

    Hint 1 of 4: the key idea

    Multiply in one factor \((1+x^i)\) at a time, or use the recursion from the \(n=4\) coefficients.

    Hint 2 of 4: tools you will need
    • \(c_4=(1,1,1,2,2,2,2,2,1,1,1)\).
    • \(c_5(w)=c_4(w)+c_4(w-5)\).
    Hint 3 of 4: step 1

    Build \(c_5\). Aim for: 16 coefficients adding to 32, symmetric about 7.5.

    Hint 4 of 4: step 2

    Accumulate from \(w=15\) downward to list the upper-tail levels.

    Solution

    Multiply in the factors one at a time, or use the recursion \(c_5(w)=c_4(w)+c_4(w-5)\) with \(c_4=(1,1,1,2,2,2,2,2,1,1,1)\) on \(w=0,\dots,10\) (Filling the gap 14.5):

    \(w\)0123456789101112131415
    \(32\,p_W(w)\)1112233333322111

    The counts add to 32 and are symmetric about 7.5. For the upper-tailed test the region is \(\{W\ge c\}\), with levels \(P(W\ge15)=\frac1{32}=0.031\), \(P(W\ge14)=\frac2{32}=0.063\), \(P(W\ge13)=\frac3{32}=0.094\), \(P(W\ge12)=\frac5{32}=0.156\), \(P(W\ge11)=\frac7{32}=0.219\), and so on. With five observations a 0.05 test can only reject when all five deviations are positive.

  7. Question 14.3.3 (annealing temperatures). Fifteen pieces of copper tubing were each cut in two; one half was annealed at a moderate temperature and the other at a high temperature. The tensile strengths (moderate, high) were (16.5, 16.9), (17.6, 17.2), (16.9, 17.0), (15.8, 16.1), (18.4, 18.2), (17.5, 17.7), (17.6, 17.9), (16.1, 16.0), (16.8, 17.3), (15.8, 16.1), (16.8, 16.5), (17.3, 17.6), (18.1, 18.4), (17.9, 17.2), (16.4, 16.5). Analyse the data with a two-sided signed-rank test at \(\alpha=0.05\).

    Hint 1 of 4: the key idea

    Paired data: apply the signed-rank test to the differences, with midranks for the many ties, and use the large-sample \(z\) since \(n=15\).

    Hint 2 of 4: tools you will need
    Hint 3 of 4: step 1

    Compute the 15 differences and their midranks. Aim for: the five positive ones have ranks summing to 42.5.

    Hint 4 of 4: step 2

    Standardise with mean 60 and variance 310 (or the tie-corrected variance). Aim for: \(z\approx-1.0\).

    Solution

    The differences moderate minus high are \(-0.4,\,0.4,\,-0.1,\,-0.3,\,0.2,\,-0.2,\,-0.3,\,0.1,\,-0.5,\,-0.3,\,0.3,\,-0.3,\,-0.3,\,0.7,\,-0.1\), with many ties in absolute value: 0.1 (three times, midrank 2), 0.2 (twice, 4.5), 0.3 (six times, 8.5), 0.4 (twice, 12.5), 0.5 (14), 0.7 (15). The positive differences 0.4, 0.2, 0.1, 0.3, 0.7 have ranks 12.5, 4.5, 2, 8.5, 15, so \(w=42.5\).

    With \(n=15\), \(\E W=60\) and \(\V W=310\), so \(z=(42.5-60)/\sqrt{310}=-0.99\) (book: 0.99, computed from the negative differences). With the tie correction of Filling the gap 14.7, \(\sum(t^3-t)=24+6+210+6=246\), \(\V W=310-246/48=304.9\) and \(z=-1.00\). Either way \(|z|<1.96\): do not reject. The exact conditional two-sided P-value is 0.34. The annealing temperature has no demonstrable effect on tensile strength.

  8. Question 14.3.7 (sign or signed rank?). The population is symmetric and we test \(H_0\colon\tilde\mu=\tilde\mu_0\). Both the sign test and the signed-rank test are valid. Which would you expect to be more powerful, and why?

    Hint 1 of 4: the key idea

    'Uses more information' is not a proof. Compare the asymptotic efficiencies of the two tests: they depend on the shape of the density.

    Hint 2 of 4: tools you will need
    Hint 3 of 4: step 1

    Evaluate the ratio for normal data. Aim for: 2/3.

    Hint 4 of 4: step 2

    Evaluate it for the Laplace density. Aim for: 4/3. What feature of the density makes the sign test win?

    Solution

    The signed-rank test uses the sizes of the deviations as well as their signs, so for most populations one expects it to be more powerful, and for normal data it is: by Filling the gap 14.18 the sign test needs about \(1/(2/3)=1.5\) times as many observations to match it. But it is not true in general. The efficiency of the sign test relative to the signed-rank test is \(f(0)^2/\big(3(\int f^2)^2\big)\), which depends on the population: 1/3 for uniform data, 2/3 for normal, 3/4 for logistic, but 4/3 for Laplace and for Cauchy data. When the density has a sharp peak at the centre and heavy tails, large deviations carry little information about the centre, and counting signs is better than ranking sizes. (The book's answer, "the signed rank test should have more power since it uses more of the information in the data", holds for light and moderate tails only.) The power demo (preset 2) shows the Laplace case.

  9. Question 14.4.6 (light bulbs from three plants). Ten 40-W bulbs from each of three plants burned for (hours) Plant 1: 905, 1018, 905, 886, 958, 1056, 904, 856, 1070, 1006; Plant 2: 1109, 1155, 835, 1152, 1036, 926, 1029, 1040, 959, 996; Plant 3: 571, 1346, 292, 825, 676, 541, 818, 90, 2246, 104. (a) Test at 0.05 that the median lives are equal (Kruskal–Wallis). (b) Test that the mean lives are equal by the analysis of variance at 0.05. (c), (d) Change 2246 to 1500 and redo (a) and (b). What do you learn?

    Hint 1 of 5: the key idea

    Ranks do not care how extreme the largest value is; the analysis of variance does, through the error sum of squares.

    Hint 2 of 5: tools you will need
    Hint 3 of 5: part (a)

    Rank all 30 lives (two tied at 905). Aim for: rank sums 164, 206, 95 and \(b\approx8.11\).

    Hint 4 of 5: part (b)

    Compute the \(F\) ratio. Aim for: \(F\approx1.40\), below 3.35.

    Hint 5 of 5: parts (c), (d)

    Does changing 2246 to 1500 change any rank? Recompute \(F\). Aim for: \(F\approx4.24\).

    Solution

    (a) Ranking all 30 lives (the two 905's share rank 13.5) gives rank sums \(R_{\cdot1}=164\), \(R_{\cdot2}=206\), \(R_{\cdot3}=95\), and

    \[ b=\frac{12}{30\cdot31}\cdot\frac{164^2+206^2+95^2}{10}-3\cdot31=8.11\ \ge\ \chi^2_{0.95,2}=5.991, \]

    so reject \(H_0\) (P-value 0.017; the tie correction changes \(b\) only in the third decimal). Plant 3's bulbs tend to fail sooner.

    (b) The means are 956.4, 1023.7 and 750.9 hours, and the analysis of variance gives \(F=1.40\) on 2 and 27 degrees of freedom, below \(F_{0.95,2,27}=3.35\) (P-value 0.26): do not reject.

    (c) 1500 is still the largest of the 30 values, so every rank is unchanged and \(b=8.11\): reject, as before.

    (d) The third mean becomes 676.3 and \(F=4.24>3.35\) (P-value 0.025): now reject. The single bulb that lasted 2246 hours inflated the within-plant variability so much that the \(F\) test could not see the obvious difference between Plant 3 and the others; pulling it in to 1500 reverses the conclusion. The rank test saw the same thing both times. This is the robustness argument of Section 14.7 in one example: the \(F\) test's power is fragile to one wild value, the ranks are not.

  10. Question 14.4.8 (another form of \(B\)). Show that the Kruskal–Wallis statistic can be written

    \[ B=\sum_{j=1}^k\frac{n-n_j}n\,Z_j^2,\qquad Z_j=\frac{\bar R_j-\frac{n+1}2}{\sqrt{(n+1)(n-n_j)/(12n_j)}},\quad\bar R_j=\frac{R_{\cdot j}}{n_j}. \]
    Hint 1 of 4: the key idea

    \(Z_j\) is the standardised mean rank of group \(j\). Substitute it and compare with the sum-of-squares form of \(B\).

    Hint 2 of 4: tools you will need
    Hint 3 of 4: step 1

    Simplify \(\frac{n-n_j}nZ_j^2\). Aim for: \(\frac{12}{n(n+1)}n_j(\bar R_j-\frac{n+1}2)^2\).

    Hint 4 of 4: step 2

    Sum over \(j\) and use Filling the gap 14.10(a).

    Solution

    By Filling the gap 14.10(b), \(Z_j\) is \(\bar R_j\) standardised by its exact null mean and standard deviation. Substituting the definition,

    \[ \frac{n-n_j}n\,Z_j^2=\frac{n-n_j}n\cdot\frac{12n_j}{(n+1)(n-n_j)}\Big(\bar R_j-\frac{n+1}2\Big)^2=\frac{12}{n(n+1)}\,n_j\Big(\bar R_j-\frac{n+1}2\Big)^2. \]

    Summing over \(j\) and using Filling the gap 14.10(a), \(\sum_j\frac{n-n_j}nZ_j^2=\frac{12}{n(n+1)}\sum_jn_j(\bar R_j-\frac{n+1}2)^2=B\). The weights \(\frac{n-n_j}n\) add up to \(k-1\), and each \(Z_j^2\) has mean 1, which is another way to see \(\E B=k-1\). The \(Z_j\) are not independent (the weighted \(\bar R_j\) add to a constant); that dependence is what removes one degree of freedom in Filling the gap 14.11.

  11. Question 14.5.3 (three methods for sodium cyclamate). Three laboratory methods (picryl chloride, Davies, AOAC) measured the percentage of sodium cyclamate in each of 12 samples of orange drink:

    samplepicryl chlorideDaviesAOAC
    10.5980.6280.632
    20.6140.6280.630
    30.6000.6000.622
    40.5800.6120.584
    50.5960.6000.650
    60.5920.6280.606
    70.6160.6280.644
    80.6140.6440.644
    90.6040.6440.624
    100.6080.6120.619
    110.6020.6280.632
    120.6140.6440.616

    Use Friedman's test at \(\alpha=0.05\) to decide whether the methods differ.

    Hint 1 of 4: the key idea

    The samples are blocks and the methods are treatments: rank the three readings within each sample.

    Hint 2 of 4: tools you will need
    Hint 3 of 4: step 1

    Find the three rank sums. Aim for: 12.5, 28, 31.5 (total 72).

    Hint 4 of 4: step 2

    Compute \(g\) and compare with \(\chi^2_{0.95,2}=5.991\). Aim for: \(g\approx17.0\).

    Solution

    The samples are the blocks (\(b=12\)) and the methods the treatments (\(k=3\)). Ranking within each sample, with midranks for the ties in samples 3 (0.600, 0.600) and 8 (0.644, 0.644), gives rank sums \(r_{\cdot1}=12.5\) (picryl), \(r_{\cdot2}=28\) (Davies), \(r_{\cdot3}=31.5\) (AOAC), which add to \(12\cdot6=72\). Then

    \[ g=\frac{12}{12\cdot3\cdot4}\big(12.5^2+28^2+31.5^2\big)-3\cdot12\cdot4=17.04\ \ge\ \chi^2_{0.95,2}=5.991, \]

    so reject \(H_0\) (book: 17.0; P-value 0.0002). With the tie correction \(1-\sum(t^3-t)/(b(k^3-k))=1-12/288\), \(g=17.78\). The picryl chloride method reads systematically lower: it ranked strictly lowest in 11 of the 12 samples and tied for lowest in the other.

  12. Question 14.6.5 (are forty simulated normals random?). Forty computer-generated values, supposedly a random sample from \(\N(5,2^2)\), are listed in time order in the book (7.0680, 4.0540, 6.6165, 1.2166, ..., 5.0209, 0.5544). Test their randomness with the number of runs up and down at \(\alpha=0.05\).

    Hint 1 of 4: the key idea

    Write the signs of the 39 successive differences and count the blocks of equal signs.

    Hint 2 of 4: tools you will need
    Hint 3 of 4: step 1

    Count the runs up and down. Aim for: \(w=25\).

    Hint 4 of 4: step 2

    Standardise with mean \(79/3\) and variance \(611/90\). Aim for: \(z\approx-0.51\).

    Solution

    Writing the signs of the 39 successive differences and counting the runs gives \(w=25\). By Theorem 14.6.1 with \(n=40\), \(\E W=\frac{79}3=26.33\) and \(\V W=\frac{16\cdot40-29}{90}=\frac{611}{90}=6.79\), so

    \[ z=\frac{25-26.33}{\sqrt{6.79}}=-0.51, \]

    inside \((-1.96,1.96)\): do not reject randomness (book: \(w=25\), \(z=-0.51\)). The exact two-sided P-value from the recursion of Filling the gap 14.15 is 0.75 (twice the smaller tail; 0.61 by the normal curve without a continuity correction). Of course a runs test checks only one kind of departure: a generator could pass it and still fail other tests.

Demonstrations for this chapter

Each demonstration runs in the browser and links back to these notes. The ▶ Demo boxes above open them already set to the case under discussion.

DemonstrationWhat you can seeSections and results
Exact null distributions of rank statisticsThe signed-rank and rank-sum laws built from their generating functions, the normal curve, exact critical regions and their sizes, and exact P-values with the data's midranks. Presets: 1 \(n=4\), Table 14.3.1; 2 \(n=7\), two-sided 0.05; 3 sharks; 4 cyclazocine; 5 game times (rank sum).Section 14.3; 14.4–14.9
What a rank test costsSimulated power of the \(t\), sign and signed-rank tests (exact size) for six symmetric populations, with the local power predicted by the efficiencies; and the book's \(k=4\), \(n_j=5\) experiment comparing Kruskal–Wallis with \(F\). Presets: 1 normal; 2 Laplace; 3 Cauchy; 4 exponential data under \(H_0\); 5 a shifted group.Section 14.7; 14.16–14.18

Related demonstrations elsewhere: in the graduate course, the permutation test demo (Sections 14.1 and 14.3: exact permutation laws) and the efficiency demo (Section 14.7: mean against median); in Statistical Methods for Modern Biology, the binomial test demo (Section 14.2) and the permutation test demo (Section 14.3); in this course, the \(t\) test robustness demo (Section 14.1).

References

  1. Billingsley, P. (1968). Convergence of Probability Measures. Wiley, New York. (Theorem 4.2, the approximation lemma used in Filling the gap 14.15.)
  2. Fienberg, S. E. (1971). Randomization and social affairs: the 1970 draft lottery. Science, 171, 255–261.
  3. Friedman, M. (1937). The use of ranks to avoid the assumption of normality implicit in the analysis of variance. Journal of the American Statistical Association, 32, 675–701.
  4. Hodges, J. L. and Lehmann, E. L. (1956). The efficiency of some nonparametric competitors of the \(t\)-test. Annals of Mathematical Statistics, 27, 324–335.
  5. Hoeffding, W. (1948). A class of statistics with asymptotically normal distribution. Annals of Mathematical Statistics, 19, 293–325.
  6. Hoeffding, W. and Robbins, H. (1948). The central limit theorem for dependent random variables. Duke Mathematical Journal, 15, 773–780.
  7. Kruskal, W. H. and Wallis, W. A. (1952). Use of ranks in one-criterion variance analysis. Journal of the American Statistical Association, 47, 583–621.
  8. Larsen, R. J. and Marx, M. L. (2018). An Introduction to Mathematical Statistics and Its Applications, 6th edition. Pearson, Boston. Chapter 14, pp. 638–673.
  9. Lehmann, E. L. (2006). Nonparametrics: Statistical Methods Based on Ranks, revised first edition. Springer, New York.
  10. Levene, H. (1952). On the power function of tests of randomness based on runs up and down. Annals of Mathematical Statistics, 23, 34–56.
  11. Mann, H. B. and Whitney, D. R. (1947). On a test of whether one of two random variables is stochastically larger than the other. Annals of Mathematical Statistics, 18, 50–60.
  12. Wallis, W. A. and Moore, G. H. (1941). A significance test for time series analysis. Journal of the American Statistical Association, 36, 401–409.
  13. Wasserman, L. (2004). All of Statistics. Springer, New York. (Chapters 5, 9 and 10; the graduate companion course.)
  14. Wilcoxon, F. (1945). Individual comparisons by ranking methods. Biometrics Bulletin, 1, 80–83.