[R] median of two groups
Thomas Lumley
tlumley at u.washington.edu
Wed Apr 7 18:33:52 CEST 2010
On Wed, 7 Apr 2010, cheba meier wrote:
> Dear Thomas,
>
> Thank you very much for your answer! Can I use your function in my analysis?
Sure.
> The wilcox.test() tests the differences in average ranks (H0: F(X)=F(Y)),
> why then do people in many studies compare t.test() with wilcox.test()?
The Wilcoxon test is slightly more complicated than difference in average ranks. The null hypothesis is actually that P(X>Y)=0.5, in the sense that if this hypothesis is true the test will not reject even for arbitrarily large sample sizes. However, because the test has truly weird behaviour when comparing arbitrary distributions, it's really not useful unless you have good reason to expect stochastic ordering, that is, the entire distribution is shifted up or down (though not necessarily by the same amount).
One reason that people compare t-tests and Wilcoxon tests is that a lot of the elegant statistical theory for two-sample testing is for location-shift alternatives, that is, for situations where you know the two distributions are the same shape but don't know if one of them is shifted up or down relative to the other. If you happen to know that the distributions are the same shape then all the tests are asking the same scientific question, so comparing them makes sense.
Now, in reality we never know that we have a location-shift alternative. It's still reasonable to hope that some of the lessons learned from studying location-shift alternatives still apply (some do, some don't), even if you do understand that reality is more complex. On the other hand, some people either don't know that reality is more complex or want to pretend it isn't.
A few years ago I gathered up ten introductory statistics and biostatistics textbooks that I and colleagues had to hand, to see what they had to say about the Wilcoxon test. If I recall correctly, eight of them said something that was both untrue and importantly misleading. Of the remaining two, one didn't mention the Wilcoxon test.
-thomas
> This makes sometime people like me a bit confused!
>
> Regards,
> Cheba
>
> 2010/4/6 Thomas Lumley <tlumley at u.washington.edu>
>
> None of them.
>
> - mood.test() looks promising until you read the help page and
> see that it does not do Mood's test for equality of quantiles,
> it does Mood's test for equality of scale parameters.
> - wilcox.test() is not a test for equal medians
> - ks.test() is not a test for equal medians.
>
>
> Mood's test for the median involves dichotomizing the data at
> the pooled median and then doing Fisher's exact test to see if
> the binary variable has the same mean in the two samples.
>
> median.test<-function(x,y){
> z<-c(x,y)
> g <- rep(1:2, c(length(x),length(y)))
> m<-median(z)
> fisher.test(z<m,g)$p.value
> }
>
> Like most exact tests, it is quite conservative at small sample
> sizes.
>
> -thomas
>
>
> On Tue, 6 Apr 2010, cheba meier wrote:
>
> Dear all,
>
> What is the right test to test whether the median of two groups
> are
> statistically significant? Is it the wilcox.test, mood.test or
> the ks.test?
> In the text book I have got there is explanation for the
> Wilcoxon (Mann
> Whitney) test which tests ob the two variable are from the same
> population
> and also ks.test!
>
> Regards,
> Cheba
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible
> code.
>
>
> Thomas Lumley Assoc. Professor, Biostatistics
> tlumley at u.washington.edu University of Washington, Seattle
>
>
>
>
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list