Cambridge International AS & A Level · Topic 4.4
A-Level Further Maths 9231 / Topic 4.4 / AS & A Level

Two samples, one ranking.

When two independent samples come from populations you cannot assume are normal, put all the values in one list, rank them, and add up the ranks of the smaller sample. If that sum is surprisingly small or surprisingly large, the two populations are probably not the same.

The key idea

Combine the two samples (sizes \(m \le n\)) and rank all \(m + n\) values from smallest. \(R_m\) is the sum of the ranks of the smaller sample. The test statistic is \(W\), the smaller of \(R_m\) and \(m(n + m + 1) - R_m\). Reject \(H_0\) (the two populations are identical) if \(W \le\) the table critical value for \((m, n)\). Beyond the table, use \[W \approx N\!\left(\tfrac{1}{2}m(m + n + 1),\ \tfrac{1}{12}mn(m + n + 1)\right)\] with a continuity correction.

Fertiliser P (m = 4) Fertiliser Q (n = 6) height (cm) rank 19.8 23.1 24.2 25.6 26.9 27.4 28.3 29.0 30.5 31.2 1 2 3 4 5 6 7 8 9 10 Rm = 1 + 2 + 4 + 6 = 13 m(n + m + 1) − Rm = 4 × 11 − 13 = 31, so W = 13
Fig. 1: the heights of 4 plants given fertiliser P and 6 given fertiliser Q, combined into one ranking. The P plants (circles) take four of the lowest six ranks, so their rank sum is small
Section 01

Rank the samples together.

The rank-sum test compares two independent samples, of sizes \(m\) and \(n\) with \(m \le n\). It does not assume normal populations. Put all \(m + n\) values into one list, give rank 1 to the smallest and rank \(m + n\) to the largest, then add the ranks belonging to the smaller sample. That total is \(R_m\).

Why it works. If \(H_0\) is true and the two populations are identical, the labels 'first sample' and 'second sample' are just shuffled at random across the ranks. Every choice of \(m\) ranks out of \(m + n\) is then equally likely, so the distribution of \(R_m\) can be found by counting. \(R_m\) can be as small as \(1 + 2 + \dots + m = \tfrac{1}{2}m(m + 1)\) or as large as \(\tfrac{1}{2}m(2n + m + 1)\), and its distribution is symmetric about \(\tfrac{1}{2}m(m + n + 1)\). A rank sum near either end is unlikely under \(H_0\).

The other end. Ranking from the largest instead turns rank \(r\) into \(m + n + 1 - r\), so the smaller sample's rank sum becomes \(m(m + n + 1) - R_m\). The test statistic is

\[ W = \text{the smaller of } R_m \text{ and } m(n + m + 1) - R_m, \]

so a single lower-tail table serves both directions.

Worked example Rank sum for two fertilisers
Heights (cm) of plants: fertiliser P: 23.1, 27.4, 19.8, 25.6; fertiliser Q: 28.3, 24.2, 30.5, 26.9, 31.2, 29.0. Find \(R_m\) and \(W\).
  1. \(m = 4\) (P is the smaller sample), \(n = 6\).
  2. Combined order: 19.8 (P), 23.1 (P), 24.2 (Q), 25.6 (P), 26.9 (Q), 27.4 (P), 28.3 (Q), 29.0 (Q), 30.5 (Q), 31.2 (Q).
  3. The P values have ranks 1, 2, 4 and 6 (Fig. 1).
  4. \[ R_m = 1 + 2 + 4 + 6 = 13 \]
  5. \[ m(n + m + 1) - R_m = 4 \times 11 - 13 = 31 \]
Answer: \(R_m = 13\), and \(W = 13\) (the smaller of 13 and 31)
Worked example Ranking from the other end
Rank the ten heights of the previous example from the largest down and check that the P rank sum is \(m(n + m + 1) - R_m\).
  1. From the top, 31.2 has rank 1, so a value with rank \(r\) from the bottom has rank \(11 - r\) from the top.
  2. The P values now have ranks \(10, 9, 7, 5\).
  3. \[ 10 + 9 + 7 + 5 = 31 = 4 \times 11 - 13 \]
  4. The two rank sums always add up to \(m(m + n + 1)\), here \(44\).
Answer: P rank sum from the top \(= 31 = m(n + m + 1) - R_m\)
Your turn
Sample A: 14, 9, 17. Sample B: 11, 20, 16, 22, 13. Find \(R_m\) and \(W\).
Examiner trap

Rank the two samples TOGETHER, not each one separately (ranking within a sample always gives \(1 + 2 + \dots\) and tells you nothing). And \(R_m\) is the rank sum of the SMALLER sample, whatever order the question lists them in.

Section 02

Compare W with the table.

The tables list, for each pair \((m, n)\) with \(m \le n \le 10\), the largest value \(w\) with \(P(W \le w) \le\) the significance level. Columns are labelled with both one-tailed levels (0.05, 0.025, 0.01, 0.005) and two-tailed levels (0.10, 0.05, 0.02, 0.01). Reject \(H_0\) if \(W \le\) the critical value.

Worked example One-tailed test on the fertiliser data
Using the data of Fig. 1, test at the 5% significance level whether plants given fertiliser P tend to be shorter than plants given fertiliser Q.
  1. \(H_0\): the heights with P and with Q come from identical populations. \(H_1\): heights with P tend to be smaller. One-tailed.
  2. From the first section, \(R_m = 13\) and \(W = 13\). The P plants rank low, which is the direction \(H_1\) claims.
  3. Critical value for \(m = 4,\ n = 6\), one-tailed 5%: \(13\).
  4. \(W = 13 \le 13\), so reject \(H_0\).
Answer: There is sufficient evidence at the 5% level that plants given P tend to be shorter than plants given Q
Worked example A two-tailed test where W is the other sum
Lifetimes (hours) of batteries: brand A: 34.8, 37.0, 37.9, 38.4, 40.7; brand B: 31.2, 32.5, 33.1, 34.0, 35.6, 36.3, 39.5. Test at the 5% level whether the lifetimes of the two brands differ.
  1. \(H_0\): the lifetimes of A and B come from identical populations. \(H_1\): they do not. Two-tailed, \(m = 5,\ n = 7\).
  2. A has ranks 5, 8, 9, 10, 12 in the combined list, so \(R_m = 44\).
  3. \[ m(n + m + 1) - R_m = 5 \times 13 - 44 = 21, \quad W = 21 \]
  4. Critical value for \(m = 5,\ n = 7\), two-tailed 5% (one-tailed 0.025): \(20\).
  5. \(W = 21 > 20\), so do not reject \(H_0\).
Answer: There is insufficient evidence at the 5% level that the lifetimes of the two brands differ
Examiner trap

The decision rule runs the opposite way to a \(t\) or \(z\) test: SMALL \(W\) means significant, and \(W\) equal to the critical value counts as significant. Also, a two-tailed 5% test uses the one-tailed 0.025 column; in the battery example the one-tailed 0.05 value is 21, which would have wrongly given a significant result.

Stage 1 · Learn

Check your understanding

Four quick checks. Each correct answer earns XP and records this skill on your profile.

Quick check+10 XP

Sample A: 5, 12, 8. Sample B: 3, 10, 15, 7. Find \(R_m\).

Quick check+10 XP

With \(m = 4\), \(n = 7\) and \(R_m = 30\), find \(W\).

Quick check+10 XP

In a rank-sum test, \(W = 15\) and the critical value is \(17\). What is the conclusion?

Quick check+10 XP

Which situation calls for the Wilcoxon rank-sum test?

Section 03

Large samples and which test.

When the sample sizes go beyond the table (both greater than 10 is the usual case), the rank sum is approximately normal. Under \(H_0\),

\[ E(R_m) = \tfrac{1}{2}m(m + n + 1), \qquad \operatorname{Var}(R_m) = \tfrac{1}{12}mn(m + n + 1). \]

\(W\) is an integer, so use a continuity correction: with \(W\) the smaller sum (below the mean), \(z = \dfrac{W + 0.5 - \tfrac{1}{2}m(m + n + 1)}{\sqrt{\tfrac{1}{12}mn(m + n + 1)}}\), and reject \(H_0\) if \(z\) is below the negative critical value of \(N(0, 1)\).

DataTest
two independent samples, normal populations with a common variance can be assumedtwo-sample \(t\)-test (uses the actual values, so more powerful)
two independent samples, no normality assumptionWilcoxon rank-sum test
paired data (same subject twice, or matched pairs)Wilcoxon matched-pairs signed-rank test on the differences
Worked example Normal approximation, two-tailed
Reaction times were recorded for 12 students who had slept for less than 6 hours and 15 who had slept for more. In the combined ranking, the 12 students have rank sum 211. Test at the 5% level whether the reaction times of the two groups differ.
  1. \(H_0\): the two populations of reaction times are identical. \(H_1\): they differ. Two-tailed, \(m = 12,\ n = 15\).
  2. \[ m(n + m + 1) - R_m = 12 \times 28 - 211 = 125, \quad W = 125 \]
  3. \[ \begin{aligned} E &= \tfrac{1}{2}(12)(28) = 168 \\ \operatorname{Var} &= \tfrac{1}{12}(12)(15)(28) = 420 \end{aligned} \]
  4. \[ z = \frac{125.5 - 168}{\sqrt{420}} = -2.074 \]
  5. Two-tailed 5%: critical value \(-1.96\). Since \(-2.074 < -1.96\), reject \(H_0\).
Answer: There is sufficient evidence at the 5% level that the reaction times of the two groups differ (the short sleepers tend to be slower)
Worked example Choosing the test
Name the most suitable test. (a) The pulse rates of 9 athletes are measured before and after a training camp. (b) Exam marks of 8 students taught online and 11 taught in class, with no reason to think the marks are normal. (c) The masses of samples of apples from two orchards, both known to be normally distributed with the same variance.
  1. (a) Each athlete gives two linked readings: paired data, so work with the 9 differences.
  2. (b) Two separate groups of different sizes, no normality: the samples are independent and a non-parametric test is needed.
  3. (c) Independent samples from normal populations with a common variance: a parametric test is valid and makes better use of the data.
Answer: (a) Wilcoxon matched-pairs signed-rank test   (b) Wilcoxon rank-sum test   (c) two-sample \(t\)-test
Your turn
Samples of sizes 11 and 13 give \(R_m = 110\) for the smaller sample. Test at the 5% level whether the population of the smaller sample tends to take smaller values.
Examiner trap

The variance is \(\tfrac{1}{12}mn(m + n + 1)\), with \(mn\), not \(m^{2}\). The continuity correction moves \(W\) TOWARDS the mean: use \(W + 0.5\), not \(W - 0.5\). And never use the rank-sum test on paired data: pairing is information the rank-sum test throws away.

Stage 2 · Exam

Exam-style questions

Unlocks once the four checks above are done. Worth more XP, written to AS & A Level Further Mathematics Paper 1 to 4 standard.

Finish the four checks above to unlock the exam questions
Exam style+20 XP

Sample A: 2.4, 3.9, 3.1, 4.6. Sample B: 3.5, 4.2, 5.0, 5.3, 4.8. The critical value for a one-tailed test at 5% with \(m = 4,\ n = 5\) is 12. Testing whether A tends to take smaller values, which is correct?

Exam style+20 XP

Find the critical value of \(W\) for a two-tailed test at the 5% level with samples of sizes 6 and 8.

Exam style+20 XP

For samples of sizes \(m = 12\) and \(n = 16\), find the mean and variance of \(R_m\) under \(H_0\).

Exam style+20 XP

With \(m = 12\), \(n = 16\) and \(W = 150\), find the standardised value used in the normal approximation.

Skill unlocked

Two samples, one ranking, one verdict.

This skill is now recorded on your profile. Keep the chain going.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Combined ranking and \(W\), one- and two-tailed table tests, a large-sample normal approximation, the exact distribution behind the tables, and choosing the right two-sample test.