# [R] median test

Joshua Wiley jwiley.psych at gmail.com
Fri May 28 18:03:34 CEST 2010

```On Fri, May 28, 2010 at 6:58 AM, linda Porz <linda.porz at gmail.com> wrote:
> Hello,
>
> I can't have different data these data came from mice that have lived under
> certain condition in the lab! I have just read the mentioned publication
> "Should the median test be retired from general use?" It says in the
> conclusion "If one felt that the data could not come from a Cauchy or slash
> distribution, the Wilcoxon should be used."! What is this? Is there is any
> test in R for a Cauchy or slash distribution? Can I used the unpaired
> Wilcoxon, or I have a Cauchy distributed data?

**Disclaimer: I have no idea what your data represents or how
(in)appropriate any of these tests may be**

R can do the tests you mentioned (and many more).

Wilcoxon test:
wilcox.test(x=group1, y=group2, paired=FALSE)
see ?wilcox.test

For testing the distribution look at:
?ks.test and ?pcauchy
The code might be something along the lines of:
ks.test(x=yourdata, y="pcauchy")

Again I want to stress that you should know your data and what tests
you are doing and why you are doing them.  R will do just about
whatever you want, including many things that you probably should not
do.

Josh

>
> Many thanks,
> Linda
>
> 2010/5/27 Joshua Wiley <jwiley.psych at gmail.com>
>>
>> Hello Linda,
>>
>> The "problem" is actually the median of your data.  What the function
>> median.test() does first is combine both groups.  Look at this:
>>
>> median(c(group1, group2))
>>
>> the median is 1, but the lowest value of the groups is also 1.  So
>> when the function does the logical check z < m where z = c(group1,
>> group2) and m is the median, there are no values that are less than
>> the median value.  Therefore there is only 1 level, and the fisher
>> test fails.
>>
>> You would either need different data or adjust the function to be:
>>
>> fisher.test(z <= m, g)\$p.value
>>
>> that way it's less than or equal to the median.
>>
>> Hope that helps,
>>
>> Josh
>>
>> On Thu, May 27, 2010 at 7:24 AM, linda Porz <linda.porz at gmail.com> wrote:
>> > Hi all,
>> >
>> > I have found the following function online
>> >
>> > median.test<-function(y1,y2){
>> >  z<-c(y1,y2)
>> >  g <- rep(1:2, c(length(y1),length(y2)))
>> >  m<-median(z)
>> >  fisher.test(z<m,g)\$p.value
>> > }
>> >
>> > in
>> >
>> > http://www.mail-archive.com/r-help@r-project.org/msg95278.html
>> >
>> > I have the following data
>> >
>> >> group1 <- c(2, 2, 2, 1, 4, 3, 1, 1)
>> >> group2 <- c(3, 1, 3, 1, 4, 1, 1, 1, 7, 1, 1, 1, 1, 1, 2)
>> >> median.test(w1,group1)
>> > [1] 1
>> >> median.test(group1,group2)
>> > Error in fisher.test(z < m, g) : 'x' and 'y' must have at least 2 levels
>> >
>> > I am very thankful in advance for any suggestion and help.
>> >
>> > Regards,
>> > Linda
>> >
>> >        [[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.
>> >
>>
>>
>>
>> --
>> Joshua Wiley
>> Senior in Psychology
>> University of California, Riverside
>> http://www.joshuawiley.com/
>
>

--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

```