0

I am writing to ask your opinion on how to interpret this case. I have two vectors "a" and "b" that I am trying to compare.

The wilcoxon test is giving me a pvalue of 5.139217e-303 of a over b with the alternative "greater". Now if I make a summary on each of them I have the following

> summary(a)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
0.0000000 0.0001411 0.0002381 0.0002671 0.0003623 0.0012910 
> summary(c)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
0.0000000 0.0000000 0.0000000 0.0004947 0.0002972 1.0000000

The mean ratio is then around 0.5399031 which naively goes in opposite direction of the wilcoxon test ( I was expecting to find a ratio >> 1)

Even after removing outlier using the outlier package, I still have the same thing. Can someone help me explain why I do have this result and how to explain it ?

Thanks in advance

Rad
  • 989
  • 3
  • 14
  • 31
  • this might be a statistical rather than an R question. Removing outliers should make very little difference, this is a nonparametric rank-based test. The null hypothesis of the Wilcoxon test assumes that the two samples come from the same population; the formally stated alternative hypothesis refers to the difference in medians (not the means), and things could also be odd if the populations differ greatly in variance. Without seeing the data themselves (or at least some more information about the distribution -- histograms?), it's hard to say. – Ben Bolker Sep 19 '12 at 21:35
  • also, note that while `mean_b>mean_a`, `Q1_a>Q1_b` (and indeed `Q1_a>median_b`); Wilcoxon is sensitive to the latter (differences in quantiles, not moments) – Ben Bolker Sep 19 '12 at 21:39

1 Answers1

3

As you haven't posted your data this is indeed a difficult question and posting your data (e.g., via dput() would make things a lot easier. Other than that we can only specify. See here for more on posing a nice question with a reproducible example.

However, your data has some properties we can see from the summary that allows for an answer.

Wilcoxon test does seem to be inappropriate for your data. Remember that Wilcoxon uses the rank of each observation. The rank is difficult to obtain as there are ties in the data. You seem to have a lot of ties (min and median for c are both 0). There are ways to deal with ties, but other methods are better.

As you do seem to not want to use the t-test (reasonable given that the distributions appear to be really different, e.g. median(a) < mean (a) but median(c) > mean(c)) another approach would be to use a permutation test.

My package afex (on CRAN, based on coin) contains the function compare.2.vectors comparing two vectors using (e.g.) t-test, Wilcoxon and most notably permutation test. If your n is small, you can even use a exact test distribution for the permutation test. Given two vectors a and c the result could be (trying to simulate your data):

> require(afex)
> a <- round(runif(100, 0, 0.00129), 5)
> c <- c(rep(0, 60), runif(37, 0, 0.00297), rep(1, 3))
> summary(a)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
0.0000100 0.0002775 0.0006500 0.0006360 0.0009475 0.0012800 
> summary(c)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
0.00000 0.00000 0.00000 0.03054 0.00116 1.00000 

> compare.2.vectors(a,c)
$parametric
   test test.statistic test.value   test.df          p
1     t              t  -1.745388 198.00000 0.08246866
2 Welch              t  -1.745388  99.00094 0.08402002

$nonparametric
             test test.statistic  test.value test.df            p
1 stats::Wilcoxon              W 6772.000000      NA 1.143036e-05
2     permutation              Z   -1.736482      NA 1.929300e-01
3  coin::Wilcoxon              Z    4.389418      NA 0.000000e+00
4          median              Z   -4.514156      NA 0.000000e+00

You see the same pattern, positive test statistics for Wilcoxon, but negative for all other tests. So better not use the Wilcoxon, but one of the other tests, all agreeing.

PS: I am happy for comments on the function. Any more tests that would make sense?

Community
  • 1
  • 1
Henrik
  • 14,202
  • 10
  • 68
  • 91
  • it's nice, but I'm not sure I like the idea of offering a whole variety of tests as a default -- it encourages cherry-picking (although I appreciate that that's not the way you're using it ... in fact the opposite) Maybe make test type a string, with "all" or "all_nonparametric" options for back-compatibility? – Ben Bolker Sep 19 '12 at 22:35
  • 1
    @BenBolker As you see, the function is intended for the purpose of allowing a comparison across tests and **not** cherry picking, hence the default values for `tests` and `coin` arguments to display all. But the question is allowed whether it is a good idea to offer something that may be dangerous (e.g., see the discussions on gun availability in the US or speed limits on German highways). Admittedly I answered the question differently then you in this case. – Henrik Sep 20 '12 at 13:49