zinegbinUC.RdDensity, distribution function, quantile function and random
generation for the zero-inflated negative binomial distribution
with parameter pstr0.
dzinegbin(x, size, prob = NULL, munb = NULL, pstr0 = 0, log = FALSE)
pzinegbin(q, size, prob = NULL, munb = NULL, pstr0 = 0)
qzinegbin(p, size, prob = NULL, munb = NULL, pstr0 = 0)
rzinegbin(n, size, prob = NULL, munb = NULL, pstr0 = 0)vector of quantiles.
vector of probabilities.
Same as in runif.
Arguments matching dnbinom.
The argument munb corresponds to mu in
dnbinom and has been renamed
to emphasize the fact that it is the mean of the negative
binomial component.
Probability of structural zero (i.e., ignoring the negative binomial distribution), called \(\phi\).
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.
dzinegbin gives the density,
pzinegbin gives the distribution function,
qzinegbin gives the quantile function, and
rzinegbin generates random deviates.
The argument pstr0 is recycled to the required
length, and must have values which lie in the interval
\([0,1]\).
These functions actually allow for zero-deflation.
That is, the resulting probability of a zero count
is less than the nominal value of the parent
distribution.
See Zipois for more information.
munb <- 3; pstr0 <- 0.2; size <- k <- 10; x <- 0:10
(ii <- dzinegbin(x, pstr0 = pstr0, mu = munb, size = k))
#> [1] 0.258030520 0.133916585 0.169971050 0.156896354 0.117672266 0.076034387
#> [7] 0.043865993 0.023138106 0.011346571 0.005236879 0.002296170
max(abs(cumsum(ii) - pzinegbin(x, pstr0 = pstr0, mu = munb, size = k)))
#> [1] 2.220446e-16
table(rzinegbin(100, pstr0 = pstr0, mu = munb, size = k))
#>
#> 0 1 2 3 4 5 6 7 8 9
#> 36 15 15 12 13 4 2 1 1 1
table(qzinegbin(runif(1000), pstr0 = pstr0, mu = munb, size = k))
#>
#> 0 1 2 3 4 5 6 7 8 9 10 11
#> 255 138 157 179 119 82 34 16 9 5 5 1
round(dzinegbin(x, pstr0 = pstr0, mu = munb, size = k) * 1000) # Similar?
#> [1] 258 134 170 157 118 76 44 23 11 5 2
if (FALSE) barplot(rbind(dzinegbin(x, pstr0 = pstr0, mu = munb, size = k),
dnbinom(x, mu = munb, size = k)), las = 1,
beside = TRUE, col = c("blue", "green"), ylab = "Probability",
main = paste("ZINB(mu = ", munb, ", k = ", k, ", pstr0 = ", pstr0,
") (blue) vs NB(mu = ", munb,
", size = ", k, ") (green)", sep = ""),
names.arg = as.character(x)) # \dontrun{}