enbin: Extended Negative Binomial (NB2) Regression

Description Usage Arguments Details Value Examples

Description

Negative binomial models (NB2) with non-constant theta.

Usage

1
2
3
4
5
6
7
enbin(formula, data, subset, na.action,
  model = TRUE, y = TRUE, x = FALSE,
  control = enbin_control(...), ...)

enbin_fit(x, y, z = NULL, control)

enbin_control(maxit = 5000, start = NULL, grad = TRUE, hessian = TRUE, ...)

Arguments

formula

a formula expression of syntax y ~ x | z where y is the response and x and z are regressor variables for the location and the scale respectively.

data

an optional data frame containing the variables occurring in the formulas.

subset

an optional vector specifying a subset of observations to be used for fitting.

na.action

a function which indicates what should happen when the data contain NAs.

model

logical. If TRUE model frame is included as a component of the returned value.

x, y

for enbin: logical. If TRUE the model matrix and response vector used for fitting are returned as components of the returned value. For enbin_fit: x is a design matrix with regressors for the location and y is a vector of observations.

z

a design matrix with regressors for the scale.

...

arguments to be used to form the default control argument if it is not supplied directly.

control, maxit, start

a list of control parameters passed to optim .

grad

logical. Should gradients be used for optimization? If TRUE, the default method is "BFGS". Otherwise method = "Nelder-Mead" is used.

hessian

logical or character. Should a numeric approximation of the (negative) Hessian matrix be computed? Either FALSE (or equivalently "none") or TRUE. Alternatively, in the latter case, hessian = "numDeriv" could be specified to signal that the Hessian should be approximated by hessian. Another option is hessian = "numDeriv" so that optim is used for computing the Hessian.

Details

enbin fits negative binomial regression models with optionally covariate-dependent theta using analytical gradient based maximum likelihood estimation

y* ~ N(mu, theta)

,

The mean mu and scale theta are linked to two linear predictors

log(mu) = x'b

log(theta) = z'g

.

enbin_fit is the actual workhorse, where the fitting takes place.

A set of standard extractor functions for fitted model objects is available for objects of class "enbin", 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.enbin and coef.enbin for more details on some methods with non-standard arguments.

Value

enbin returns an object of class "enbin", i.e., a list with components as follows. enbin_fit returns an unclassed list with components up to df.

coefficients

a list with elements "location" and "scale" containing the coefficients from the respective models,

counts

count of function and gradient evaluations from optim,

convergence

convergence code from optim,

message

optional further information from optim,

vcov

covariance matrix of all parameters in the model,

residuals

a vector of raw residuals (observed - fitted),

fitted.values

a list with elements "location" and "scale" containing the latent fitted means and standard deviations,

method

the method argument passed to the optim call,

nobs

number of observations,

df

number of estimated parameters,

call

the original function call,

formula

the original formula,

terms

a list with elements "location", "scale" and "full" containing the terms objects for the respective models,

levels

a list with elements "location", "scale" and "full" containing the levels of the categorical regressors,

contrasts

a list with elements "location" and "scale" containing the contrasts corresponding to levels from the respective models,

model

the full model frame (if model = TRUE),

y

the numeric response vector (if y = TRUE),

x

a list with elements "location" and "scale" containing the model matrices from the respective models (if x = TRUE).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## data on alcohol and tobacco expenditures in Belgian households
data("RecreationDemand", package = "AER")

## model comparison of negative binomial (NB2) model with constant vs. non-constant theta
m1 <- enbin(trips ~ . - income, data = RecreationDemand)
m2 <- enbin(trips~ . - income | . - income, data = RecreationDemand)

## comparison of the two models
AIC(m1, m2)
BIC(m1, m2)

## comparison with glm.nb
if(require("MASS")) {
c1 <- glm.nb(trips ~ . - income, data = RecreationDemand)
summary(c1)
}

enbin documentation built on May 2, 2019, 5:57 p.m.