median of two groups

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

median of two groups

cheba meier
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Thomas Lumley


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]]
>
> ______________________________________________
> [hidden email] 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
[hidden email] University of Washington, Seattle

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

cheba meier
Dear Thomas,

Thank you very much for your answer! Can I use your function in my analysis?

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()?
This makes sometime people like me a bit confused!

Regards,
Cheba

2010/4/6 Thomas Lumley <[hidden email]>

>
> 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]]
>>
>> ______________________________________________
>> [hidden email] 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
> [hidden email]        University of Washington, Seattle
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Thomas Lumley
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 <[hidden email]>
>
>       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]]
>
> ______________________________________________
> [hidden email] 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
> [hidden email]        University of Washington, Seattle
>
>
>
>
Thomas Lumley Assoc. Professor, Biostatistics
[hidden email] University of Washington, Seattle

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

cheba meier
In reply to this post by Thomas Lumley
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?

Thank you in advance for your help.

Regards,
Cheba

2010/4/6 Thomas Lumley <[hidden email]>

>
>
> 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]]
>>
>> ______________________________________________
>> [hidden email] 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
> [hidden email]        University of Washington, Seattle
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Joris FA Meys
That's a robust way of obtaining a p-value, and can be classified as a test.
The important trick here is to take into account that you have two tails in
a distribution. If the p-value is calculated taking both tails into account,
then it indeed tests the null hypothesis that median group1 - median group2
= 0 (which is equivalent to median group1 = median group2).

Cheers
Joris

On Fri, May 7, 2010 at 2:00 PM, cheba meier <[hidden email]>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?
>
> Thank you in advance for your help.
>
> Regards,
> Cheba
>
> 2010/4/6 Thomas Lumley <[hidden email]>
>
> >
> >
> > 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]]
> >>
> >> ______________________________________________
> >> [hidden email] 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
> > [hidden email]        University of Washington, Seattle
> >
> >
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
[hidden email]
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Greg Snow-2
In reply to this post by cheba meier
Permutation tests are real tests (if done properly), but one subtle but important note:  The null hypothesis being tested is that the 2 distributions are identical, the medians being equal is part of that, but the null includes more than just that assumption.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of cheba meier
> Sent: Friday, May 07, 2010 6:01 AM
> To: Thomas Lumley
> Cc: [hidden email]
> Subject: Re: [R] median of two groups
>
> 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?
>
> Thank you in advance for your help.
>
> Regards,
> Cheba
>
> 2010/4/6 Thomas Lumley <[hidden email]>
>
> >
> >
> > 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]]
> >>
> >> ______________________________________________
> >> [hidden email] 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
> > [hidden email]        University of Washington, Seattle
> >
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Thomas Lumley
In reply to this post by cheba meier
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


> Thank you in advance for your help.
>
> Regards,
> Cheba
>
> 2010/4/6 Thomas Lumley <[hidden email]>
>
>>
>>
>> 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]]
>>>
>>> ______________________________________________
>>> [hidden email] 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
>> [hidden email]        University of Washington, Seattle
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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
[hidden email] University of Washington, Seattle

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Joris FA Meys
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 <[hidden email]>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
>
>
>
>  Thank you in advance for your help.
>>
>> Regards,
>> Cheba
>>
>> 2010/4/6 Thomas Lumley <[hidden email]>
>>
>>
>>>
>>> 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]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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
>>> [hidden email]        University of Washington, Seattle
>>>
>>>
>>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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
> [hidden email]        University of Washington, Seattle
>
> ______________________________________________
> [hidden email] 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.
>



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
[hidden email]
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

cheba meier
Hi all,

Thank you for your reply.

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 <[hidden email]>

> 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 <[hidden email]>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
>>
>>
>>
>>  Thank you in advance for your help.
>>>
>>> Regards,
>>> Cheba
>>>
>>> 2010/4/6 Thomas Lumley <[hidden email]>
>>>
>>>
>>>>
>>>> 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]]
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] 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
>>>> [hidden email]        University of Washington, Seattle
>>>>
>>>>
>>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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
>> [hidden email]        University of Washington, Seattle
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
>
>
> --
> Joris Meys
> Statistical Consultant
>
> Ghent University
> Faculty of Bioscience Engineering
> Department of Applied mathematics, biometrics and process control
>
> Coupure Links 653
> B-9000 Gent
>
> tel : +32 9 264 59 87
> [hidden email]
> -------------------------------
> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Joris FA Meys
On Fri, May 7, 2010 at 9:45 PM, cheba meier <[hidden email]>wrote:

> Hi all,
>
> Thank you for your reply.
>
> 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!

This is only valid if the experiment consists of paired data.


> 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?
>
Nope. the H0 is : median difference = 0
permutation tests run with replacement=F, bootstrapping (which is arguably
the better choice if you can't calculate all permutations)  is done with
replacement = T
# make some data
a <- 1:10
b <- 3:12
x <- c(a,b)
y <- rep(c("a","b"),each=10)

# define function difference of the medians. This can be any function, this
is just for demonstration purposes
med.diff <-function(x,y){
     tmp <- by(x,y,median)
     return(diff(tmp))
}
# bootstrap
med.diff.observed <- med.diff(x,y)  # observed test statistic

n <- 100 # number of bootstraps

boot.samples <- replicate(n,sample(x,replace=T)) # bootstrap samples
med.diff.boot <- apply(boot.samples,2,med.diff,y) # test statistic for
bootstrap samples
med.diff.boot <- scale(med.diff.boot) # centralization for 2-sided testing
pvalue <- mean(abs(med.diff.boot)>=abs(med.diff.observed)) # calculate
proportion of test statistic that is more extreme than the observed
pvalue

I use the central limit theorem in a way, assuming the distribution of the
statistic for the bootstrap sample is symmetric.


> Best wishes,
> Cheba
>
>
>
> 2010/5/7 Joris Meys <[hidden email]>
>
> 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 <[hidden email]>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
>>>
>>>
>>>
>>>  Thank you in advance for your help.
>>>>
>>>> Regards,
>>>> Cheba
>>>>
>>>> 2010/4/6 Thomas Lumley <[hidden email]>
>>>>
>>>>
>>>>>
>>>>> 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]]
>>>>>>
>>>>>> ______________________________________________
>>>>>> [hidden email] 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
>>>>> [hidden email]        University of Washington, Seattle
>>>>>
>>>>>
>>>>>
>>>>        [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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
>>> [hidden email]        University of Washington, Seattle
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>>
>>
>>
>> --
>> Joris Meys
>> Statistical Consultant
>>
>> Ghent University
>> Faculty of Bioscience Engineering
>> Department of Applied mathematics, biometrics and process control
>>
>> Coupure Links 653
>> B-9000 Gent
>>
>> tel : +32 9 264 59 87
>> [hidden email]
>> -------------------------------
>> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>>
>
>


--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
[hidden email]
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Bert Gunter
In reply to this post by cheba meier
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: [hidden email] [mailto:[hidden email]] On
Behalf Of cheba meier
Sent: Friday, May 07, 2010 12:46 PM
To: Joris Meys
Cc: [hidden email]; Thomas Lumley
Subject: Re: [R] median of two groups

Hi all,

Thank you for your reply.

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 <[hidden email]>

> 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
<[hidden email]>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
>>
>>
>>
>>  Thank you in advance for your help.
>>>
>>> Regards,
>>> Cheba
>>>
>>> 2010/4/6 Thomas Lumley <[hidden email]>
>>>
>>>
>>>>
>>>> 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]]
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] 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
>>>> [hidden email]        University of Washington, Seattle
>>>>
>>>>
>>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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
>> [hidden email]        University of Washington, Seattle
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
>
>
> --
> Joris Meys
> Statistical Consultant
>
> Ghent University
> Faculty of Bioscience Engineering
> Department of Applied mathematics, biometrics and process control
>
> Coupure Links 653
> B-9000 Gent
>
> tel : +32 9 264 59 87
> [hidden email]
> -------------------------------
> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

cheba meier
Thank you very much for that.

What is then if I have unpaired and unbalanced samples?

Best regards,
Cheba

2010/5/7 Bert Gunter <[hidden email]>

> 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: [hidden email] [mailto:[hidden email]]
> On
> Behalf Of cheba meier
> Sent: Friday, May 07, 2010 12:46 PM
> To: Joris Meys
> Cc: [hidden email]; Thomas Lumley
> Subject: Re: [R] median of two groups
>
> Hi all,
>
> Thank you for your reply.
>
> 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 <[hidden email]>
>
> > 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
> <[hidden email]>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
> >>
> >>
> >>
> >>  Thank you in advance for your help.
> >>>
> >>> Regards,
> >>> Cheba
> >>>
> >>> 2010/4/6 Thomas Lumley <[hidden email]>
> >>>
> >>>
> >>>>
> >>>> 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]]
> >>>>>
> >>>>> ______________________________________________
> >>>>> [hidden email] 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
> >>>> [hidden email]        University of Washington, Seattle
> >>>>
> >>>>
> >>>>
> >>>        [[alternative HTML version deleted]]
> >>>
> >>> ______________________________________________
> >>> [hidden email] 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
> >> [hidden email]        University of Washington, Seattle
> >>
> >> ______________________________________________
> >> [hidden email] 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.
> >>
> >
> >
> >
> > --
> > Joris Meys
> > Statistical Consultant
> >
> > Ghent University
> > Faculty of Bioscience Engineering
> > Department of Applied mathematics, biometrics and process control
> >
> > Coupure Links 653
> > B-9000 Gent
> >
> > tel : +32 9 264 59 87
> > [hidden email]
> > -------------------------------
> > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
> >
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

Greg Snow-2
Here is a simple example of a permutation test on medians without pairing and different numbers of subjects in each group:

sw <- iris$Sepal.Width[ c(101:130, 51:70) ]
group <- rep( 1:2, c(30,20) )

out <- replicate( 1999, { tmp <- sample(group);
        median(sw[tmp==1]) - median(sw[tmp==2]) } )

out <- c( median(sw[group==1]) - median(sw[group==2]), out )
hist(out)
abline(v=out[1], col='red')
mean( out >= out[1] )


Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of cheba meier
> Sent: Monday, May 10, 2010 3:02 AM
> To: Bert Gunter
> Cc: [hidden email]; Thomas Lumley
> Subject: Re: [R] median of two groups
>
> Thank you very much for that.
>
> What is then if I have unpaired and unbalanced samples?
>
> Best regards,
> Cheba
>
> 2010/5/7 Bert Gunter <[hidden email]>
>
> > 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: [hidden email] [mailto:r-help-bounces@r-
> project.org]
> > On
> > Behalf Of cheba meier
> > Sent: Friday, May 07, 2010 12:46 PM
> > To: Joris Meys
> > Cc: [hidden email]; Thomas Lumley
> > Subject: Re: [R] median of two groups
> >
> > Hi all,
> >
> > Thank you for your reply.
> >
> > 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 <[hidden email]>
> >
> > > 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
> > <[hidden email]>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
> > >>
> > >>
> > >>
> > >>  Thank you in advance for your help.
> > >>>
> > >>> Regards,
> > >>> Cheba
> > >>>
> > >>> 2010/4/6 Thomas Lumley <[hidden email]>
> > >>>
> > >>>
> > >>>>
> > >>>> 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]]
> > >>>>>
> > >>>>> ______________________________________________
> > >>>>> [hidden email] 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
> > >>>> [hidden email]        University of Washington,
> Seattle
> > >>>>
> > >>>>
> > >>>>
> > >>>        [[alternative HTML version deleted]]
> > >>>
> > >>> ______________________________________________
> > >>> [hidden email] 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
> > >> [hidden email]        University of Washington, Seattle
> > >>
> > >> ______________________________________________
> > >> [hidden email] 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.
> > >>
> > >
> > >
> > >
> > > --
> > > Joris Meys
> > > Statistical Consultant
> > >
> > > Ghent University
> > > Faculty of Bioscience Engineering
> > > Department of Applied mathematics, biometrics and process control
> > >
> > > Coupure Links 653
> > > B-9000 Gent
> > >
> > > tel : +32 9 264 59 87
> > > [hidden email]
> > > -------------------------------
> > > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
> > >
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
> >
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: median of two groups

cheba meier
Thank you very much.

These is no statistician where I am! It was clear for me from the previous
email that it is possible to do permutation on the median differences even
if we have unpaired and unbalanced samples. I was only confused about the
null hypothesis ( median difference
or difference of the medians), what Thomas and Bert wrote!

Thank you again and best regards,
Cheba

2010/5/11 Greg Snow <[hidden email]>

> Here is a simple example of a permutation test on medians without pairing
> and different numbers of subjects in each group:
>
> sw <- iris$Sepal.Width[ c(101:130, 51:70) ]
> group <- rep( 1:2, c(30,20) )
>
> out <- replicate( 1999, { tmp <- sample(group);
>        median(sw[tmp==1]) - median(sw[tmp==2]) } )
>
> out <- c( median(sw[group==1]) - median(sw[group==2]), out )
> hist(out)
> abline(v=out[1], col='red')
> mean( out >= out[1] )
>
>
> Hope this helps,
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> [hidden email]
> 801.408.8111
>
>
> > -----Original Message-----
> > From: [hidden email] [mailto:r-help-bounces@r-
> > project.org] On Behalf Of cheba meier
> > Sent: Monday, May 10, 2010 3:02 AM
> > To: Bert Gunter
> > Cc: [hidden email]; Thomas Lumley
> > Subject: Re: [R] median of two groups
> >
> > Thank you very much for that.
> >
> > What is then if I have unpaired and unbalanced samples?
> >
> > Best regards,
> > Cheba
> >
> > 2010/5/7 Bert Gunter <[hidden email]>
> >
> > > 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: [hidden email] [mailto:r-help-bounces@r-
> > project.org]
> > > On
> > > Behalf Of cheba meier
> > > Sent: Friday, May 07, 2010 12:46 PM
> > > To: Joris Meys
> > > Cc: [hidden email]; Thomas Lumley
> > > Subject: Re: [R] median of two groups
> > >
> > > Hi all,
> > >
> > > Thank you for your reply.
> > >
> > > 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 <[hidden email]>
> > >
> > > > 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
> > > <[hidden email]>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
> > > >>
> > > >>
> > > >>
> > > >>  Thank you in advance for your help.
> > > >>>
> > > >>> Regards,
> > > >>> Cheba
> > > >>>
> > > >>> 2010/4/6 Thomas Lumley <[hidden email]>
> > > >>>
> > > >>>
> > > >>>>
> > > >>>> 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]]
> > > >>>>>
> > > >>>>> ______________________________________________
> > > >>>>> [hidden email] 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
> > > >>>> [hidden email]        University of Washington,
> > Seattle
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>        [[alternative HTML version deleted]]
> > > >>>
> > > >>> ______________________________________________
> > > >>> [hidden email] 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
> > > >> [hidden email]        University of Washington, Seattle
> > > >>
> > > >> ______________________________________________
> > > >> [hidden email] 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.
> > > >>
> > > >
> > > >
> > > >
> > > > --
> > > > Joris Meys
> > > > Statistical Consultant
> > > >
> > > > Ghent University
> > > > Faculty of Bioscience Engineering
> > > > Department of Applied mathematics, biometrics and process control
> > > >
> > > > Coupure Links 653
> > > > B-9000 Gent
> > > >
> > > > tel : +32 9 264 59 87
> > > > [hidden email]
> > > > -------------------------------
> > > > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
> > > >
> > >
> > >        [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [hidden email] 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.
> > >
> > >
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.