Learn R Programming

extraDistr (version 1.8.1)

BetaNegBinom: Beta-negative binomial distribution

Description

Probability mass function and random generation for the beta-negative binomial distribution.

Usage

dbnbinom(x, size, alpha = 1, beta = 1, log = FALSE)
pbnbinom(q, size, alpha = 1, beta = 1, lower.tail = TRUE, log.p = FALSE)
rbnbinom(n, size, alpha = 1, beta = 1)

Arguments

x, q
vector of quantiles.
size
number of trials (zero or more).
alpha, beta
non-negative parameters of the beta distribution.
log, log.p
logical; if TRUE, probabilities p are given as log(p).
lower.tail
logical; if TRUE (default), probabilities are $P[X \le x]$ otherwise, $P[X > x]$.
n
number of observations. If length(n) > 1, the length is taken to be the number required.

Details

If $p ~ Beta(\alpha, \beta)$ and $X ~ NegBinomial(r, p)$, then $X ~ BetaNegBinomial(r, \alpha, \beta)$.

Probability mass function $$ f(x) = \frac{\Gamma(r+x)}{x! \Gamma(r)} \frac{\mathrm{B}(\alpha+r, \beta+x)}{\mathrm{B}(\alpha, \beta)} $$

Warning: cumulative distribution function is defined as $$F(x) = \sum_{k=0}^x f(k)$$ so it may be slow for large datasets.

See Also

Beta, NegBinomial

Examples

Run this code

x <- rbnbinom(1e5, 1000, 5, 13)
xx <- 0:1e5
hist(x, 100, freq = FALSE)
lines(xx-0.5, dbnbinom(xx, 1000, 5, 13), col = "red")
hist(pbnbinom(x, 1000, 5, 13))
plot(ecdf(x))
lines(xx, pbnbinom(xx, 1000, 5, 13), col = "red", lwd = 2)

Run the code above in your browser using DataLab