Skip to contents

Estimate a Random Effects Negative Binomial regression model

Usage

renb(
  formula,
  group_var,
  data,
  method = "NM",
  max.iters = 1000,
  verbose = FALSE,
  stderr = "normal",
  bootstraps = NULL,
  offset = NULL,
  weights = NULL,
  keep_data = TRUE,
  print.level = NULL
)

Arguments

formula

an R formula.

group_var

the grouping variable(s) for the random effects (e.g., individual ID or other panel ID variables). Required. Several columns are combined into one panel identifier.

data

a dataframe that has all of the variables in the formula.

method

a method to use for optimization in the maximum likelihood estimation. For options, see maxLik. Note that "BHHH" is not available for this function due to the implementation for the random effects.

max.iters

the maximum number of iterations to allow the optimization method to perform.

verbose

logical; if TRUE, print the progress of the optimization.

stderr

the type of standard errors: "normal" (Hessian-based, the default), "robust" (sandwich; clustered by panel because the likelihood has one contribution per panel), or "boot" (bootstrap that resamples whole panels). Giving bootstraps without stderr also requests bootstrapped standard errors.

bootstraps

Optional integer specifying the number of bootstrap samples to be used for estimating standard errors. Whole panels (groups) are resampled, so the standard errors account for the correlation within panels. If not specified, no bootstrapping is performed.

offset

an optional character vector of offset column names (summed when several are given; on the log scale). An offset can instead be given with offset() in formula; use only one of the two.

weights

the name of a column of data, or a numeric vector with one value per row of data, of frequency weights of the panels: a panel with weight w counts as w independent panels in the log-likelihood, the robust covariance, BIC and the bootstrap. Weights must be constant within each panel. Bootstrap standard errors need whole-number weights.

keep_data

logical; if FALSE, the training data are not stored in the fitted object (saving memory). predict() then needs newdata, and fitted()/residuals() are unavailable.

print.level

deprecated; use verbose.

Value

An object of class flexCountReg which is a list with the following components:

  • model: the fitted model object.

  • data: the data frame used to fit the model.

  • call: the matched call.

  • formula: the formula used to fit the model.

Details

This function estimates a random effects negative binomial (RENB) regression model. This model is based on the NB-1 model. The PDF for the RENB is: $$f(y_{it}|\lambda_{it}, a, b) = \frac{\Gamma(a+b) \Gamma(a + \sum_{t = 1}^{n_i} \lambda_{it}) \Gamma(b + \sum_{t=1}^{n_i}y_{it})} {\Gamma(a) \Gamma(b) \Gamma(a + b + \sum_{t=1}^{n_i}\lambda_{it} + \sum_{t=1}^{n_i}y_{it})} \prod_{t=1}^{n_i} \frac{\Gamma(\lambda_{it}+y_{it})}{\Gamma(\lambda_{it})\Gamma(y_{it}+1)}$$

Where \(y_{it}\) is the count outcome for individual \(i\) at time \(t\), and \(\lambda_{it}\) is the latent Poisson mean parameter for individual \(i\) at time \(t\). The parameters \(a\) and \(b\) are the shape parameters for the beta distribution that is used to model the random effects. The RENB model allows for overdispersion in the count data and accounts for unobserved heterogeneity across individuals by including random effects in the model. This formulation follows the approach described in the paper by Hausman, Hall, and Griliches (1984) for modeling panel data with random effects.

The marginal mean and marginal variance of the RENB model are given by: $$E[y_{it}] = \lambda_{it}\frac{b}{a-1}=\mu_it=exp(X_{it}\beta)$$

$$Var[y_{it}] = \frac{a+b-1}{a-2}\mu_{it} + \frac{a+b-1}{b(a-2)} \mu_{it}^2$$

Thus, the formulation of the model estimated here allows the use of the estimated coefficients to directly compute the marginal mean.

Note that the RENB model is a panel data model, and the group_var argument must be specified to indicate the grouping variable(s) for the random effects. The model is estimated using maximum likelihood estimation, and the optimization is performed using the maxLik package. The user can specify the optimization method and maximum iterations.

References

Hausman, Jerry A., Bronwyn H. Hall, and Zvi Griliches. "Econometric models for count data with an application to the patents-R&D relationship." Econometrica: Journal of the Econometric Society (1984): 909-938.

Examples

# \donttest{
## RENB Model
data("washington_roads")
washington_roads$AADTover10k <- 
  ifelse(washington_roads$AADT > 10000, 1, 0) # create a dummy variable
renb.mod <- renb(Animal ~ lnaadt + speed50 + ShouldWidth04 + AADTover10k,
                                data=washington_roads,
                                offset = "lnlength",
                                group_var="ID",
                                method="nm",
                                max.iters = 1000)
summary(renb.mod)
#> Call:
#> renb(formula = Animal ~ lnaadt + speed50 + ShouldWidth04 + AADTover10k, 
#>     group_var = "ID", data = washington_roads, method = "nm", 
#>     max.iters = 1000, offset = "lnlength")
#> 
#> Model: renb | optimizer: NM
#> Iterations: 680 
#> Convergence: successful convergence 
#> 
#> Coefficients (standard errors: Hessian-based):
#>               Estimate Std. Error z value Pr(>|z|)    
#> (Intercept)     -9.466      1.360   -6.96  3.5e-12 ***
#> lnaadt           0.978      0.158    6.19  6.1e-10 ***
#> speed50         -0.966      0.350   -2.76  0.00572 ** 
#> ShouldWidth04   -0.363      0.277   -1.31  0.18991    
#> AADTover10k     -0.946      0.529   -1.79  0.07406 .  
#> ln(a-1)          2.977      0.771    3.86  0.00011 ***
#> ln(b)            0.573      0.757    0.76  0.44882    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> Offset: lnlength (coefficient fixed at 1)
#> 
#> Log-likelihood: -263.831 | AIC: 541.661 | BIC: 571.261 
#> N: 1501 | panels: 507
# }