[R] fisher.test function error

Marc Schwartz marc_schwartz at me.com
Fri Mar 31 14:45:18 CEST 2017


> On Mar 31, 2017, at 7:04 AM, Stefan Evert <stefanML at collocations.de> wrote:
> 
> 
>> On 30 Mar 2017, at 11:51, Eshi Vaz <eshithasunithi2 at gmail.com> wrote:
>> 
>> When trying to computer a fisher’s exact test using the fisher.test function from the gmodels() package,  <----
> 
> The problem seems to be with a different fisher.test() function from the gmodels package, not with stats::fisher.test.
> 
> The usual recommendation is to contact the package authors for help.
> 
> Best regards,
> Stefan


There is no fisher.test() function in the gmodels package. 

The error message is being generated from compiled code in stats::fisher.test().

A Google search for the error message indicates that there are reports going back at least as far as 2002, suggesting that the underlying issue is an integer overflow:

  https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=1662

with at least one example resolved back in 2005:

  https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=6986

The former report has recent reports from 2014/2015 suggesting that the original 2002 issue is still present, at least in specific situations:

d4 <- matrix(c(0, 0, 0, 0, 0,  0, 3, 0, 1, 0,  0, 0, 0, 0, 0,
               1, 0, 0, 0, 0,  1, 0, 0, 2, 0,  0, 0, 1, 0, 0,
               0, 1, 0, 1, 0,  4, 0, 2, 0, 0,  0, 1, 0, 0, 0,  0, 0, 0, 0, 0,
               0, 1, 0, 0, 2,  0, 0, 0, 2, 2,  0, 1, 0, 0, 0,
               0, 0, 1, 1, 0,  0, 0, 0, 0, 0,  0, 1, 0, 0, 0,
               1, 0, 0, 0, 2,  0, 0, 0, 3, 0,  0, 0, 0, 0, 1,  0, 0, 0, 0, 0,
               2, 0, 0, 0, 0,  0, 0, 0, 0, 0,  0, 0, 1, 0, 1,
               0, 0, 0, 0, 2,  0, 0, 0, 0, 8,  0, 0, 0, 3, 0,
               0, 0, 0, 0, 0,  0, 0, 0, 0, 0,  0, 0, 0, 0, 0,  0, 0, 0, 0, 1,
               0, 0, 1, 0, 0,  0, 0, 0, 0, 0,  2, 0, 0, 1, 0,
               0, 2, 0, 0, 0,  0, 2, 0, 0, 1,  3, 0, 0, 0, 0,
               0, 0, 0, 0, 0,  0, 0, 0, 0, 1,  0, 0, 1, 0, 0,  4, 0, 0, 0, 0),
             nr=50)

> fisher.test(d4)
Error in fisher.test(d4) : FEXACT error 30.
Stack length exceeded in f3xact.
This problem should not occur.


tab <- structure(list(V1 = c(1, 0, 0, 0, 0, 0), 
                      V2 = c(323, 4, 1, 0, 0, 22), 
                      V3 = c(3, 0, 0, 0, 0, 1), 
                      V4 = c(2, 0, 1, 0, 1, 3), 
                      V5 = c(1, 0, 0, 0, 0, 4), 
                      V6 = c(1, 0, 0, 0, 0, 0), 
                      V7 = c(0, 0, 0, 1, 0, 1), 
                      V8 = c(96, 0, 0, 0, 0, 2)), 
                      .Names = c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8"), 
                      class = "data.frame", row.names = c(NA, -6L))

> fisher.test(tab)
Error in fisher.test(tab) : Bug in FEXACT: gave negative key


Note that in the second example, the data frame is coerced to a matrix inside fisher.test().

The above two examples were run using R version 3.3.3 on macOS 10.12.4 in a CLI console.

Regards,

Marc Schwartz



More information about the R-help mailing list