Beta-negative binomial distribution
Probability mass function and random generation for the beta-negative binomial distribution.
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). Must be strictly positive, need not be integer.
-
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≤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(α,β) and X NegBinomial(r,p), then X BetaNegBinomial(r,α,β).
Probability mass function
f(x)=x!Γ(r)Γ(r+x)B(α,β)B(α+r,β+x)f(x)=Γ(r+x)/(x!Γ(r))∗B(α+r,β+x)/B(α,β)
Cumulative distribution function is calculated using recursive algorithm that employs the fact that Γ(x)=(x−1)! and c("\n", "B(x,y)=(Gamma(x)Gamma(y))/Gamma(x+y)\n"). This enables re-writing probability mass function as
f(x)=x!Γ(r)(r+x−1)!B(α,β)(α+β+r+x−1)!(α+r−1)!(β+x−1)!f(x)=((r+x−1)!)/(x!∗Γ(r))∗(((α+r−1)!∗(β+x−1)!)/((α+β+r+x−1)!))/B(α,β)
what makes recursive updating from x to x+1 easy using the properties of factorials
f(x+1)=x!(x+1)Γ(r)(r+x−1)!(r+x)B(α,β)(α+β+r+x−1)!(α+β+r+x)(α+r−1)!(β+x−1)!(β+x)f(x+1)=((r+x−1)!∗(r+x))/(x!∗(x+1)∗Γ(r))∗(((α+r−1)!∗(β+x−1)!∗(β+x))/((α+β+r+x−1)!∗(α+β+r+x)))/B(α,β)
and let's us efficiently calculate cumulative distribution function as a sum of probability mass functions
F(x)=k=0∑xf(k)F(x)=f(0)+...+f(x)
Examples
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))
xx <- seq(0, 1e5, by = 0.1)
plot(ecdf(x))
lines(xx, pbnbinom(xx, 1000, 5, 13), col = "red", lwd = 2)
See Also
Beta
, NegBinomial