## dhyperQ() is simply
function (x, m, n, k)
{
stopifnot(k - x == as.integer(k - x))
chooseZ(m, x) * chooseZ(n, k - x) / chooseZ(m + n, k)
}
# a case where phyper(11, 15, 0, 12, log=TRUE) gave 'NaN'
(phyp5.0.12 <- cumsum(dhyperQ(0:12, m=15,n=0,k=12)))
stopifnot(phyp5.0.12 == c(rep(0, 12), 1))
for(x in 0:9)
stopifnot(phyperQ(x, 10,7,8) +
phyperQ(x, 10,7,8, lower.tail=FALSE) == 1)
(ph. <- phyperQall(m=10, n=7, k=8))
## Big Rational ('bigq') object of length 8:
## [1] 1/2431 5/374 569/4862 2039/4862 3803/4862 4685/4862 4853/4862 1
stopifnot(identical(gmp::c_bigq(list(0, ph.)),
1- c(phyperQall(10,7,8, lower.tail=FALSE), 0)))
(doExtras <- DPQmpfr:::doExtras())
if(doExtras) { # too slow for standard testing
k <- 5000
system.time(ph <- phyper(k, 2*k, 2*k, 2*k)) # 0 (< 0.001 sec)
system.time(phQ <- phyperQ(k, 2*k, 2*k, 2*k)) # 5.6 (was 6.3) sec
## Relative error of R's phyper()
stopifnot(print(gmp::asNumeric(1 - ph/phQ)) < 1e-14) # seen 1.063e-15
}
Run the code above in your browser using DataLab