[R] help comparing two median with R

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Apr 17 14:03:09 CEST 2007


On Tue, 17 Apr 2007, Robert McFadden wrote:

>
>
>> -----Original Message-----
>> From: r-help-bounces at stat.math.ethz.ch
>> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Jim Lemon
>> Sent: Tuesday, April 17, 2007 12:37 PM
>> To: Pedro A Reche
>> Cc: r-help at stat.math.ethz.ch
>> Subject: Re: [R] help comparing two median with R
>>
>> Pedro A Reche wrote:
>>> Dear R users,
>>> I am new to R and  I would like to ask your help with the following
>>> topic. I have three sets of numeral data, 2 sets are paired and a
>>> third is independent of the other two. For each of these sets I have
>>> obtained their basic statistics (mean, median, stdv, range ...).
>>> Now I want to compare if these sets differ. I could compare
>> the mean
>>> doing a basic T test . However, I was looking for a test to compare
>>> the medians using R.   If that is possible I would love to
>> hear the
>>> specifics.
>>
>> Hi Pedro,
>> You can use the Mann-Whitney test ("wilcox" with two
>> samples), but you would have to check that the second and
>> third moments of the variable distributions were the same, I think.
>>
>> Jim

> Use Mann-Whitney U test, but remember about 2 assumption:
> 1. samples come from continuous distribution (there are no tied
> obserwations)
> 2. distributions are identical in shape. It's very similar to t-test but
> Mann-Whitney U test is not as affected by violation of the homogeneity of
> variance assumption as t-test is.

Sorry, the other way round, as in R the (Welch)unequal-variance t test is 
the default, so it makes no 'homogeneity of variance assumption'.  The 
Wilcoxon/Mann-Whitney test is sensitive to differences in shape, in rather 
complex ways, more so than t.test. (I've posted simulated comparisons here 
in the past.)

I don't think anyone is answering the question here.  If the distributions 
are identical in shape, the Wilcoxon/Mann-Whitney test is measuring 
differences in means, medians ... (they are all the same), and if they are 
not, it is not measuring differences in medians.

To test specifically for a difference in medians, you can do almost the 
same thing as the Welch two-sample t-test, but use estimates of the 
asympototic standard errors of the medians (for which you will need
density estimates at the medians).

But I can only see this as being worth doing where the median is of 
substantive interest (as it could just be for lifetime distributions), and 
statistical significance is of importance (rather than useful 
improvement).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list