2

I am trying to perform paired Mann Whitney U tests. My samples for each test are very different and by the t.test do produce different results, but the results are identical for the MW test. By contrast the default settings for the MW test work just fine and do give different results. Any ideas? Attached is code which contains a sample of my overall data and the test function. The t.test is included to show that different results are produced by the test:

x1 <- c(26.33323, 26.69508, 26.25390, 18.78399, 24.11386, 23.94950, 
23.77843, 21.09932, 17.71425, 19.03429, 20.01796, 19.86626, 12.84303)
x2 <- c(20.82535, 20.27921, 17.99138, 10.40184, 23.23184, 22.56530, 
18.69153, 18.33580, 13.83343, 18.22934, 15.21738, 10.07495, 9.93721)

y1 <- c(169.73751, 134.85579, 122.62475, 67.87308, 110.10757, 125.72300, 
133.87937, 135.56772, 79.41600, 96.92930, 97.92528, 68.62409, 40.21653)
y2 <- c(92.88698, 54.23404, 51.58410, 21.72830, 72.02835, 70.74432, 
69.52055, 89.59934, 49.08684, 79.98573, 50.58707, 22.80362, 22.49185)

wilcox.test(x1, x2, paired = TRUE)
wilcox.test(y1, y2, paired = TRUE)

t.test(x1, x2, paired = TRUE)
t.test(y1, y2, paired = TRUE)
  • Welcome to SO, this isn't really a [minimal example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Can you edit and provide just the vectors you made and the code required to reproduce the error? Asking people to download files is sketchy at best and should only be a last resort sharing option. – Nate Nov 19 '18 at 19:15
  • 1
    Hi Nate. Thanks for the advice about posting. I will certainly follow it in future, and hopefully here! I have amended my post accordingly. – Joe Flannery Sutherland Nov 19 '18 at 19:30
  • the R function `wilcox.test()` is called different tests under the hood so you are getting different results. This is described in the details section of `?wilcox.test`. When `x` and `y` are given with `paired = TRUE` a [Wilcoxon signed rank test](https://en.wikipedia.org/wiki/Wilcoxon_signed-rank_test) is performed test if the two samples are from the same distribution. When `paired = FALSE` a [Wilcoxon rank sum test](https://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U_test) is performed testing if the difference in means between the two samples is equal to `mu` (which defaults to 0). – Nate Nov 19 '18 at 20:04
  • So they are very similar but employ different formulas, if you want a deeper dive into the math [CrossValidated](https://stats.stackexchange.com/questions) is the place for you! – Nate Nov 19 '18 at 20:04
  • Thanks for the clarification, I didn't realise they were separate kinds of tests. My tests have to be paired, however, due to the nature of the samples. I'm still unsure as to why each pair of vectors, which are different to each other and the other pairs, all produce the same result with paired = TRUE (U = 91, p = 0.0002441). Something must still be going wrong somewhere right? – Joe Flannery Sutherland Nov 19 '18 at 23:11

1 Answers1

0

No the test is performing as expected. Maybe seeing the arithmatic in R of wilcox.test will help.

From the Wikipedia page example here are the steps of wilcox.text(x, y, paired = TRUE) or a Wilcoxon signed rank test:

# calculate pair-wise differences
x_diffs <- x1 - x2 
y_diffs <- y1 - y2

# rank them
x_ranks <- rank(x_diffs)
y_ranks <- rank(y_diffs)

# adjust ranks by the original sign of each difference
x_ranks_signed <- rank(x_diffs) * sign(x_diffs)
y_ranks_signed <- rank(y_diffs) * sign(y_diffs)

# sum them for the test statistic
sum(x_ranks_signed)
sum(y_ranks_signed)

In your example both of the 2 values are smaller than the 1 values so no ranks get multiplied by -1, since all of the deltas are positive numbers. Since both x and y are the same length 13, you correctly get the same test statistic 91 or sum(1:13) for both tests.

To get a different test statistic you would need to introduce some negative delta values, ie making x3 bigger than x1.

x3 <- c(28, 29, 17.99138, 10.40184, 23.23184, 22.56530, 
        18.69153, 18.33580, 13.83343, 18.22934, 15.21738, 10.07495, 9.93721)

wilcox.test(x1, x2, paired = T) # same old test statistic and p-value

    Wilcoxon signed rank test

data:  x1 and x2
V = 91, p-value = 0.0002441
alternative hypothesis: true location shift is not equal to 0

wilcox.test(x1, x3, paired = T) # new negative deltas >> new test stat and new p-value

    Wilcoxon signed rank test

data:  x1 and x3
V = 82, p-value = 0.008057
alternative hypothesis: true location shift is not equal to 0
Nate
  • 10,361
  • 3
  • 33
  • 40