binomQ: Exact Rational Binomial Probabilities

binomQR Documentation

Exact Rational Binomial Probabilities

Description

Compute exact binomial probabilities using (big integer and) big rational arithmetic.

Usage

dbinomQ(x, size, prob, log = FALSE)

Arguments

x, size

integer or big integer ("bigz"), will be passed to chooseZ().

prob

the probability; should be big rational ("bigq"); if not it is coerced with a warning.

log

logical; must be FALSE on purpose. Use log(Rmpfr::mpfr(dbinomQ(..), precB)) for the logarithm of such big rational numbers.

Value

a big rational ("bigq") of the length of (recycled) x+size+prob.

Author(s)

Martin Maechler

See Also

chooseZ; R's (stats package) dbinom().

Examples

dbinomQ(0:8,8, as.bigq(1,2))
##  1/256  1/32   7/64   7/32   35/128 7/32   7/64   1/32   1/256

ph16. <- dbinomQ(0:16, size=16, prob = 1/2)  # innocous warning
ph16  <- dbinomQ(0:16, size=16, prob = as.bigq(1,2))
ph16.75 <- dbinomQ(0:16, size=16, prob = as.bigq(3,4))
ph8.75  <- dbinomQ(0:8, 8, as.bigq(3,4))
stopifnot(exprs = {
   dbinomQ(0:8,8, as.bigq(1,2)) * 2^8 == choose(8, 0:8)
   identical(ph8.75, chooseZ(8,0:8) * 3^(0:8) / 4^8)
   all.equal(ph8.75, choose (8,0:8) * 3^(0:8) / 4^8, tol=1e-15) # see exactly equal
   identical(ph16, ph16.)
   identical(ph16,
            dbinomQ(0:16, size=16, prob = as.bigz(1)/2))
   all.equal(dbinom(0:16, 16, prob=1/2), asNumeric(ph16),    tol=1e-15)
   all.equal(dbinom(0:16, 16, prob=3/4), asNumeric(ph16.75), tol=1e-15)
})

gmp documentation built on July 9, 2023, 7 p.m.

Related to binomQ in gmp...