CalcPath
ProgressProblem setsFeedback
← Question sheet

Statistics · Solutions

Nonparametric Methods

12 questions · about 106 minutes

Work this sheet on paper, showing every step — the method is what is being tested, and the solutions are written so you can check your route rather than just your answer. Name every result you use (“by the null moments of W+”, “by exchangeability”, “by the probability integral transform”) and say what its hypotheses are; a rank test that is used where its assumptions fail earns nothing. Every number on this sheet can be found exactly by hand, as a fraction or a surd, so no calculator is needed; where a normal critical value is required it is given. Full worked solutions are on a separate page; each question also has its own reveal, so you can check one answer without seeing the rest.

  1. 1.Computation

    A sample of four observations is to be tested against a fully specified continuous distribution function F0​. Evaluated at the ordered observations x(1)​<x(2)​<x(3)​<x(4)​, the hypothesised distribution function takes the values

    F0​(x(1)​)=0.10,F0​(x(2)​)=0.45,F0​(x(3)​)=0.55,F0​(x(4)​)=0.70.

    1. (a)Compute the Kolmogorov-Smirnov statistic D4​, stating at which observation, and from which side of the jump, the supremum is attained.
    2. (b)Suppose instead that F0​(x(4)​)=0.97, the other three values being unchanged. Recompute D4​. Which gap is now the largest, and what does this say about checking only one side of each jump?
    3. (c)Without any further calculation, explain why the null distribution of D4​ would be the same whether F0​ were a normal, an exponential or a logistic distribution function, and name the transformation that shows it.

    Solution

    (a) Both gaps at every jump. The empirical distribution function F4​ is a staircase that equals (i−1)/4 just before x(i)​ and i/4 just after it. Since F0​ is continuous, the largest vertical distance between the two functions occurs at one of these eight values.

    The “after” gaps ∣i/4−F0​(x(i)​)∣ are

    ∣0.25−0.10∣=0.15,∣0.50−0.45∣=0.05,∣0.75−0.55∣=0.20,∣1.00−0.70∣=0.30.

    The “before” gaps ∣(i−1)/4−F0​(x(i)​)∣ are

    ∣0−0.10∣=0.10,∣0.25−0.45∣=0.20,∣0.50−0.55∣=0.05,∣0.75−0.70∣=0.05.

    The largest of the eight is 0.30, so D4​=0.30, attained just after the fourth observation: the staircase has reached 1 while F0​ is still at 0.70.

    (b) Move the last point. Only the two gaps at x(4)​ change. After the jump, ∣1.00−0.97∣=0.03; before it, ∣0.75−0.97∣=0.22. The other six gaps are as in (a), the largest of them being 0.20 (twice). So now

    D4​=0.22,

    attained just before the fourth observation. In (a) the maximum came from the after-side of the last jump; here it comes from the before-side of the same jump, and a computation that checked only the after-gaps would have reported 0.20 instead of 0.22. The supremum of ∣Fn​−F0​∣ is always at a jump, but it can be on either side, so both must be checked at every observation.

    (c) Distribution-free. By the probability integral transform, if X has continuous distribution function F0​ then U=F0​(X) is Uniform(0,1). Since F0​ is non-decreasing, the empirical distribution function of the transformed values ui​=F0​(xi​), evaluated at u=F0​(x), equals F4​(x); hence

    D4​=xsup​∣F4​(x)−F0​(x)∣=u∈(0,1)sup​∣G4​(u)−u∣,

    where G4​ is the empirical distribution function of four uniforms. Nothing about the particular F0​ survives the substitution, so the null distribution of D4​ is the same for every continuous F0​ — which is why a single table of critical values serves every goodness-of-fit problem of this type. Notice that the data in (a) were given to you already in the form F0​(x(i)​): those four numbers are exactly the transformed sample u(i)​.

  2. 2.Computation

    Ten patients were randomised, five to a treatment and five to a control, and each was classified as improved or not:

    treatmentcontrol​improved516​not044​5510​​

    Write a for the top-left count, so that the observed table has a=5.

    1. (a)Compute the four expected counts under independence and explain why the chi-square test of independence should not be used here.
    2. (b)With both margins fixed, list every value a can take, and compute the hypergeometric probability of each possible table. Check that your probabilities sum to 1.
    3. (c)Give the one-sided p-value of Fisher's exact test against the alternative that treatment improves the outcome, and the two-sided p-value obtained by summing the probabilities of all tables at least as unlikely as the observed one.
    4. (d)Compute the chi-square statistic anyway (the 5% critical value of χ12​ is 3.841) and compare its verdict with the exact two-sided p. Which of the two limitations of the chi-square test does the comparison illustrate?

    Solution

    (a) Expected counts. Under independence Eij​=(row total)(column total)/n, so

    E11​=105×6​=3,E12​=105×4​=2,E21​=3,E22​=2.

    All four are below 5. The χ12​ distribution for X2 is asymptotic and needs expected counts of roughly 5 or more; with n=10 the statistic takes only a handful of distinct values, and the continuous approximation cannot be trusted. Fisher's exact test is the right tool.

    (b) The possible tables. The row totals are 5 and 5 and the column totals are 6 and 4. Since the improved column has total 6 and each row has only 5 patients, a≤5 and 6−a≤5, so a∈{1,2,3,4,5}. By the hypergeometric formula with a+b=5, c+d=5 and a+c=6,

    P(a)=(610​)(a5​)(6−a5​)​,(610​)=210.

    The numerators are

    a=1: (15​)(55​)=5,a=2: (25​)(45​)=50,a=3: (35​)(35​)=100,a=4: (45​)(25​)=50,a=5: (55​)(15​)=5,

    and 5+50+100+50+5=210, so the probabilities 2105​,21050​,210100​,21050​,2105​ sum to 1. ✓ The observed table has probability 2105​=421​.

    (c) The p-values. “Treatment improves the outcome” means large a. The observed a=5 is the largest possible value, so the only table at least as extreme is the observed one:

    pone-sided​=421​≈0.024.

    For the two-sided test, the tables with probability at most 2105​ are a=5 and a=1 (the mirror image, in which the control group does all the improving). So

    ptwo-sided​=2105+5​=21010​=211​≈0.048.

    (d) The approximation, for comparison. With the observed counts 5,0,1,4 and expected counts 3,2,3,2,

    X2=3(5−3)2​+2(0−2)2​+3(1−3)2​+2(4−2)2​=34​+2+34​+2=320​≈6.67,

    which is well beyond 3.841 and corresponds to a p-value near 0.01. The exact two-sided p is 0.048 — nearly five times larger. This is the small expected counts limitation: with a discrete, skewed statistic the χ2 approximation rejects too often, exactly as the rule of thumb warns. (The other limitation, arbitrariness of binning, does not arise because the data are genuinely categorical.) Note what not to do: there is nothing here to pool, and pooling would change the hypothesis anyway.

  3. 3.Computation

    Two unrelated studies. Use χ0.05,42​=9.488 and χ0.05,12​=3.841.

    Study I. A 3×3 table on n=400 subjects gives a chi-square statistic of X2=32.

    Study II. Two hundred people were asked the same yes/no question before and after a campaign. Seven changed from no to yes, one changed from yes to no, and the remaining 192 gave the same answer both times.

    1. (a)For Study I, test independence at α=0.05 and compute Cramér's V. Then find X2 and V for a table with the identical pattern of proportions but n=100, and say in one sentence what the comparison shows.
    2. (b)For Study II, carry out McNemar's test at α=0.05. Then compute the exact two-sided p-value by treating the 8 changers as a Binomial(8,21​) count, and reconcile the two verdicts.
    3. (c)Explain why the 192 unchanged subjects in Study II carry no information about whether the campaign shifted opinion, and say what a chi-square test of independence on the 2×2 before-by-after table would be testing instead.

    Solution

    (a) Study I. Degrees of freedom (3−1)(3−1)=4, and 32>9.488, so independence is rejected at the 5% level (the p-value is far below 0.001). For the strength, min(r−1,c−1)=2, so

    V=nmin(r−1,c−1)X2​​=400×232​​=0.04​=0.2.

    For a fixed pattern of association X2 is proportional to n, so at n=100 the statistic is X2=32×400100​=8, which is below 9.488: not significant. But

    V=100×28​​=0.04​=0.2

    exactly as before. The statistic measures evidence and tracks the sample size; V measures strength and does not — and V=0.2 is a weak association whether or not n is large enough to make it significant.

    (b) Study II. With b=7 and c=1,

    X2=b+c(b−c)2​=836​=4.5>3.841,

    so McNemar's test rejects at the 5% level.

    Exactly: under H0​ each changer is equally likely to change in either direction, so conditional on b+c=8 changers, b∼Binomial(8,21​). The one-sided tail is

    P(b≥7)=28(78​)+(88​)​=2568+1​=2569​,

    and doubling gives the two-sided p=25618​=1289​≈0.070 — not significant at 5%.

    The verdicts differ because χ12​ is an asymptotic approximation to a statistic that, with only 8 discordant pairs, takes very few values; the expected count of each kind of change is only 4, below the working threshold of 5. The exact binomial calculation is the one to trust. The chi-square version is the same statistic with a continuous distribution stretched over nine possible outcomes, and it rejects too readily, as approximations to discrete counts do.

    (c) Why the concordant pairs drop out. The question is whether the marginal proportion of yes answers moved. A subject who answered the same way twice contributes one yes (or one no) to both margins and therefore cannot move the difference between them, whichever way the campaign worked. Under the null the only random quantity is the direction of each change, and that is what the test conditions on — the same logic as pairing in the paired t-test, where within-pair differences discard between-subject variation.

    A chi-square test of independence on the before-by-after table would ask a different question: whether a person's before answer is associated with their after answer. With 192 of 200 unchanged it would reject overwhelmingly, reporting only that people tend to agree with themselves — which says nothing about whether the campaign shifted opinion.

  4. 4.Computation

    Eight subjects were measured before and after a treatment. The after-minus-before differences are

    +2.4,+0.7,−0.3,+5.1,+1.9,+3.3,+0.8,+4.0.

    Use z0.025​=1.96 where a normal approximation is asked for.

    1. (a)Carry out the sign test of H0​: median difference is zero, giving the exact one-sided and two-sided p-values. State the only assumption the test needs.
    2. (b)Compute the Wilcoxon signed-rank statistic W+, its null mean and variance, and the standardised value; decide at the 5% two-sided level. Show without a calculator that your decision does not depend on the rounding of the square root.
    3. (c)Find the exact two-sided p-value of the signed-rank test by counting sign patterns, and explain why the two tests disagree on these data.

    Solution

    (a) Sign test. Seven differences are positive and one is negative, no ties. Under H0​ the number of positives is S∼Binomial(8,21​), which needs only that each difference is positive with probability 21​ — no symmetry, no shape. Then

    P(S≥7)=28(78​)+(88​)​=2569​≈0.035,

    so the two-sided p-value is 25618​=1289​≈0.070. Not significant at the 5% level.

    (b) Signed-rank test. Order the absolute differences and rank them:

    0.3(1), 0.7(2), 0.8(3), 1.9(4), 2.4(5), 3.3(6), 4.0(7), 5.1(8).

    The only negative difference is −0.3, with rank 1, so W−=1 and, since the ranks sum to 28⋅9​=36,

    W+=36−1=35.

    By the null moments of the signed-rank statistic with n=8,

    E(W+)=48⋅9​=18,Var(W+)=248⋅9⋅17​=241224​=51.

    So z=51​35−18​=51​17​. Since 72=49<51<51.84=7.22, the standard deviation lies between 7 and 7.2, hence

    2.36<7.217​<z<717​<2.43,

    and every value in that range exceeds 1.96. Reject H0​ at the 5% level; z≈2.38, two-sided p≈0.017.

    (c) Exact p. Under the null (differences symmetric about 0) each of the 28=256 sign patterns is equally likely. W+≥35 means W−≤1, which happens for exactly two patterns: no negatives (W−=0) or the rank-1 difference alone negative (W−=1). So

    P(W+≥35)=2562​=1281​,ptwo-sided​=1282​=641​≈0.016,

    in close agreement with the normal approximation.

    The two tests disagree because the sign test sees only that 7 of 8 differences are positive, and with n=8 that pattern is simply not rare enough (p=0.070). The signed-rank test also sees that the one negative difference is the smallest in magnitude while the positives include all the large ones. That extra information is what pushes the evidence past the 5% line — and it is bought with the extra assumption of symmetry, which the sign test does not need.

  5. 5.Proof

    Let d1​,…,dn​ be paired differences with no ties and none equal to zero, and let W+ be the Wilcoxon signed-rank statistic. You may quote ∑i=1n​i=2n(n+1)​ and ∑i=1n​i2=6n(n+1)(2n+1)​.

    1. (a)Write W+=∑i=1n​iZi​ for suitable indicator variables Zi​ and prove that under the null hypothesis that the differences are symmetric about zero, E(W+)=4n(n+1)​ and Var(W+)=24n(n+1)(2n+1)​. Say precisely where symmetry is used and which step would fail without it.
    2. (b)Prove that under the same null, W−=2n(n+1)​−W+ has exactly the same distribution as W+, and deduce that P(W+≥w)=P(W+≤2n(n+1)​−w) for every w.
    3. (c)Using (b), find the smallest attainable one-sided and two-sided p-values for a sample of n=5 pairs, and hence the smallest n for which a two-sided signed-rank test can ever reject at α=0.05.

    Solution

    (a) The moments. Rank the absolute differences ∣di​∣ from 1 to n and let Zi​=1 if the difference holding absolute rank i is positive, Zi​=0 otherwise. Then W+, the sum of the ranks of the positive differences, is ∑i=1n​iZi​.

    Under symmetry about zero, each difference is equally likely to be positive or negative, and its sign is independent of its magnitude: symmetry says the conditional distribution of the sign given ∣di​∣ is still a fair coin. Hence the signs are independent of the ranking, and the Zi​ are independent Bernoulli(21​) variables. This is the step that needs symmetry. Under a skewed null with median zero the signs are still fair coins, but they are no longer independent of the magnitudes — large ∣d∣ would be more often positive, say — so the Zi​ attached to large ranks would not be Bernoulli(21​), and neither formula would hold.

    By linearity,

    E(W+)=i=1∑n​iE(Zi​)=21​i=1∑n​i=21​⋅2n(n+1)​=4n(n+1)​.

    By independence the variance of the sum is the sum of the variances, and Var(Zi​)=21​⋅21​=41​, so

    Var(W+)=i=1∑n​i2Var(Zi​)=41​⋅6n(n+1)(2n+1)​=24n(n+1)(2n+1)​.■

    Linearity did not need independence; the variance step did.

    (b) Symmetry of the null distribution. The ranks of the negative differences are those i with Zi​=0, so

    W−=i=1∑n​i(1−Zi​)=2n(n+1)​−W+.

    Under the null the vector (Z1​,…,Zn​) consists of independent fair coins, and so does (1−Z1​,…,1−Zn​): the two vectors have the same joint distribution, namely uniform over the 2n sign patterns. Since W+ is the function ∑iZi​ of the first vector and W− is the same function of the second, W− and W+ have the same distribution. Therefore, for any w,

    P(W+≥w)=P(W−≥w)=P(2n(n+1)​−W+≥w)=P(W+≤2n(n+1)​−w).■

    The null distribution is symmetric about 4n(n+1)​, which is why one tail of a table suffices.

    (c) The floor. With n=5 the ranks sum to 15 and there are 25=32 equally likely sign patterns. The most extreme value W+=15 arises from exactly one pattern (all positive), so the smallest one-sided p-value is 321​=0.03125. By (b) the lower tail W+≤0 has the same probability, so the smallest two-sided p-value is 322​=161​=0.0625, which exceeds 0.05: no two-sided signed-rank test on five pairs can reject at the 5% level, whatever the data.

    In general the smallest two-sided p is 2n2​, and 2n2​≤0.05 requires 2n≥40, that is n≥6: with six pairs the extreme pattern gives p=642​=0.03125. (One-sided, 2n≥20 suffices, so n=5 is enough.) A rank test cannot be more decisive than the number of sign patterns allows, and with tiny samples that ceiling binds before any question about power arises.

  6. 6.Critique

    Two independent samples of sizes n1​=5 and n2​=7 are ranked together, and the rank sum of the first sample is W=17. A student writes the following. Use z0.025​=1.96.

    Step 1. The Mann-Whitney statistic is the rank sum, so U=17.

    Step 2. E(U)=25×7​=17.5 and Var(U)=125×7×13​=12455​, so z=455/12​17−17.5​≈−0.08.

    Step 3. Since ∣z∣<1.96 we do not reject, and therefore the two populations have the same median.

    Take U=W−2n1​(n1​+1)​; this is the number of pairs (i,j) in which the first-sample observation xi​ exceeds the second-sample observation yj​.

    1. (a)Show that W−2n1​(n1​+1)​ does count the pairs described, by considering the k-th smallest first-sample observation and its rank in the combined ordering.
    2. (b)Identify every error in the student's argument — there are three, and they are of different kinds — and say which result or hypothesis each one abuses.
    3. (c)Redo the test correctly. Show without a calculator whether ∣z∣ exceeds 1.96, and state the conclusion in a form that is actually justified by the test.

    Solution

    (a) The identity. Let the first-sample observations in increasing order have combined ranks r(1)​<r(2)​<⋯<r(n1​)​. The k-th smallest first-sample value has k−1 first-sample values below it, so the remaining r(k)​−k observations below it all belong to the second sample: r(k)​−k is the number of yj​ it exceeds. Summing over k,

    #{(i,j):xi​>yj​}=k=1∑n1​​(r(k)​−k)=W−2n1​(n1​+1)​.■

    Its range is 0 to n1​n2​, and W alone ranges from 2n1​(n1​+1)​ upward, which is exactly why the offset matters.

    (b) Three errors.

    Step 1 confuses W with U. By the definition of the Mann-Whitney statistic, U=W−2n1​(n1​+1)​=17−15=2, not 17. The null moments E(U)=2n1​n2​​ and Var(U)=12n1​n2​(n1​+n2​+1)​ are moments of U; feeding them W compares a statistic with the wrong centre. (Note that W=17 is only 2 above its minimum of 15: the first sample holds nearly all the lowest ranks, which is the opposite of “no evidence”.)

    Step 3 turns non-rejection into acceptance. Failing to reject H0​ means the data are compatible with H0​; it never establishes it. With n1​=5 and n2​=7 the test has modest power, so a non-significant result would be weak evidence of anything.

    Step 3 also misstates the hypothesis. The Mann-Whitney null is that the two distributions are identical, and the alternative is a stochastic ordering, P(X<Y)=21​. A conclusion about medians is valid only under the extra assumption that the two distributions differ by a pure shift and are otherwise the same shape — an assumption the student never stated.

    (c) The correct test. With U=2,

    z=455/12​2−17.5​=455/12​−15.5​.

    Compare squares: ∣z∣>1.96 if and only if 15.52>1.962×12455​. The left side is 240.25. On the right, 1.962=3.8416 and 12455​<38, so the right side is below 3.8416×38=145.98. Since 240.25>146, ∣z∣>1.96 comfortably; in fact 6.12=37.21<12455​<38.44=6.22 gives 2.50<∣z∣<2.54, so z≈−2.52 and the two-sided p is about 0.012.

    Reject H0​ at the 5% level. The justified conclusion: the two samples are unlikely to come from the same distribution, and the direction is that first-sample values tend to be smaller — only 2 of the 35 pairs have the first-sample value on top. Any statement about medians requires adding, and stating, the shift assumption.

  7. 7.Computation

    Five students sit two examinations. Ranked by the first examination they are students 1,2,3,4,5; their ranks on the second examination, listed in the same order, are 3,1,2,5,4. The raw second-examination scores were y=6,1,3,1000,40.

    1. (a)Compute Spearman's ρs​ from the computing formula, giving the answer as an exact fraction.
    2. (b)List every pair of students as concordant or discordant and compute Kendall's τ. Compare it with ρs​.
    3. (c)The score 1000 is a data-entry error; the true value was 100. Determine, with reasons, what happens to ρs​ and τ when it is corrected, and explain what happens to Pearson's r computed on the raw scores. Which single feature of the rank definitions is responsible for the difference?

    Solution

    (a) Spearman. With ri​=1,2,3,4,5 and si​=3,1,2,5,4, the rank differences di​=ri​−si​ are

    −2, +1, +1, −1, +1,so∑di2​=4+1+1+1+1=8.

    There are no ties, so the computing formula applies with n(n2−1)=5×24=120:

    ρs​=1−1206×8​=1−12048​=1−52​=53​.

    (b) Kendall. Listing the second-exam ranks in first-exam order, 3,1,2,5,4, a pair (i,j) with i<j is concordant when the second rank increases too. The (25​)=10 pairs:

    (1,2) 3>1 D,(1,3) 3>2 D,(1,4) 3<5 C,(1,5) 3<4 C,(2,3) 1<2 C,

    (2,4) 1<5 C,(2,5) 1<4 C,(3,4) 2<5 C,(3,5) 2<4 C,(4,5) 5>4 D.

    So C=7, D=3 and

    τ=(25​)C−D​=104​=52​.

    As usual ∣τ∣<∣ρs​∣ for the same data; here τ=32​ρs​ exactly, the rough rule of thumb landing on the nose. The interpretation of τ is direct: a randomly chosen pair of students is ordered the same way by both exams with probability 0.7 and the opposite way with probability 0.3, and τ is the difference.

    (c) Correcting the error. With the true score the second-exam values are 6,1,3,100,40. Since 100 is still the largest, student 4 still has rank 5 and every other rank is unchanged: the rank vector is 3,1,2,5,4 exactly as before. Every di​ is unchanged, so ρs​=53​ still; every pair is concordant or discordant exactly as before, so τ=52​ still. A rank depends only on order, and correcting 1000 to 100 preserves the order of the five scores. The same is true of any strictly increasing transformation of the scores — squaring them, taking logarithms — which is why rank correlation detects any monotone relationship and not merely a linear one.

    Pearson's r is built from products of deviations, Sxy​=∑(xi​−xˉ)(yi​−yˉ​), and with y4​=1000 that single term dominates Sxy​ while (y4​−yˉ​)2 dominates Syy​. In the limit of an ever larger y4​, r tends to the correlation between x and the indicator of student 4: the x-deviations are −2,−1,0,1,2, the indicator's deviations from its mean 0.2 are −0.2,−0.2,−0.2,0.8,−0.2, the cross-products sum to 0.4+0.2+0+0.8−0.4=1, and with Sxx​=10 and SII​=4(0.04)+0.64=0.8 the limit is r=8​1​=22​1​≈0.35. So r is being reported by one observation, and correcting that observation to 100 moves r appreciably, while a second error putting it at 106 would move it again. The rank statistics bound the influence of any one observation — the erroneous score can never contribute more than a rank difference of 4 — and that robustness is a different property from being assumption-free.

  8. 8.Proof

    Let r1​,…,rn​ and s1​,…,sn​ be the ranks of two variables on the same n observations, with no ties, and let di​=ri​−si​. You may quote ∑i=1n​i=2n(n+1)​ and ∑i=1n​i2=6n(n+1)(2n+1)​, but not the identity in (a).

    1. (a)Prove that i=1∑n​(i−2n+1​)2=12n(n2−1)​.
    2. (b)Starting from the definition of ρs​ as Pearson's correlation of the two rank vectors, derive the computing formula ρs​=1−n(n2−1)6∑di2​​. Say where the absence of ties is used.
    3. (c)Prove that if the second ranking is the exact reverse of the first, si​=n+1−ri​ for every i, then ρs​=−1. Deduce that ∑di2​≤3n(n2−1)​ for any two rankings, and check both statements by hand for n=3.

    Solution

    (a) The sum of squared deviations of 1,…,n. Expand the square and use the two quoted sums:

    i=1∑n​(i−2n+1​)2=∑i2−(n+1)∑i+n⋅4(n+1)2​=6n(n+1)(2n+1)​−2n(n+1)2​+4n(n+1)2​.

    The last two terms combine to −4n(n+1)2​. Factor out n(n+1) and put everything over 12:

    n(n+1)[122(2n+1)−3(n+1)​]=n(n+1)⋅124n+2−3n−3​=12n(n+1)(n−1)​=12n(n2−1)​.■

    (b) The computing formula. Because there are no ties, each rank vector is a permutation of 1,…,n. So both have the same mean rˉ=sˉ=2n+1​ and, by (a), the same sum of squared deviations,

    Srr​=Sss​=12n(n2−1)​.

    (With ties, averaged ranks would spoil both of these — the means would still agree but the sums of squares would be smaller, and the formula would need a correction.)

    Now write di​=(ri​−rˉ)−(si​−sˉ), which is legitimate because the two means are equal, and expand:

    ∑di2​=∑(ri​−rˉ)2−2∑(ri​−rˉ)(si​−sˉ)+∑(si​−sˉ)2=Srr​−2Srs​+Sss​=2Srr​−2Srs​.

    Hence Srs​=Srr​−21​∑di2​, and Pearson's correlation of the ranks is

    ρs​=Srr​Sss​​Srs​​=Srr​Srr​−21​∑di2​​=1−2Srr​∑di2​​=1−2⋅n(n2−1)/12∑di2​​=1−n(n2−1)6∑di2​​.■

    (c) Reversed rankings. If si​=n+1−ri​ then

    di​=ri​−(n+1−ri​)=2ri​−(n+1)=2(ri​−2n+1​),

    so, since the ri​ are a permutation of 1,…,n, part (a) gives

    ∑di2​=4i=1∑n​(i−2n+1​)2=4⋅12n(n2−1)​=3n(n2−1)​,

    and the computing formula returns ρs​=1−n(n2−1)6​⋅3n(n2−1)​=1−2=−1. ■

    For the bound: ρs​ is a Pearson correlation, so by the Cauchy–Schwarz inequality ρs​≥−1 for any two rankings. Substituting the computing formula, 1−n(n2−1)6∑di2​​≥−1 rearranges to ∑di2​≤3n(n2−1)​, with equality exactly when ρs​=−1 — which the reversed ranking attains. (Equivalently: reversing the order minimises ∑ri​si​, the rearrangement inequality in rank form.)

    Check, n=3. The bound is 33⋅8​=8. Reversing 1,2,3 to 3,2,1 gives d=−2,0,2 and ∑di2​=4+0+4=8, so ρs​=1−246⋅8​=−1. ✓ The other five permutations give ∑di2​∈{0,2,2,6,6}, all below 8, so the bound is attained only by the reversal. ✓

  9. 9.Sketch

    Two groups give x=1,2 and y=4,6,9. A permutation test is to be run on T=yˉ​−xˉ, one-sided against yˉ​>xˉ. Write s for the sum of the two values assigned to the first group.

    1. (a)Show that T=644−5s​, and deduce that rejecting for large T is the same as rejecting for small s. Why is s the better statistic to tabulate?
    2. (b)List all (25​)=10 relabellings with their values of s, verify that the average of the ten values equals n1​ times the pooled mean, and draw the permutation null distribution of s as a bar chart, marking the observed value and shading the rejection region that the observed data define.
    3. (c)Read the one-sided p-value off your chart. Then say what is the two-sided p-value under the rule “at least as far from E(s) as the observed value”, and explain from the chart why this distribution, unlike the equal-sizes case, is not symmetric.

    Solution

    (a) Reduce to the group sum. The pooled total is 1+2+4+6+9=22. If the first group's two values sum to s, the second group's three values sum to 22−s, so

    T=yˉ​−xˉ=322−s​−2s​=62(22−s)−3s​=644−5s​.

    This is a strictly decreasing function of s, so “T at least as large as observed” is exactly “s at least as small as observed”, and the two tests have identical p-values. Tabulating s is better because it takes integer values, and because the argument shows that any statistic that is a monotone function of the first group's sum — a difference of totals, of means, a t-statistic with pooled variance — yields the same test.

    (b) The ten relabellings. Choosing which two of {1,2,4,6,9} go to the first group:

    {1,2}→3,{1,4}→5,{2,4}→6,{1,6}→7,{2,6}→8,{1,9}→10,{4,6}→10,{2,9}→11,{4,9}→13,{6,9}→15.

    The observed labelling is {1,2}, so sobs​=3, the smallest value in the list. The ten values sum to 3+5+6+7+8+10+10+11+13+15=88, so their average is 8.8; the pooled mean is 22/5=4.4 and n1​×4.4=8.8. ✓ (Under exchangeability each of the two first-group slots holds a randomly chosen pooled value, so E(s)=2× pooled mean.)

    The chart. Horizontal axis s from 3 to 15 with integer ticks; vertical axis “number of relabellings” from 0 to 2. Draw a bar of height 1 at each of s=3,5,6,7,8,11,13,15 and a bar of height 2 at s=10: nine bars, total height 10. Mark the bar at s=3 as the observed value — it stands alone at the far left. The rejection region defined by the data is {s≤3}, which is just that one bar, so shade it. Draw a vertical dashed line at E(s)=8.8; it falls between the bars at 8 and 10.

    (c) Reading off. Exactly one of the ten equally likely relabellings has s≤3, so

    pone-sided​=101​.

    This is also the smallest p-value the design can produce: with n1​=2 and n2​=3 nothing can reach α=0.05, however cleanly the groups separate.

    For the two-sided rule, the observed distance is ∣3−8.8∣=5.8, so a relabelling counts if s≤3 or s≥14.6. From the chart that is s=3 and s=15, two of ten: ptwo-sided​=102​.

    Why no symmetry. In the chapter's equal-sizes example every relabelling has a mirror image obtained by swapping the two groups, which negates T, so the null distribution is symmetric about 0. Here the groups have sizes 2 and 3, and swapping them is not a relabelling of the same design, so nothing forces symmetry. The chart shows it: the bars to the left of 8.8 sit at distances 5.8,3.8,2.8,1.8,0.8 while those to the right sit at 1.2,1.2,2.2,4.2,6.2, and the value 9 stretches the right tail. Exactness does not need symmetry — the proof that the permutation test has the stated level uses only that the ten relabellings are equally likely — but reading a two-sided p-value from an asymmetric distribution does require saying which rule is being used.

  10. 10.Critique

    Two arguments follow. Each contains exactly one fatal step. For each argument, name the step, explain why it fails, and give the corrected procedure.

    Argument A. “Five observations 0.9, 2.3, 3.1, 4.4, 4.8 come from a Uniform(0,θ) population. Step 1. The maximum likelihood estimate of θ is the sample maximum, 4.8. Step 2. The sampling distribution of the maximum is awkward, so bootstrap it: draw resamples of size 5 with replacement, compute the maximum of each, and take the 2.5% and 97.5% quantiles of the resample maxima as a 95% confidence interval for θ. Step 3. Since the interval comes from resampling, it makes no assumption about the population.”

    Argument B. “Ten paired differences are −0.3, −0.1, 0.2, 0.4, 0.5, 0.7, 0.8, 9, 12, 15. Step 1. The differences are strongly right-skewed, so the paired t-test is unreliable. Step 2. Rank tests are distribution-free, so the Wilcoxon signed-rank test is valid whatever the shape of the differences. Step 3. Apply it to test whether the median difference is zero.”

    1. (a)For Argument A, compute exactly the probability that a resample's maximum equals the observed maximum 4.8, and use it to describe the shape of the bootstrap distribution of the maximum. What does that shape do to the upper end of the percentile interval, and why is that fatal for a parameter that is certainly at least 4.8?
    2. (b)For Argument B, say what the Wilcoxon null actually assumes beyond a zero median, and show concretely on these ten differences why the test is not what its user thinks it is. What should be used instead, and what does “distribution-free” actually promise?

    Solution

    (a) Argument A: Step 2 is the fatal one. Step 1 is correct, and Step 3 is only wrong as a consequence of Step 2.

    The resample maximum is at most the observed maximum, because a resample contains only observed values. It equals 4.8 unless all five draws miss the largest observation, and each draw misses it with probability 54​ independently, so

    P(resample max=4.8)=1−(54​)5=1−31251024​=31252101​≈0.672.

    So the bootstrap distribution of the maximum puts about two-thirds of its mass on the single point 4.8 and the rest at 4.4, 3.1, 2.3 or 0.9 — a distribution that lives entirely at or below the estimate. Its 97.5% quantile is therefore 4.8 itself (indeed every quantile above the 33% point is 4.8), so the percentile interval has the form (something,4.8].

    That is fatal because θ≥4.8 with certainty — the population cannot produce a value larger than θ — and θ>4.8 with probability one. An interval whose upper endpoint is 4.8 contains θ with probability zero, not 0.95. The bootstrap fails here because the statistic depends on an extreme order statistic, and the empirical distribution is a poor stand-in for the population exactly at its boundary. (As n grows the defect does not go away: 1−(1−n1​)n→1−e−1≈0.63.)

    Correction. The sampling distribution of the maximum is not awkward at all: for a Uniform(0,θ) sample of size n, P(X(n)​≤t)=(t/θ)n for 0≤t≤θ. Use that exact distribution to build the interval, as the estimation of θ for the uniform is done in closed form; the bootstrap is the wrong tool for a boundary parameter. Step 3's claim of “no assumption” is also empty: the argument already assumed a uniform population to justify the maximum in Step 1.

    (b) Argument B: Step 2 is the fatal one. Step 1 is a fair observation, and Step 3 merely acts on Step 2.

    The null hypothesis of the Wilcoxon signed-rank test is that the differences are symmetric about zero, not merely that their median is zero. The null distribution of W+ — E(W+)=4n(n+1)​, Var(W+)=24n(n+1)(2n+1)​, and the uniform distribution over the 2n sign patterns — is derived by writing W+=∑iZi​ with the signs Zi​ independent fair coins independent of the magnitudes. Symmetry is what delivers that independence.

    On these data the assumption is visibly false. Ranking the absolute values gives 0.1(1), 0.2(2), 0.3(3), 0.4(4), 0.5(5), 0.7(6), 0.8(7), 9(8), 12(9), 15(10); the two negatives hold ranks 1 and 3, so W−=4 and W+=55−4=51, against a null mean of 27.5 and null standard deviation 96.25​≈9.8 — about 2.4 standard deviations up, a “significant” result. But look at where the evidence comes from: the three largest magnitudes, 9,12,15, carry ranks 8,9,10 and contribute 27 of the 51 on their own, while the small differences are split almost evenly in sign. Under a right-skewed population with median zero that pattern is typical, not evidence: the long right tail supplies large magnitudes far more often than the short left tail does, so the signs attached to the largest ranks are not fair coins, E(W+) exceeds 4n(n+1)​ under the null, and the test rejects a true null far more often than α. The user would be “detecting” a shift whose existence the test had assumed away.

    Correction. With skewed differences, use the sign test: S=8 positives out of 10, and under the null that the median difference is zero S∼Binomial(10,21​), with no further assumption — that null needs only P(d>0)=21​. Then P(S≥8)=1024(810​)+(910​)+(1010​)​=102445+10+1​=102456​=1287​≈0.055, two-sided about 0.11: not significant, which is the honest reading of eight positives in ten.

    “Distribution-free” promises only that the null distribution of the statistic can be computed without knowing the population — for the sign test under any continuous distribution with median zero, for the signed-rank test under any distribution symmetric about zero. It does not mean assumption-free, and the assumption a rank test does make is exactly what fixes which null distribution one is entitled to use.

  11. 11.Proof

    Two independent samples have sizes n1​ and n2​, and the null hypothesis is that both come from the same continuous distribution. Let N=(n1​n1​+n2​​) and let T be any statistic computed from the labelled data; assume T takes N distinct values across the N relabellings. The permutation p-value is the proportion of relabellings with T at least as large as the observed Tobs​.

    1. (a)Prove that under the null, P(p≤α)=⌊αN⌋/N for every α∈(0,1). Conclude that the test has level at most α, with equality exactly when αN is an integer, and say precisely what “the permutation test is exact” means in the light of this. Point to the one place the null hypothesis is used.
    2. (b)Show that the smallest attainable one-sided p-value is 1/N. For equal group sizes n1​=n2​=m, find the smallest m for which a one-sided permutation test can reject at α=0.05, and the smallest m for which a two-sided test (with p doubled) can.
    3. (c)Take x=1,2,3 and y=4,5,6 with T=yˉ​−xˉ. Show that the one-sided p-value is exactly 0.05, and then show that the same p-value is obtained if every observation is first replaced by its rank, or if T is replaced by the Mann-Whitney U of the second sample. What does this say about the relationship between rank tests and permutation tests?

    Solution

    (a) Exactness. Under the null the n1​+n2​ pooled observations are independent draws from one distribution, so their joint distribution is unchanged by any permutation of the labels: the observations are exchangeable. This is the only place the null hypothesis enters. Condition on the multiset of pooled values. Given that multiset, each of the N ways of choosing which n1​ values carry the first label has the same conditional probability 1/N, so the observed labelling is a uniform draw from the N relabellings, and Tobs​ is a uniform draw from the N distinct values t(1)​<t(2)​<⋯<t(N)​ that T takes.

    If Tobs​=t(N−k+1)​, the k-th largest value, then exactly k relabellings have T≥Tobs​ and p=k/N. Hence p is uniform on {N1​,N2​,…,1}, and

    P(p≤α)=P(k≤αN)=N#{k∈{1,…,N}:k≤αN}​=N⌊αN⌋​≤α.

    This is the conditional probability given the multiset; since it does not depend on the multiset, it is the unconditional probability too. Equality holds precisely when αN is an integer. ■

    So “exact” means: the rejection probability under the null is known exactly, for every sample size, with no approximation — it is ⌊αN⌋/N, and it equals α whenever α is one of the attainable levels k/N. It does not mean that every α is attainable, and it says nothing about power. Nothing about the form of T was used, which is why any statistic may be permuted.

    (b) The floor. The smallest p occurs when Tobs​ is the largest of the N values, giving p=1/N; no relabelling can have p smaller, since the observed one always counts. For n1​=n2​=m, N=(m2m​) runs 2,6,20,70,252,… for m=1,2,3,4,5,…

    One-sided at α=0.05 requires N1​≤0.05, i.e. N≥20: m=2 gives N=6 and fails, m=3 gives N=20 and succeeds, with p=201​=0.05 exactly. So m=3 is the smallest, and only the single most extreme relabelling rejects.

    Two-sided with p doubled requires N2​≤0.05, i.e. N≥40: m=3 fails and m=4 gives N=70, p=702​=351​≈0.029. So m=4 is the smallest.

    (c) The example. The pooled values are 1,…,6 and N=(36​)=20. Since yˉ​−xˉ=3(21−s)−s​=321−2s​ where s is the first group's sum, T is largest when s is smallest, and the observed labelling {1,2,3} has the smallest possible sum s=6. It is the unique relabelling with T≥Tobs​, so p=201​=0.05, exactly the floor from (b).

    Replacing values by ranks. The values 1,…,6 are their own ranks, so nothing changes and p=201​. More generally, replacing observations by ranks is a strictly increasing transformation, and under it the ordering of relabellings by any statistic that is monotone in the group sum is preserved whenever, as here, the observed group holds the n1​ smallest values — that relabelling is the unique extreme one before and after ranking.

    Replacing T by U. With W the rank sum of the second sample, Uy​=W−2n2​(n2​+1)​=(4+5+6)−6=9, which equals n1​n2​=9, the maximum possible: every y exceeds every x. Across relabellings Uy​ is a strictly increasing function of the second group's rank sum, hence a strictly decreasing function of s, so it orders the 20 relabellings exactly as T does, and again exactly one relabelling is at least as extreme: p=201​.

    The lesson. The Mann-Whitney test is a permutation test — the permutation test whose statistic is the rank sum, applied to the ranks. Its tabulated null distribution is precisely the permutation distribution of W over the N relabellings, which is why it is the same for every continuous population: ranking has already removed the data's values, so the enumeration can be done once. A permutation test on the raw values keeps the magnitudes and can use any statistic, at the price of redoing the enumeration for each data set. Both are exact for the same reason, exchangeability under the null; they differ in what they throw away, and hence in power against particular alternatives.

  12. 12.Computation

    A sample of three values, 1, 3, 8, is to be bootstrapped. Rather than simulate, enumerate: treat a resample as three independent draws, each uniform on {1,3,8}, and compute the bootstrap distribution exactly.

    1. (a)How many ordered resamples are there, and how many distinct resamples if order is ignored? What is the probability that a resample contains all three distinct values?
    2. (b)Find the exact bootstrap distribution of the resample median — the probability that it equals 1, 3 and 8 — and check that the three probabilities sum to one.
    3. (c)Compute the bootstrap mean of the median and the bootstrap standard error of the median, both exactly.
    4. (d)Give the 95% percentile interval for the median and explain what it reveals about bootstrapping a median from three observations. Then show, without enumerating, that the bootstrap standard error of the mean is exactly 326​​, and say why that statistic behaves better.

    Solution

    (a) Counting. Each of the three positions takes one of three values, so there are 33=27 equally likely ordered resamples. Ignoring order, a resample is a multiset of size 3 from 3 types, of which there are (33+3−1​)=(35​)=10 — but these are not equally likely. A resample contains all three distinct values in 3!=6 of the 27 orderings, so the probability is 276​=92​; the other 97​ of resamples repeat at least one observation, which is what makes sampling with replacement produce any variation at all.

    (b) The median. The resample median is the middle value of the three draws.

    The median is 1 exactly when at least two of the three draws are 1: two of them, (23​)(31​)232​=276​, or all three, (31​)3=271​. So P(median=1)=277​, and by the same count P(median=8)=277​.

    The median is 3 in the remaining cases — at least two 3s (277​ again) or all three values distinct (276​, from (a)), which are disjoint — giving P(median=3)=2713​.

    Check: 277+13+7​=1. ✓

    (c) Moments of the bootstrap median. Writing M∗ for the resample median,

    E(M∗)=277⋅1+13⋅3+7⋅8​=277+39+56​=27102​=934​,

    E(M∗2)=277⋅1+13⋅9+7⋅64​=277+117+448​=27572​.

    Hence

    Var(M∗)=27572​−(934​)2=811716​−811156​=81560​,

    and the bootstrap standard error of the median is

    SE∗=81560​​=916⋅35​​=9435​​≈2.63.

    Note that the bootstrap mean 934​≈3.78 is above the observed median 3: the resampling distribution has inherited the right skew of the data, since a resample that picks up the 8 twice moves the median much further than one that picks up the 1 twice.

    (d) The percentile interval. The bootstrap distribution has only three atoms. Its cumulative probabilities are P(M∗≤1)=277​≈0.26 and P(M∗≤3)=2720​≈0.74. The 2.5% quantile is the smallest value with cumulative probability at least 0.025, which is 1; the 97.5% quantile is the smallest value with cumulative probability at least 0.975, which is 8. The 95% percentile interval is [1,8] — the entire range of the data. Indeed every percentile interval wider than the middle 48% is [1,8]: the distribution is far too coarse to yield anything else. The bootstrap has not manufactured information three observations do not contain; a resample median is always one of the observed values, so with tiny n the bootstrap distribution of the median is a handful of points and its quantiles are crude.

    The mean, without enumeration. A resample mean is the average of three independent draws from the empirical distribution, which puts mass 31​ on each of 1,3,8. That distribution has mean 4 and variance

    3(1−4)2+(3−4)2+(8−4)2​=39+1+16​=326​,

    so the variance of the average of three independent draws is 326​⋅31​=926​ and

    SE∗(xˉ∗)=326​​≈1.70.

    This is just σ^/n​ with the divisor-n standard deviation — the bootstrap reproduces the textbook formula because the mean is linear in the data. The mean behaves better as a bootstrap target because it varies continuously with the resample: the 27 resamples give many distinct means spread smoothly over the range, whereas the median jumps between three values. The same reasoning is why a trimmed mean bootstraps more smoothly than a median at small n.

← Back to the question sheet

CalcPath·Free university mathematics

SubjectsProblem setsProgressFeedbackAbout