Learn R Programming

VGAM (version 0.8-4.1)

Zinegbin: Zero-Inflated Negative Binomial Distribution

Description

Density, distribution function, quantile function and random generation for the zero-inflated negative binomial distribution with parameter phi.

Usage

dzinegbin(x, phi, size, prob = NULL, munb = NULL, log = FALSE)
pzinegbin(q, phi, size, prob = NULL, munb = NULL)
qzinegbin(p, phi, size, prob = NULL, munb = NULL)
rzinegbin(n, phi, size, prob = NULL, munb = NULL)

Arguments

x, q
vector of quantiles.
p
vector of probabilities.
n
number of observations. Must be a single positive integer.
size, prob, munb, log
Arguments matching dnbinom. The argument munb corresponds to mu in dnbinom and has been renam
phi
Probability of zero (ignoring the negative binomial distribution), called $\phi$.

Value

  • dzinegbin gives the density, pzinegbin gives the distribution function, qzinegbin gives the quantile function, and rzinegbin generates random deviates.

Details

The probability function of $Y$ is 0 with probability $\phi$, and a negative binomial distribution with probability $1-\phi$. Thus $$P(Y=0) =\phi + (1-\phi) P(W=0)$$ where $W$ is distributed as a negative binomial distribution (see rnbinom.) See negbinomial, a VGAM family function, for the formula of the probability density function and other details of the negative binomial distribution.

See Also

zinegbinomial, rnbinom, rzipois.

Examples

Run this code
munb = 3; phi = 0.2; size = k = 10
x = 0:10
(ii = dzinegbin(x, phi = phi, mu = munb, size = k))
max(abs(cumsum(ii) - pzinegbin(x, phi = phi, mu = munb, size = k))) # Should be 0
table(rzinegbin(100, phi = phi, mu = munb, size = k))

table(qzinegbin(runif(1000), phi = phi, mu = munb, size = k))
round(dzinegbin(x, phi = phi, mu = munb, size = k) * 1000) # Should be similar

barplot(rbind(dzinegbin(x, phi = phi, mu = munb, size = k),
                dnbinom(x, mu = munb, size = k)),
        beside = TRUE, col = c("blue", "green"),
        main = paste("ZINB(mu = ", munb, ", k = ", k, ", phi = ", phi,
                   ") (blue) vs negative binomial(mu = ", munb,
                   ", size = ", k, ") (green)", sep = ""),
        names.arg = as.character(x))

Run the code above in your browser using DataLab