# Example 1
nbdat <- data.frame(x2 = runif(nn <- 1000))
nbdat <- transform(nbdat, phi = logit(-0.5 + 1 * x2, inverse = TRUE),
munb = exp(3 + x2),
size = exp(0 + 2*x2))
nbdat <- transform(nbdat, y1 = rzinegbin(nn, phi, mu = munb, size = size),
y2 = rzinegbin(nn, phi, mu = munb, size = size))
with(nbdat, table(y1)["0"] / sum(table(y1)))
fit <- vglm(cbind(y1, y2) ~ x2, zinegbinomial(zero = NULL), nbdat)
coef(fit, matrix = TRUE)
summary(fit)
head(cbind(fitted(fit), with(nbdat, (1-phi) * munb)))
round(vcov(fit), 3)
# Example 2: RR-ZINB could also be called a COZIVGLM-ZINB-2
nbdat <- data.frame(x2 = runif(nn <- 2000))
nbdat <- transform(nbdat, x3 = runif(nn))
nbdat <- transform(nbdat, eta1 = 3 + 1 * x2 + 2 * x3)
nbdat <- transform(nbdat, phi = logit(-1.5 + 0.5 * eta1, inverse = TRUE),
munb = exp(eta1),
size = exp(4))
nbdat <- transform(nbdat, y1 = rzinegbin(nn, phi, mu = munb, size = size))
with(nbdat, table(y1)["0"] / sum(table(y1)))
rrzinb <- rrvglm(y1 ~ x2 + x3, zinegbinomial(zero = NULL), nbdat,
Index.corner = 2, szero = 3, trace = TRUE)
coef(rrzinb, matrix = TRUE)
Coef(rrzinb)
Run the code above in your browser using DataLab