CS计算机代考程序代写 1

1

-Sum Test, also known as the Mann-Whitney test

• Rank the data. That is, replace the data values by their ranks, from smallest
to largest. For example, the pH samples are:

Loc
1 8.53 8.52 8.01 7.99 7.93 7.89 7.85 7.82 7.80
2 7.85 7.73 7.58 7.40 7.35 7.30 7.27 7.27 7.23

are replaced by the ranks

Loc
1 18 17 16 15 14 13 11.5 10 9
2 11.5 8 7 6 5 4 3 2 1

The tied values (7.85, 7.85) would have had ranks 11 and 12 were they slightly
different. In the case of ties, assign the “mid-rank” [here (11+12)/2] to both
values.

• Calculate W , which is the sum of the ranks in the first group. In this case,
W = 123.5.

• In small samples we compare W to the distribution of values of W under all
possible allocations of the ranks to the two samples.

• In larger samples we use a normal approximation to this distribution.

• Let n1 be the number of observations in the first group, n2 the number in the
second group, and N = n1 + n2. Here n1 = n2 = 9 and N = 18.

• Under the null hypothesis that the two distributions are the same, the mean
and variance of W are

µW = n1(N + 1)/2

and
σ2W = n1n2(N + 1)/12

• the observed value of the test statistic is

Zobs =
W − µW

σW
=

(123.5− 9× 19/2)√
9× 9× 19/12

= 3.355

• As with the permutation test, the null hypothesis is that the population dis-
tributions are the same, and the two sided alternative is that the distributions
are different.

2

• The hypotheses can also be written in terms of means. Where µ1 and µ2 are
the means of the two populations, the null hypothesis is H0 : µ1 = µ2. The
possible alternatives and p-values are:

HA p-value

µ1 6= µ2 2P (Z > |Zobs|)
µ1 > µ2 P (Z > Zobs)
µ1 < µ2 P (Z < Zobs) • For example, with the two sided alternative, the p-value is 2P (Z > |3.355|) = 2(.0004) = .0008

3

Comparison of Wilcoxon, Permutation
and t-tests

• What p-value did the permutation test give in this case?
The test statistic for the permutation test was |X̄1 − X̄2| = 0.595556.

With a two sided alternative, there were


 18

9


 = 48620 possible arrangements

of the data into two groups of size 9, of which 8 gave at least as much evidence
against H0 as did the value 3.335. Hence the p-value for the permutation test
was
P = 8/48620 = .0002.

• The p-value for the pooled t-test was 0.0002.

• In this case, the Wilcoxon, permutation and t-tests all show very strong evidence
against the null hypothesis of equal distributions.

• Typically, the p-values for the permutation and Wilcoxon test will be fairly
close if the sample size is moderately large.

• If the data are approximately normally distributed and the assumption of equal
variances holds, the p-value for the pooled t-test will be fairly close to those for
the Wilcoxon and permutation tests.

4

another example: n1 = n2 = 3 with data

Treatment 175 250 260
Control 255 275 300

• The treatment ranks are 1,2,4.

• The control ranks are 3,5,6.

• The sum of the treatment ranks is W = 7.

• In this case is it possible to consider all possible permutations of the ranks
between the two samples

1 2 3 4 5 6 W

1 1 1 2 2 2 6
1 1 2 1 2 2 7 = Wobs
1 1 2 2 1 2 8
1 1 2 2 2 1 9
1 2 1 2 2 1 10
1 2 1 2 1 2 9
1 2 1 1 2 2 8
1 2 2 1 1 2 10
1 2 2 2 1 1 12
1 2 2 1 2 1 11
2 1 1 1 2 2 9
2 1 1 2 1 2 10
2 1 1 2 2 1 11
2 1 2 1 1 2 11
2 1 2 1 2 1 12
2 1 2 2 1 1 13
2 2 1 1 1 2 12
2 2 1 1 2 1 13
2 2 1 2 1 1 14
2 2 2 1 1 1 15

5

• The distribution of W under Ho is summarized in the table below

W 6 7 8 9 10 11 12 13 14 15
Prob 1

20
1
20

2
20

3
20

3
20

3
20

3
20

2
20

1
20

1
20

• The probability of getting a value for W as small or smaller than Wobs = 7
is 2/20, and the probability of getting a value as extreme or more extreme is
P = 4/20 = .2

• Under the null hypothesis, the mean of W is 3 × 7/2 = 10.5 and the variance
of W is 3× 3× 7/12 = 5.25.

• Using the normal approximation to the null distribution of W , the observed
test statistic is
Zobs = (7− 10.5)/


5.25 = −1.53.

• With the two sided alternative, the p-value is

2P (Z > | − 1.53|) = 2P (Z > 1.53) = 2(.063) = .126

• Even with such small samples, the two approaches give quite similar answers.