2
$\begingroup$

I am fairly new to stats and have read up on the Mann-Whitney U-test but I still am facing an issue I can't resolve. I have two independent samples:

a = (110, 115, 128, 142, 123, 129, 130, 128 ,134, 133, 128, 147, 137, 112, 138, 128, 132, 139, 133, 135, 133, 125, 134, 139, 138, 142, 152, 140, 144, 147 ,153 ,141)
b = (122, 118, 120 ,131 ,124 ,118 ,120 ,140 ,124, 120, 134, 127, 127 ,134, 133, 137 ,137 ,135 ,129 ,138 ,143, 128 ,121 ,129, 133, 138, 142, 131, 135, 132, 146, 135)

The null hypothesis states that a and b have similar distributions (or rather medians). When individually tested, I get a p-value(0.106) higher than 0.05, which indicates I should accept my null hypothesis. But on manual checking, it shows the medians are different. Following is the code:

>a = c(110, 115, 128, 142, 123, 129, 130, 128 ,134, 133, 128, 147, 137, 112, 138, 128, 132, 139, 133, 135, 133, 125, 134, 139, 138, 142, 152, 140, 144, 147 ,153 ,141)
>b = c(122, 118, 120 ,131 ,124 ,118 ,120 ,140 ,124, 120, 134, 127, 127 ,134, 133, 137 ,137 ,135 ,129 ,138 ,143, 128 ,121 ,129, 133, 138, 142, 131, 135, 132, 146, 135

>wilcox.test(a,b)
Wilcoxon rank sum test with continuity correction

data:  c and d
W = 632.5, p-value = 0.1067
alternative hypothesis: true location shift is not equal to 0

I am not sure why this is happening. Any help is appreciated. Thanks!

$\endgroup$
  • $\begingroup$ You have to rank the pooled data and then see if the samples are intertwined or not. $\endgroup$ – Michael R. Chernick May 5 '17 at 2:46
  • $\begingroup$ Are you asking "what is the difference between descriptive and inferential statistics?" $\endgroup$ – Michael M May 5 '17 at 6:56
  • $\begingroup$ 1. The Mann-Whitney is not a test for equality of medians. 2. a null hypothesis should not contain the word "similar" (also note that it's a specific statement about one or more populations). 3. Failure to reject does not imply the sample quantities the test actually compares would be identical (so even if it were a test of medians, the sample medians could differ and it would not automatically imply that the test should reject). $\endgroup$ – Glen_b -Reinstate Monica May 5 '17 at 8:30
3
$\begingroup$

I am not sure whether the following will address your question, but here it goes... a and b presumably are independent. If you run histograms and overlap them you get the following:

enter image description here

which suggest overlap between the values of both vectors. You can get the same impression running

> summary(a)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  110.0   128.0   134.0   134.0   140.2   153.0 
> summary(b)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  118.0   124.0   131.5   130.7   135.5   146.0 

And this is why you can't reject the null hypothesis which follows from the definition in Wikipedia:

In statistics, the Mann–Whitney U test (also called the Mann–Whitney–Wilcoxon (MWW), Wilcoxon rank-sum test, or Wilcoxon–Mann–Whitney test) is a nonparametric test of the null hypothesis that it is equally likely that a randomly selected value from one sample will be less than or greater than a randomly selected value from a second sample.

Under the null hypothesis $\text{H}_0$, the probability of an observation from the population $X$ exceeding an observation from the second population $Y$ equals the probability of an observation from $Y$ exceeding an observation from $X$.

The test statistic produced by R's wilcox.text()

> wilcox.test(a,b)

    Wilcoxon rank sum test with continuity correction

data:  a and b
W = 632.5, p-value = 0.1067
alternative hypothesis: true location shift is not equal to 0

of $632.5$ can be reproduced manually as

> n1 = length(a)
> n2 = length(b)
> d = data.frame(a,b)
> d = stack(d)
> pooled = d[order(d$values),]
> pooled$ranks = rank(pooled$values)
> (R1 = sum(pooled[pooled$ind == "a", "ranks"]))
[1] 1160.5
> (R2 = sum(pooled[pooled$ind == "b", "ranks"]))
[1] 919.5
> (U1 = R1 - n1 * (n1 + 1) / 2)
[1] 632.5
> (U2 = R2 - n2 * (n2 + 1) / 2)
[1] 391.5
> (U = max(U1, U2))
[1] 632.5

Surprisingly R seems to pick the maximum value of the adjusted rank sums for both groups, whereas the minimum value is typically chosen. This is likely anecdotal since the sum of all unadjusted ranks $R_1 + R_2 = \frac{N(N+1)}{2}$ with $N$ being the total number of observations.

$\endgroup$
  • 1
    $\begingroup$ I realised I forgot to thank you for your answer... Your explanation helped me. Thank you :) $\endgroup$ – user2330778 Aug 2 '17 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.