[R] hybrid in fisher.test broken?

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Nov 13 23:51:44 CET 2006


Jonathan Dushoff <dushoff at eno.princeton.edu> writes:

> Thank you very much for this useful response.  
> 
> I did a search for fexact both inside R and on R-project.org before
> posting: can somebody tell me where I could have found this information?
> 
> In particular, I am still not clear on whether the Cochran criteria are
> being tested.

You need the actual source for FEXACT for this, then look at the 5th
argument:

    EXPECT  - Expected value used in the hybrid algorithm for
              deciding when to use asymptotic theory
              probabilities.
              (Input)
              If EXPECT <= 0.0 then asymptotic theory probabilities
              are not used and Fisher exact test probabilities are
              computed.  Otherwise, if PERCNT or more of the cells in
              the remaining table have estimated expected values of
              EXPECT or more, with no remaining cell having expected
              value less than EMIN, then asymptotic chi-squared
              probabilities are used.  See the algorithm section of
              the
              manual document for details.
              Use EXPECT = 5.0 to obtain the 'Cochran' condition.

and compare with

            PVAL <- .C("fexact", nr, nc, x, nr, as.double(5), 
                as.double(80), as.double(1), double(1), p = double(1), 
                as.integer(workspace), mult = as.integer(mult), 
                PACKAGE = "stats")$p

The source file in question is

 src/library/stats/src/fexact.c 

available in the R source tarballs or via https://svn.r-project.org/R

 
> Thanks,
> 
> JD
> 
> ----------------------------------------------------------------------
> 
> Jonathan Dushoff <dushoff at eno.princeton.edu> writes:
> 
> > The hybrid feature in fisher.test looks to me like an excellent way to
> > analyze my two-way tables.   The only problem is that it does not seem
> > to be implemented.  Am I right about this?
> > 
> > An example is pasted below.  I note that I get the warning message only
> > when I shouldn't: for a 2x2 table hybrid seems to be ignored without
> > warning.  In no case does fisher.test seem to be checking Cochran
> > criteria as promised.
> > 
> > Any help will be appreciated.
> 
> 
> Well, something seems to have been mangled in connection with these
> changes: 
> 
> ------------------------------------------------------------------------
> r36358 | ripley | 2005-11-15 17:50:12 +0100 (Tue, 15 Nov 2005) | 2
> lines
> 
> add simulation option to fisher.test
> 
> ------------------------------------------------------------------------
> r36266 | ripley | 2005-11-10 22:19:34 +0100 (Thu, 10 Nov 2005) | 2
> lines
> 
> move 2x2 case in fisher.test to similar code as that used for or != 1
> 
> ------------------------------------------------------------------------
> 
> so that the warning 
> 
>         else if (hybrid) {
>             warning("'hybrid' is ignored for a 2 x 2 table")
> 
> now appears inside
> 
>     if (nr != 2 || nc != 2) {
> 
> which is clearly wrong.
> 
> However, the call to "fexact" that follows does have parameters set
> for the hybrid algorithm, so it's just the warning that is spurious.
> Notice that the hybrid algorithm may save a bit of time on probability
> calculations, but still needs to generate a large number of tables, so
> you really do need a larger workspace:
> 
> > fisher.test(matrix(10*1:9, nc=3),hybrid=TRUE,workspace=1e6)
> 
>         Fisher's Exact Test for Count Data
> 
> data:  matrix(10 * 1:9, nc = 3) 
> p-value = 0.3149
> alternative hypothesis: two.sided 
> 
> Warning message:
> 'hybrid' is ignored for a 2 x 2 table in: fisher.test(matrix(10 * 1:9,
> nc = 3), hybrid = TRUE, workspace = 1e+06) 
> 
> whereas (notice the slightly different p value)
> 
> .
> .
> .
> 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list