# [R] median of two groups

Bert Gunter gunter.berton at gene.com
Fri May 7 22:07:19 CEST 2010

```Perhaps this might help clarify:

sample A:   10   15   20
sample B:   12   15   22

Median of sample A = 15; median of sample B = 15. Sample medians are =.
But: B-A differences are 2,0,2 with a median of 2. So the median difference
does not equal the difference of the medians.

Clarity in what you wish to test (and why!) is essential to determine how.

Bert Gunter
Genentech Nonclinical Statistics

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of cheba meier
Sent: Friday, May 07, 2010 12:46 PM
To: Joris Meys
Cc: R-help at r-project.org; Thomas Lumley
Subject: Re: [R] median of two groups

Hi all,

if done properly! What does this mean? The R-code I have is using the
R-function sample without replacement. Am I doing this properly?

median of the differences is zero! Does this mean if I run 1000 permutation
and for each permutation I compute the median difference and as a result I
have 1000 differences. Is the the H0: median(1000 differences) =0? If yes,
which conclusion one would have from this H0?

Best wishes,
Cheba

2010/5/7 Joris Meys <jorismeys at gmail.com>

> depends on how you interprete "absolute median difference". Is that the
> absolute difference of the medians, or the median of the absolute
> differences. Probably the latter one, so you would be right. If it's the
> former one, then it is testing whether the difference of the medians is
> zero.
>
> Cheers
> Joris
>
>
> On Fri, May 7, 2010 at 6:52 PM, Thomas Lumley
<tlumley at u.washington.edu>wrote:
>
>> On Fri, 7 May 2010, cheba meier wrote:
>>
>>  Dear Thomas,
>>>
>>> I have been running simulations in order me to understand this problem!
I
>>> have found something online where the absolute median difference is
>>> computed
>>> and permutations are ran to compute a p-value. Is such a test (if I can
>>> call
>>> it a test) tests the null hypothesis that median group 1 = median group
>>> 2?
>>>
>>
>> No, that is testing whether the median of the differences is zero.  This
>> is not the same as testing whether the difference of the medians is zero.
>>
>>    -thomas
>>
>>
>>
>>>
>>> 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
>>>>> 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
>>>>
>>>>
>>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> 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
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Joris Meys
> Statistical Consultant
>
> Ghent University
> Faculty of Bioscience Engineering
> Department of Applied mathematics, biometrics and process control
>
> B-9000 Gent
>
> tel : +32 9 264 59 87
> Joris.Meys at Ugent.be
> -------------------------------
> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>

[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help