[Rd] possible minor bug in fisher.test

From: Fay, Michael (NIH/NIAID) [E] <mfay_at_niaid.nih.gov>
Date: Wed, 20 Apr 2011 15:30:15 -0400


 I received a bug report for my exact2x2 package that seems to apply to fisher.test in the stats package also.

Here is some code which creates the error:

> y<-factor(c(1,1,1),levels=c(0,1))
> fisher.test(x,y)

Error in fisher.test(x, y) : 'x' and 'y' must have at least 2 levels

The help says that x and y could be factors, and technically y does have 2 levels, although both are not observed. There is no problem statistically with y not having 2 observed levels, and

> fisher.test(table(x,y))

Produces the correct p-value of 1 and no errors.

There is an easy solution. In fisher.test replace

        x <- factor(x[OK])
        y <- factor(y[OK])


        x <- as.factor(x[OK])
        y <- as.factor(y[OK])

(similar to how it is done in mcnemar.test).


Michael P. Fay, PhD
Mathematical Statistician
National Institute of Allergy and Infectious Diseases Tel: 301-451-5124 Fax:301-480-0912 (U.S. postal mail address)
6700B Rockledge Drive MSC 7609
Bethesda, MD 20892-7609
(Overnight mail address)
6700-A Rockledge Drive, Room 5133
Bethesda, MD 20817

The information in this e-mail and any of its attachment...{{dropped:11}}

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 20 Apr 2011 - 19:32:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Apr 2011 - 23:20:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive