dnbinomR {DPQ}R Documentation

Pure R Versions of R's C (Mathlib) dnbinom() Negative Binomial Probabilities

Description

Compute pure R implementations of R's C Mathlib (Rmath) dnbinom() binomial probabilities, allowing to see the effect of the cutoff eps.

Usage

dnbinomR  (x, size, prob, log = FALSE, eps = 1e-10)
dnbinom.mu(x, size, mu,   log = FALSE, eps = 1e-10)

Arguments

x, size, prob, mu, log

see R's dnbinom().

eps

non-negative number specifying the cutoff for “small x/size”, in which case the 2-term approximation from Abramowitz and Stegun, 6.1.47 (p.257) is preferable to the dbinom() based evaluation.

Value

numeric vector of the same length as x which may have to be thought of recycled along size and prob or mu.

Author(s)

R Core and Martin Maechler

References

Abramowitz, M. and Stegun, I. A. (1972) Handbook of Mathematical Functions. New York: Dover. https://en.wikipedia.org/wiki/Abramowitz_and_Stegun provides links to the full text which is in public domain.

See Also

dbinom_raw; Note that our CRAN package Rmpfr provides dnbinom, dbinom and more, where mpfr-accurate functions are used instead of R's (and our pure R version of) bd0() and stirlerr().

Examples


 stopifnot( dnbinomR(0, 1, 1) == 1 )
 size <- 1000 ; x <- 0:size
 dnb <- dnbinomR(x, size, prob = 5/8, log = FALSE, eps = 1e-10)
 plot(x, dnb, type="b")
 all.equal(dnb, dnbinom(x, size, prob = 5/8)) ## mean rel. diff: 0.00017...

 dnbm <- dnbinom.mu(x, size, mu = 123, eps = 1e-10)
 all.equal(dnbm, dnbinom(x, size, mu = 123)) #  Mean relative diff: 0.00069...

[Package DPQ version 0.5-8 Index]