Learn R Programming

VGAM (version 0.8-7)

zinegbinomial: Zero-Inflated Negative Binomial Distribution Family Function

Description

Fits a zero-inflated negative binomial distribution by full maximum likelihood estimation.

Usage

zinegbinomial(lpstr0 = "logit", lmunb = "loge", lsize = "loge",
              epstr0 = list(),  emunb = list(), esize = list(),
              ipstr0 = NULL, isize = NULL, zero = c(-1, -3),
              imethod = 1, shrinkage.init = 0.95, nsimEIM = 250)

Arguments

lpstr0, lmunb, lsize
Link functions for the parameters $\phi$, the mean and $k$; see negbinomial for details, and Links for more choices. For the zero-deflated m
epstr0, emunb, esize
List. Extra arguments for the respective links. See earg in Links for general information.
ipstr0, isize
Optional initial values for $\phi$ and $k$. The default is to compute an initial value internally for both. If a vector then recycling is used.
imethod
An integer with value 1 or 2 or 3 which specifies the initialization method for the mean parameter. If failure to converge occurs try another value and/or else specify a value for shrinkage.init.
zero
Integers specifying which linear/additive predictor is modelled as intercepts only. If given, their absolute values must be either 1 or 2 or 3. The default is the $\phi$ and $k$ parameters (both for each response). See
shrinkage.init, nsimEIM
See CommonVGAMffArguments for information.

Value

  • An object of class "vglmff" (see vglmff-class). The object is used by modelling functions such as vglm, and vgam.

Warning

Numerical problems can occur, e.g., when the probability of zero is actually less than, not more than, the nominal probability of zero. Half-stepping is not uncommon. If failure to converge occurs, try using combinations of imethod, shrinkage.init, ipstr0, isize, and/or zero if there are explanatory variables.

Details

This function uses simulation and Fisher scoring, and is based on $$P(Y=0) = \phi + (1-\phi) (k/(k+\mu))^k,$$ and for $y=1,2,\ldots$, $$P(Y=y) = (1-\phi) \, dnbinom(y, \mu, k).$$ The parameter $\phi$ satisfies $0 < \phi < 1$. The mean of $Y$ is $(1-\phi) \mu$ (returned as the fitted values). By default, the three linear/additive predictors are $(logit(\phi), \log(\mu), \log(k))^T$. See negbinomial, another VGAM family function, for the formula of the probability density function and other details of the negative binomial distribution.

Independent multivariate responses are handled. If so then arguments ipstr0 and isize may be vectors with length equal to the number of responses.

See Also

Zinegbin, negbinomial, rpois, CommonVGAMffArguments.

Examples

Run this code
# Example 1
ndata <- data.frame(x2 = runif(nn <- 1000))
ndata <- transform(ndata, pstr0 = logit(-0.5 + 1 * x2, inverse = TRUE),
                          munb  =   exp( 3   + 1 * x2),
                          size  =   exp( 0   + 2 * x2))
ndata <- transform(ndata,
                   y1 = rzinegbin(nn, mu = munb, size = size, pstr0 = pstr0),
                   y2 = rzinegbin(nn, mu = munb, size = size, pstr0 = pstr0))
with(ndata, table(y1)["0"] / sum(table(y1)))
fit <- vglm(cbind(y1, y2) ~ x2, zinegbinomial(zero = NULL), ndata)
coef(fit, matrix = TRUE)
summary(fit)
head(cbind(fitted(fit), with(ndata, (1 - pstr0) * munb)))
round(vcov(fit), 3)


# Example 2: RR-ZINB could also be called a COZIVGLM-ZINB-2
ndata <- data.frame(x2 = runif(nn <- 2000))
ndata <- transform(ndata, x3 = runif(nn))
ndata <- transform(ndata, eta1 =          3   + 1   * x2 + 2 * x3)
ndata <- transform(ndata, pstr0  = logit(-1.5 + 0.5 * eta1, inverse = TRUE),
                          munb = exp(eta1),
                          size = exp(4))
ndata <- transform(ndata,
                   y1 = rzinegbin(nn, pstr0 = pstr0, mu = munb, size = size))
with(ndata, table(y1)["0"] / sum(table(y1)))
rrzinb <- rrvglm(y1 ~ x2 + x3, zinegbinomial(zero = NULL), ndata,
                 Index.corner = 2, szero = 3, trace = TRUE)
coef(rrzinb, matrix = TRUE)
Coef(rrzinb)

Run the code above in your browser using DataLab