Skip to content

fisher.test() in ctest or perhaps uniroot() (PR#455)

3 messages · Thomas Lumley, Peter Dalgaard

#
fisher.test(matrix(c(1,20,246,6873),2),hybrid=F)
Error in if (f(lower, ...) * f(upper, ...) >= 0) stop("f() values at end
points not of opposite sign") :
        missing value where logical needed


Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
thomas@biostat.washington.edu writes:
Problem seems to be that mnhyper as defined doesn't like extreme
arguments, and is being called with

 1/.Machine$double.eps

e.g.
[1] NaN
[1] 21

The code looks like this:

    if (ncp == 0) 
        return(lo)
    if (ncp == Inf) 
        return(hi)
    q <- lo:hi
    d <- dhyper(q, m, n, k) * ncp^(0:(hi - lo))

And I suspect that the test should be ncp^(hi-lo)==Inf.

Seems to work:
Fisher's Exact Test for Count Data 

data:  matrix(c(1, 20, 246, 6873), 2) 
p-value = 0.5231 
alternative hypothesis: true odds ratio is not equal to 1 
95 percent confidence interval:
 0.0335691 8.8064130 
sample estimates:
odds ratio 
  1.396855
#
Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
Committed. Two other similar cases fixed as well.