Learn R Programming

VGAM (version 1.0-5)

Zipois: Zero-Inflated Poisson Distribution

Description

Density, distribution function, quantile function and random generation for the zero-inflated and zero-deflated Poisson distribution with parameter pstr0.

Usage

dzipois(x, lambda, pstr0 = 0, log = FALSE)
pzipois(q, lambda, pstr0 = 0)
qzipois(p, lambda, pstr0 = 0)
rzipois(n, lambda, pstr0 = 0)

Arguments

x, q

vector of quantiles.

p

vector of probabilities.

n

number of observations. Must be a single positive integer.

lambda

Vector of positive means.

pstr0

Probability of a structural zero (i.e., ignoring the Poisson distribution), called \(\phi\). The default value of \(\phi = 0\) corresponds to the response having an ordinary Poisson distribution. This argument may be negative to allow for 0-deflation, hence its interpretation as a probability ceases.

log

Logical. Return the logarithm of the answer?

Value

dzipois gives the density, pzipois gives the distribution function, qzipois gives the quantile function, and rzipois generates random deviates.

Details

The probability function of \(Y\) is 0 with probability \(\phi\), and \(Poisson(\lambda)\) with probability \(1-\phi\). Thus $$P(Y=0) =\phi + (1-\phi) P(W=0)$$ where \(W\) is distributed \(Poisson(\lambda)\).

See Also

zipoisson, dpois, rzinegbin.

Examples

Run this code
# NOT RUN {
lambda <- 3; pstr0 <- 0.2; x <- (-1):7
(ii <- dzipois(x, lambda, pstr0 = pstr0))
max(abs(cumsum(ii) - pzipois(x, lambda, pstr0 = pstr0)))  # Should be 0
table(rzipois(100, lambda, pstr0 = pstr0))

table(qzipois(runif(100), lambda, pstr0))
round(dzipois(0:10, lambda, pstr0 = pstr0) * 100)  # Should be similar

# }
# NOT RUN {
 x <- 0:10
par(mfrow = c(2, 1))  # Zero-inflated Poisson
barplot(rbind(dzipois(x, lambda, pstr0 = pstr0), dpois(x, lambda)),
        beside = TRUE, col = c("blue", "orange"),
        main = paste("ZIP(", lambda, ", pstr0 = ", pstr0, ") (blue) vs",
                     " Poisson(", lambda, ") (orange)", sep = ""),
        names.arg = as.character(x))

deflat.limit <- -1 / expm1(lambda)  # Zero-deflated Poisson
newpstr0 <- round(deflat.limit / 1.5, 3)
barplot(rbind(dzipois(x, lambda, pstr0 = newpstr0),
                dpois(x, lambda)),
        beside = TRUE, col = c("blue","orange"),
        main = paste("ZDP(", lambda, ", pstr0 = ", newpstr0, ") (blue) vs",
                     " Poisson(", lambda, ") (orange)", sep = ""),
        names.arg = as.character(x)) 
# }

Run the code above in your browser using DataLab