Description Usage Arguments Details Value References See Also Examples
Fit negative binomial (NB) regression models with NB1 response distribution. The negative binomial distribution can arise as a gamma mixture of Poisson distributions, and can be used for modelling over-dispersed count data.
1 2 3 4 5 6 7 |
formula |
an object of class " |
data |
a data frame containing the variables of the model. If not found in the data, variables are taken from |
.
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
na.action |
a function which indicates what should happen when the data contain NAs. |
model, y, x |
logicals. If TRUE the corresponding components of the fit are returned. |
control |
a list of parameters for controlling the fitting process. For |
... |
additional arguments to be passed. |
maxit, start |
control arguments passed to |
grad |
logical. Should gradients be used for optimization? If |
hessian |
logical or character. Should a numeric approximation of the
(negative) Hessian matrix be computed? Either |
A continous mixture of Poisson distribution with Gamma weights is called negative binomial distribution. To employ the NB1 distribution in a regression, the natural mean equation is employed:
log(μ_{i}) = x_i^\top β
.
For the variance, the NB1 model assumes varying θ_i such that α = μ_i/θ_i and thus
Var(y_i | x_i) = (1 + α) \cdot μ_i
.
The workhorse function is negbin1_fit
, which is normally not called directly, but when the model response and model matrix have already been calculated. Starting values in the optimization are by default taken from a Poisson glm.
negbin1_fit
is the lower level function where the actual fitting takes place.
A set of standard extractor functions for fitted model objects is available for
objects of class "negbin1"
, including methods to the generic functions
print
, summary
, coef
,
vcov
, logLik
, residuals
,
predict
, terms
,
model.frame
, model.matrix
, update
,
estfun
and bread
(from the sandwich package), and
getSummary
(from the memisc package, enabling mtable
).
See predict.negbin1
and coef.negbin1
for more details
on some methods with non-standard arguments.
negbin1
returns an object of class "negbin"
, i.e., a list
with components as follows.
negbin1.fit
returns an unclassed list with components up to df
.
coefficients |
a vector containing the coefficients from the respective models, |
counts |
count of function and gradient evaluations from |
convergence |
convergence code from |
message |
optional further information from |
vcov |
covariance matrix of all parameters in the model, |
residuals |
a vector of raw residuals (observed - fitted), |
fitted.values |
a list with elements |
method |
the method argument passed to the |
nobs |
number of observations, |
df |
number of estimated parameters, |
call |
the original function call, |
formula |
the original formula, |
terms |
a list with elements containing the terms objects for the respective models, |
levels |
a list with elements containing the levels of the categorical regressors, |
contrasts |
a list with elements containing the contrasts
corresponding to |
model |
the full model frame (if |
y |
the numeric response vector (if |
x |
a list with elements containing the model matrices from the respective models
(if |
Cameron AC & Trivedi PK (1986). Econometric Models Based on Count Data: Comparisons and Applications of Some Estimators and Tests, Journal of Applied Econometrics, 1, 29–53.
Cameron AC & Trivedi PK (2013). “Regression Analysis of Count Data”, Cambridge University Press.
Lawless JF (1987). Negative Binomial and Mixed Poisson Regression, The Canadian Journal of Statistics, 15(3), 209–225.
Winkelmann R & Boes S (2009). “Analysis of Microdata”, Springer, Second Edition.
predict.negbin1
, coef.negbin1
, gamlss
, vglm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | ## packages
require("Formula")
require("gamlss")
require("VGAM")
require("lmtest")
## data generating process
dgp <- function(n = 1000, coef = c(0.2, 0.3, 0, 2)) {
d <- data.frame(
x1 = runif(n, -1, 1),
x2 = runif(n, -1, 1)
)
d$mu <- exp(coef[1] + coef[2] * d$x1 + coef[3] * d$x2)
d$y <- rnbinom(n, mu = d$mu, size = d$mu / coef[4])
return(d)
}
## simulate data
set.seed(2007-05-15)
d <- dgp()
## model (with function negbin1)
nb1 <- negbin1(y ~ x1 + x2, data = d)
summary(nb1)
## model (with vglm from VGAM package)
nb2 <- vglm(y ~ x1 + x2, negbinomial(parallel = TRUE, zero = NULL), data = d, trace = TRUE)
summary(nb2)
## model (with gamlss from gamlss)
nb3 <- gamlss(y ~ x1 + x2, family = NBII(sigma.link = "identity"), data = d)
summary(nb3)
## comparison of coefficient vectors
cbind("negbin1" = coef(nb1), "vglm" = coef(nb2)[c(1,3,4)], "gamlss" = coef(nb3))
## comparison of log likelihoods
cbind("negbin1" = logLik(nb1), "vglm" = logLik(nb2), "gamlss" = logLik(nb3))
## model comparison
nb0 <- negbin1(y ~ x1, data = d)
AIC(nb0, nb1)
BIC(nb0, nb1)
lrtest(nb0, nb1)
## comparison of alpha
co <- coef(nb2, matrix = TRUE)
diff <- 1/ (exp(co["(Intercept)", "loge(size)"] - co["(Intercept)", "loge(mu)"]))
cbind("negbin1" = nb1$coefficients$alpha, "vglm" = diff, "gamlss" = nb3$sigma.coefficients)
## benefit of formula/terms interface
update(nb1, subset = x2 > 0)
head(model.frame(nb1))
head(model.matrix(nb1))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.