Hi,

 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:

>x<-factor(c(0,1,1),levels=c(0,1))
> 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])


with

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

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


Mike


******************************************************************
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
http://www3.niaid.nih.gov/about/organization/dcr/BRB/staff/michael.htm
**********************************************************************
Disclaimer:
The information in this e-mail and any of its attachment...{{dropped:11}}

