negbinomial(lmu = "loge", lsize = "loge",
imu = NULL, isize = NULL, probs.y = 0.75,
nsimEIM = 100, cutoff = 0.995,
Maxiter = 5000, deviance.arg = FALSE, imethod = 1,
parallel = FALSE, ishrinkage = 0.95, zero = -2)
polya(lprob = "logit", lsize = "loge",
iprob = NULL, isize = NULL, probs.y = 0.75, nsimEIM = 100,
imethod = 1, ishrinkage = 0.95, zero = -2)
polyaR(lsize = "loge", lprob = "logit",
isize = NULL, iprob = NULL, probs.y = 0.75, nsimEIM = 100,
imethod = 1, ishrinkage = 0.95, zero = -1)
Links
for more choices.
Note that the $\mu$, $k$
and $p$ parameters are the mu
,
size
and prob
imethod
).
For a $S$-column response, isize
can be of length $S$.
A value NULL
probs
argument
of quantile
when imethod = 3
to obtain an initial value for the mean.CommonVGAMffArguments
for more information
and the If TRUE
, the deviance is computed after convergence.
It only works in the NB-2 model.
It is also necessary to set criterion = "coefficients"
or half.step = FALSE
since
one cannot use th
1
or 2
or 3
which
specifies the initialization method for the $\mu$ parameter.
If failure to converge occurs try another value
and/or else specify a value for ishrinkage
andCommonVGAMffArguments
for more information.
Setting parallel = TRUE
is useful in order to get
something similar to quasipoisso
lsize
is applied) is modelled as a single "vglmff"
(see vglmff-class
).
The object is used by modelling functions such as vglm
,
rrvglm
and vgam
.poissonff
or quasipoissonff
.
These functions are fragile; the maximum likelihood
estimate of the index parameter is fraught (see Lawless,
1987). In general, the quasipoissonff
is
more robust. Other alternatives to negbinomial
are
to fit a NB-1 or RR-NB (aka NB-P) model; see Yee (2014).
Also available are the NB-C, NB-H and NB-G.
Assigning values to the isize
argument may lead
to a local solution, and smaller values are preferred
over large values when using this argument.
Yet to do: write a family function which uses the methods of moments estimator for $k$.
negbinomial()
uses the
mean $\mu$ and an index parameter
$k$, both which are positive.
Specifically, the density of a random variable $Y$ is
fitted.values
slot of the object contains
the estimated value of the $\mu$ parameter, i.e., of the mean
$E(Y)$.
It is common for some to use $\alpha=1/k$ as the
ancillary or heterogeneity parameter;
so common alternatives for lsize
are
negloge
and
reciprocal
.
For polya
the density is
Family function polyaR()
is the same as polya()
except
the order of the two parameters are switched.
The reason is that polyaR()
tries to match with
rnbinom
closely
in terms of the argument order, etc.
Should the probability parameter be of primary interest,
probably, users will prefer using polya()
rather than
polyaR()
.
Possibly polyaR()
will be decommissioned one day.
The negative binomial distribution can be coerced into the
classical GLM framework with one of the parameters being
of interest and the other treated as a nuisance/scale
parameter (this is implemented in the negbinomial
treats both
parameters on the same footing, and estimates them both
by full maximum likelihood estimation. Simulated Fisher
scoring is employed as the default (see the nsimEIM
argument).
The parameters $\mu$ and $k$ are independent (diagonal EIM), and the confidence region for $k$ is extremely skewed so that its standard error is often of no practical use. The parameter $1/k$ has been used as a measure of aggregation.
These zero = -2
means that
all species have a $k$ equalling a (different)
intercept only.
Hilbe, J. M. (2011) Negative Binomial Regression, 2nd Edition. Cambridge: Cambridge University Press.
Bliss, C. and Fisher, R. A. (1953) Fitting the negative binomial distribution to biological data. Biometrics 9, 174--200.
Yee, T. W. (2014) Reduced-rank vector generalized linear models with two linear predictors. Computational Statistics and Data Analysis.
quasipoissonff
,
poissonff
,
zinegbinomial
,
negbinomial.size
(e.g., NB-G),
nbcanlink
(NB-C),
posnegbinomial
,
inv.binomial
,
rnbinom
,
nbolf
,
rrvglm
,
cao
,
cqo
,
CommonVGAMffArguments
,
simulate.vlm
.# Example 1: apple tree data
appletree <- data.frame(y = 0:7, w = c(70, 38, 17, 10, 9, 3, 2, 1))
fit <- vglm(y ~ 1, negbinomial(deviance = TRUE), data = appletree,
weights = w, crit = "coef")
fit <- vglm(y ~ 1, negbinomial(deviance = TRUE), data = appletree,
weights = w, half.step = FALSE) # Alternative method
summary(fit)
coef(fit, matrix = TRUE)
Coef(fit)
deviance(fit) # NB2 only; needs 'crit = "coef"' & 'deviance = TRUE' above
# Example 2: simulated data with multivariate response
ndata <- data.frame(x2 = runif(nn <- 500))
ndata <- transform(ndata, y1 = rnbinom(nn, mu = exp(3+x2), size = exp(1)),
y2 = rnbinom(nn, mu = exp(2-x2), size = exp(0)))
fit1 <- vglm(cbind(y1, y2) ~ x2, negbinomial, data = ndata, trace = TRUE)
coef(fit1, matrix = TRUE)
# Example 3: large counts so definitely use the nsimEIM argument
ndata <- transform(ndata, y3 = rnbinom(nn, mu = exp(12+x2), size = exp(1)))
with(ndata, range(y3)) # Large counts
fit2 <- vglm(y3 ~ x2, negbinomial(nsimEIM = 100), data = ndata, trace = TRUE)
coef(fit2, matrix = TRUE)
# Example 4: a NB-1 to estimate a negative binomial with Var(Y) = phi0 * mu
nn <- 1000 # Number of observations
phi0 <- 10 # Specify this; should be greater than unity
delta0 <- 1 / (phi0 - 1)
mydata <- data.frame(x2 = runif(nn), x3 = runif(nn))
mydata <- transform(mydata, mu = exp(2 + 3 * x2 + 0 * x3))
mydata <- transform(mydata, y3 = rnbinom(nn, mu = mu, size = delta0 * mu))
plot(y3 ~ x2, data = mydata, pch = "+", col = 'blue',
main = paste("Var(Y) = ", phi0, " * mu", sep = ""), las = 1)
nb1 <- vglm(y3 ~ x2 + x3, negbinomial(parallel = TRUE, zero = NULL),
data = mydata, trace = TRUE)
# Extracting out some quantities:
cnb1 <- coef(nb1, matrix = TRUE)
mydiff <- (cnb1["(Intercept)", "loge(size)"] -
cnb1["(Intercept)", "loge(mu)"])
delta0.hat <- exp(mydiff)
(phi.hat <- 1 + 1 / delta0.hat) # MLE of phi
summary(nb1)
# Obtain a 95 percent confidence interval for phi0:
myvec <- rbind(-1, 1, 0, 0)
(se.mydiff <- sqrt(t(myvec) %*% vcov(nb1) %*% myvec))
ci.mydiff <- mydiff + c(-1.96, 1.96) * se.mydiff
ci.delta0 <- ci.exp.mydiff <- exp(ci.mydiff)
(ci.phi0 <- 1 + 1 / rev(ci.delta0)) # The 95 percent conf. interval for phi0
Confint.nb1(nb1) # Quick way to get it
summary(glm(y3 ~ x2 + x3, quasipoisson, mydata))$disper # cf. moment estimator
Run the code above in your browser using DataLab