zinegbinomial {VGAM} | R Documentation |
Fits a zero-inflated negative binomial distribution by full maximum likelihood estimation.
zinegbinomial(lpstr0 = "logit", lmunb = "loge", lsize = "loge", type.fitted = c("mean", "pobs0", "pstr0", "onempstr0"), ipstr0 = NULL, isize = NULL, zero = -3, imethod = 1, ishrinkage = 0.95, nsimEIM = 250) zinegbinomialff(lmunb = "loge", lsize = "loge", lonempstr0 = "logit", type.fitted = c("mean", "pobs0", "pstr0", "onempstr0"), isize = NULL, ionempstr0 = NULL, zero = c(-2, -3), imethod = 1, ishrinkage = 0.95, nsimEIM = 250)
lpstr0, lmunb, lsize |
Link functions for the parameters pstr0,
the mean and k; see |
type.fitted |
See |
ipstr0, isize |
Optional initial values for pstr0 and k. The default is to compute an initial value internally for both. If a vector then recycling is used. |
lonempstr0, ionempstr0 |
Corresponding arguments for the other parameterization. See details below. |
imethod |
An integer with value |
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 pstr0 and k parameters
(both for each response).
See |
ishrinkage, nsimEIM |
See |
These functions are based on
P(Y=0) = φ + (1-φ) * (k/(k+μ))^k,
and for y=1,2,…,
P(Y=y) = (1-φ) * dnbinom(y, μ, k).
The parameter phi satisfies 0 < phi < 1.
The mean of Y is (1-phi)*munb
(returned as the fitted values).
By default, the three linear/additive predictors
for zinegbinomial()
are (logit(phi),
log(munb), 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.
The VGAM family function zinegbinomialff()
has a few
changes compared to zinegbinomial()
.
These are:
(i) the order of the linear/additive predictors is switched so the
NB mean comes first;
(ii) onempstr0
is now 1 minus the probability of a structural 0,
i.e., the probability of the parent (NB) component,
i.e., onempstr0
is 1-pstr0
;
(iii) argument zero
has a new default so that the onempstr0
is intercept-only by default.
Now zinegbinomialff()
is generally recommended over
zinegbinomial()
.
Both functions implement Fisher scoring and can handle
multiple responses.
An object of class "vglmff"
(see vglmff-class
).
The object is used by modelling functions such as vglm
,
and vgam
.
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 arguments
stepsize
(in vglm.control
),
imethod
,
ishrinkage
,
ipstr0
,
isize
, and/or
zero
if there are explanatory variables.
An infinite loop might occur if some of the fitted values (the means) are too close to 0.
This VGAM family function is computationally expensive
and usually runs slowly;
setting trace = TRUE
is useful for monitoring convergence.
Estimated probabilities of a structural zero and an
observed zero can be returned, as in zipoisson
;
see fittedvlm
for more information.
If k is large then the use of VGAM family function
zipoisson
is probably preferable.
This follows because the Poisson is the limiting distribution of a
negative binomial as k tends to infinity.
The zero-deflated negative binomial distribution
might be fitted by setting lpstr0 = identitylink
,
albeit, not entirely reliably. See zipoisson
for information that can be applied here. Else try
the zero-altered negative binomial distribution (see
zanegbinomial
).
T. W. Yee
Zinegbin
,
negbinomial
,
rpois
,
CommonVGAMffArguments
.
## Not run: # 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), data = 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), data = ndata, Index.corner = 2, str0 = 3, trace = TRUE) coef(rrzinb, matrix = TRUE) Coef(rrzinb) ## End(Not run)