Skip to contents

Computes DPIT residuals for regression models with zero-inflated Poisson outcomes using the observed counts(y) and their fitted distributional parameters(mu, pzero).

Usage

dpit_zpois(y, mu, pzero)

Arguments

y

An observed outcome vector.

mu

A vector of fitted mean values for the count (non-zero) component.

pzero

A vector of fitted probabilities for the zero-inflation component.

Value

A dpit object containing DPIT residuals.

Details

For formulation details on discrete outcomes, see dpit.

Examples

## Zero-Inflated Poisson
library(pscl)
n <- 500
set.seed(1234)
# Covariates
x1 <- rnorm(n)
x2 <- rbinom(n, 1, 0.7)
# Coefficients
beta0 <- -2
beta1 <- 2
beta2 <- 1
beta00 <- -2
beta10 <- 2

# Mean of Poisson part
lambda1 <- exp(beta0 + beta1 * x1 + beta2 * x2)
# Excess zero probability
p0 <- 1 / (1 + exp(-(beta00 + beta10 * x1)))
## simulate outcomes
y0 <- rbinom(n, size = 1, prob = 1 - p0)
y1 <- rpois(n, lambda1)
y <- ifelse(y0 == 0, 0, y1)
## True model
modelzero1 <- zeroinfl(y ~ x1 + x2 | x1, dist = "poisson", link = "logit")
y1 <- modelzero1$y
mu1    <- stats::predict(modelzero1, type = "count")
pzero1 <- stats::predict(modelzero1, type = "zero")
dpit.zero1 <- dpit_zpois(y= y1, pzero=pzero1, mu=mu1)
resid.zero1 <- residuals(dpit.zero1)
plot(dpit.zero1)


## Zero inflation
modelzero2 <- glm(y ~ x1 + x2, family = poisson(link = "log"))
y2 <- modelzero2$y
mu2    <- fitted(modelzero2)
dpit.zero2 <- dpit_pois(y= y2, mu=mu2)
resid.zero2 <- residuals(dpit.zero2)
plot(dpit.zero2)