feglm {fixest} | R Documentation |
Estimates GLM models with any number of fixed-effects.
feglm(fml, data, family = "poisson", offset, weights, start = NULL, etastart = NULL, mustart = NULL, fixef, fixef.tol = 1e-06, fixef.iter = 1000, glm.iter = 25, glm.tol = 1e-08, na_inf.rm = getFixest_na_inf.rm(), nthreads = getFixest_nthreads(), warn = TRUE, notes = getFixest_notes(), verbose = 0, combine.quick, ...) feglm.fit(y, X, fixef_mat, family = "poisson", offset, weights, start = NULL, etastart = NULL, mustart = NULL, fixef.tol = 1e-06, fixef.iter = 1000, glm.iter = 25, glm.tol = 1e-08, na_inf.rm = getFixest_na_inf.rm(), nthreads = getFixest_nthreads(), warn = TRUE, notes = getFixest_notes(), verbose = 0, ...) fepois(fml, data, offset, weights, start = NULL, etastart = NULL, mustart = NULL, fixef, fixef.tol = 1e-06, fixef.iter = 1000, glm.iter = 25, glm.tol = 1e-08, na_inf.rm = getFixest_na_inf.rm(), nthreads = getFixest_nthreads(), warn = TRUE, notes = getFixest_notes(), verbose = 0, combine.quick, ...)
fml |
A formula representing the relation to be estimated. For example: |
data |
A data.frame containing the necessary variables to run the model. The variables of the non-linear right hand side of the formula are identified with this |
family |
Family to be used for the estimation. Defaults to |
offset |
A formula or a numeric vector. An offset can be added to the estimation. If equal to a formula, it should be of the form (for example) |
weights |
A formula or a numeric vector. Each observation can be weighted, the weights must be greater than 0. If equal to a formula, it should be of one-sided: for example |
start |
Starting values for the coefficients. Can be: i) a numeric of length 1 (e.g. |
etastart |
Numeric vector of the same length as the data. Starting values for the linear predictor. Default is missing. |
mustart |
Numeric vector of the same length as the data. Starting values for the vector of means. Default is missing. |
fixef |
Character vector. The name/s of a/some variable/s within the dataset to be used as fixed-effects. These variables should contain the identifier of each observation (e.g., think of it as a panel identifier). |
fixef.tol |
Precision used to obtain the fixed-effects (ie cluster coefficients). Defaults to |
fixef.iter |
Maximum number of iterations in the step obtaining the fixed-effects (only in use for 2+ clusters). Default is 10000. |
glm.iter |
Number of iterations of the glm algorithm. Default is 25. |
glm.tol |
Tolerance level for the glm algorithm. Default is |
na_inf.rm |
Logical, default is |
nthreads |
Integer: Number of nthreads to be used (accelerates the algorithm via the use of openMP routines). The default is to use the total number of nthreads available minus two. You can set permanently the number of nthreads used within this package using the function |
warn |
Logical, default is |
notes |
Logical. By default, two notes are displayed: when NAs are removed (to show additional information) and when some observations are removed because of only 0 (or 0/1) outcomes in a fixed-effect (in Poisson/Neg. Bin./Logit models). To avoid displaying these messages, you can set |
verbose |
Integer, default is 0. It represents the level of information that should be reported during the optimisation process. If |
combine.quick |
Logical. When you combine different variables to transform them into a single fixed-effects you can do e.g. |
... |
Not currently used. |
y |
Numeric vector of the dependent variable. |
X |
Numeric matrix of the regressors. |
fixef_mat |
Matrix/data.frame of the fixed-effects. |
The core of the GLM are the weighted OLS estimations. These estimations are performed with feols
. The method used to demean each variable along the fixed-effects is based on Berge (2018), since this is the same problem to solve as for the Gaussian case in a ML setup.
feglm.fit
: Matrix method for fixed-effects GLM estimation
fepois
: Fixed-effects Poisson estimation
You can combine two variables to make it a new fixed-effect using ^
. The syntax is as follows: fe_1^fe_2
. Here you created a new variable which is the combination of the two variables fe_1 and fe_2. This is identical to doing paste0(fe_1, "_", fe_2)
but more convenient.
Note that pasting is a costly operation, especially for large data sets. Thus, the internal algorithm uses a numerical trick which is fast, but the drawback is that the identity of each observation is lost (i.e. they are now equal to a meaningless number instead of being equal to paste0(fe_1, "_", fe_2)
). These “identities” are useful only if you're interested in the value of the fixed-effects (that you can extract with fixef.fixest
). If you're only interested in coefficients of the variables, it doesn't matter. Anyway, you can use combine.quick = FALSE
to tell the internal algorithm to use paste
instead of the numerical trick. By default, the numerical trick is performed only for large data sets.
You can add variables with varying slopes in the fixed-effect part of the formula. The syntax is as follows: cluster_var[var1, var2]. Here the variables var1 and var2 will be with varying slopes (one slope per value in cluster_var) and the fixed-effect cluster_var will also be added.
To add only the variables with varying slopes and not the fixed-effect, use double square brackets: cluster_var[[var1, var2]].
In other words:
cluster_var[var1, var2] is equivalent to cluster_var + cluster_var[[var1]] + cluster_var[[var2]]
cluster_var[[var1, var2]] is equivalent to cluster_var[[var1]] + cluster_var[[var2]]
@seealso
See also summary.fixest
to see the results with the appropriate standard-errors, fixef.fixest
to extract the cluster coefficients, and the functions esttable
and esttex
to visualize the results of multiple estimations.
And other estimation methods: femlm
, feglm
, fepois
, fenegbin
, feNmlm
.
Laurent Berge
Berge, Laurent, 2018, "Efficient estimation of maximum likelihood models with multiple fixed-effects: the R package FENmlm." CREA Discussion Papers, 13 (https://wwwen.uni.lu/content/download/110162/1299525/file/2018_13).
For models with multiple fixed-effects:
Gaure, Simen, 2013, "OLS with multiple high dimensional category variables", Computational Statistics & Data Analysis 66 pp. 8–18
See also summary.fixest
to see the results with the appropriate standard-errors, fixef.fixest
to extract the cluster coefficients, and the functions esttable
and esttex
to visualize the results of multiple estimations.
And other estimation methods: feols
, femlm
, fenegbin
, feNmlm
.
# default is a poisson model res = feglm(Sepal.Length ~ Sepal.Width + Petal.Length | Species, iris) # with the fit method: res_bis = feglm.fit(iris$Sepal.Length, iris[, 2:3], iris$Species)