Negative Binomial model fitting with high-dimensional k-way fixed effects
Source:R/fenegbin.R
fenegbin.Rd
A routine that uses the same internals as feglm
.
Usage
fenegbin(
formula = NULL,
data = NULL,
weights = NULL,
beta_start = NULL,
eta_start = NULL,
init_theta = NULL,
link = c("log", "identity", "sqrt"),
control = NULL
)
Arguments
- formula
an object of class
"formula"
: a symbolic description of the model to be fitted.formula
must be of typey ~ x | k
, where the second part of the formula refers to factors to be concentrated out. It is also possible to pass clustering variables tofeglm
asy ~ x | k | c
.- data
an object of class
"data.frame"
containing the variables in the model. The expected input is a dataset with the variables specified informula
and a number of rows at least equal to the number of variables in the model.- weights
an optional string with the name of the 'prior weights' variable in
data
.- beta_start
an optional vector of starting values for the structural parameters in the linear predictor. Default is \(\boldsymbol{\beta} = \mathbf{0}\).
- eta_start
an optional vector of starting values for the linear predictor.
- init_theta
an optional initial value for the theta parameter (see
glm.nb
).- link
the link function. Must be one of
"log"
,"sqrt"
, or"identity"
.- control
a named list of parameters for controlling the fitting process. See
feglm_control
for details.
Value
A named list of class "feglm"
. The list contains the following
eighteen elements:
- coefficients
a named vector of the estimated coefficients
- eta
a vector of the linear predictor
- weights
a vector of the weights used in the estimation
- hessian
a matrix with the numerical second derivatives
- deviance
the deviance of the model
- null_deviance
the null deviance of the model
- conv
a logical indicating whether the model converged
- iter
the number of iterations needed to converge
- theta
the estimated theta parameter
- iter.outer
the number of outer iterations
- conv.outer
a logical indicating whether the outer loop converged
- nobs
a named vector with the number of observations used in the estimation indicating the dropped and perfectly predicted observations
- lvls_k
a named vector with the number of levels in each fixed effects
- nms_fe
a list with the names of the fixed effects variables
- formula
the formula used in the model
- data
the data used in the model after dropping non-contributing observations
- family
the family used in the model
- control
the control list used in the model
Examples
# check the feglm examples for the details about clustered standard errors
# subset trade flows to avoid fitting time warnings during check
set.seed(123)
trade_2006 <- trade_panel[trade_panel$year == 2006, ]
trade_2006 <- trade_2006[sample(nrow(trade_2006), 700), ]
mod <- fenegbin(
trade ~ log_dist + lang + cntg + clny | exp_year + imp_year,
trade_2006
)
summary(mod)
#> Formula: trade ~ log_dist + lang + cntg + clny | exp_year + imp_year
#> <environment: 0x568089444240>
#>
#> Family: Negative Binomial(1.9067)
#>
#> Estimates:
#>
#> | | Estimate | Std. Error | z value | Pr(>|z|) |
#> |----------|----------|------------|----------|------------|
#> | log_dist | -1.1863 | 0.0651 | -18.2286 | 0.0000 *** |
#> | lang | 0.6575 | 0.1208 | 5.4413 | 0.0000 *** |
#> | cntg | 0.4718 | 0.2304 | 2.0477 | 0.0406 * |
#> | clny | 0.5040 | 0.2261 | 2.2293 | 0.0258 * |
#>
#> Significance codes: *** 99.9%; ** 99%; * 95%; . 90%
#>
#> Number of observations: Full 700; Missing 0; Perfect classification 0
#>
#> Number of Fisher Scoring iterations: 1
#> Number of outer iterations: 4
#> theta= 1.907, std. error= 0.115