Please note that the median test is considered obsolete by many, because of its very low power. See the reference below. -Frank

@Article{fri00sho,
  author =               {Freidlin, Boris and Gastwirth, Joseph L.},
  title =                {Should the median test be retired from general use?},
  journal =      The American Statistician,
  year =                 2000,
  volume =               54,
  number =               3,
  pages =                {161-164},
  annote =               {inefficiency of Mood median test}
}


On 05/27/2010 10:20 AM, Joshua Wiley wrote:
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.p...@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@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.






--
Frank E Harrell Jr   Professor and Chairman        School of Medicine
                     Department of Biostatistics   Vanderbilt University

______________________________________________
R-help@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.

Reply via email to