| Title: | Fast Fixed-Effects Estimation with the 'fixest' Interface |
|---|---|
| Description: | Ordinary least squares, two-stage least squares, Poisson and logit regressions with any number of high-dimensional fixed effects, interactions of fixed effects, varying slopes, weights and iid, heteroskedasticity-robust (HC1, HC2, HC3), multiway-clustered, CRV3, Newey-West, Driscoll-Kraay or Conley standard errors. The formula syntax, arguments, results and methods follow the 'fixest' package and reproduce its estimates. The computations run in a parallel 'Rust' library that eliminates the largest fixed effect exactly and solves for the others by preconditioned conjugate gradient. |
| Authors: | Leo Liu [aut, cre, cph], Authors of the bundled Rust crates [ctb, cph] (see inst/AUTHORS for each crate's authors and license) |
| Maintainer: | Leo Liu <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0 |
| Built: | 2026-10-23 10:01:23 UTC |
| Source: | https://github.com/cran/fereg |
Side-by-side table of several estimations in fixest's etable() layout: coefficients with
standard errors in parentheses and significance stars, fixed effects, variance type and fit
statistics.
etable( ..., vcov = NULL, ssc = NULL, tex = FALSE, digits = 4, digits.stats = 5, fitstat = NULL, keep = NULL, drop = NULL, family = NULL )etable( ..., vcov = NULL, ssc = NULL, tex = FALSE, digits = 4, digits.stats = 5, fitstat = NULL, keep = NULL, drop = NULL, family = NULL )
... |
|
vcov, ssc
|
Variance for every model (see summary()); |
tex |
Return LaTeX code instead of a data frame. |
digits |
Significant digits of coefficients and standard errors. |
digits.stats |
Digits of the fit statistics, as in fixest: a number (significant digits,
at least one decimal for large values), or |
fitstat |
Fit statistics (see |
keep, drop
|
Character vectors of regular expressions (Perl syntax) selecting the
coefficient rows, as in fixest: |
family |
Show the row "Family" (OLS, Poisson, Logit); by default only when the models are of different families. |
A data frame (class fereg_etable) or, with tex = TRUE, a character string (class
fereg_etable_tex).
data(trade_toy, package = "fereg") m1 <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) m2 <- fepois(count ~ x1 + x2 | id + year, trade_toy, nthreads = 2) etable(m1, m2, vcov = ~id) etable(m1, tex = TRUE)data(trade_toy, package = "fereg") m1 <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) m2 <- fepois(count ~ x1 + x2 | id + year, trade_toy, nthreads = 2) etable(m1, m2, vcov = ~id) etable(m1, tex = TRUE)
Drop-in replacement for fixest::feols(): same formula syntax, arguments and defaults, same
numbers. Estimation runs in the fereg Rust core.
feols( fml, data, vcov, weights, offset, subset, split, fsplit, cluster, se, ssc, panel.id, fixef.rm = "perfect_fit", fixef.tol = 1e-08, fixef.iter = 16000, collin.tol = 1e-09, nthreads = getOption("fereg.nthreads", default_threads()), lean = FALSE, notes = getOption("fereg.notes", TRUE), ... )feols( fml, data, vcov, weights, offset, subset, split, fsplit, cluster, se, ssc, panel.id, fixef.rm = "perfect_fit", fixef.tol = 1e-08, fixef.iter = 16000, collin.tol = 1e-09, nthreads = getOption("fereg.nthreads", default_threads()), lean = FALSE, notes = getOption("fereg.notes", TRUE), ... )
fml |
A formula |
data |
A data frame (or a list of equal-length vectors). |
vcov |
Variance type, as in fixest: a string ( |
weights |
Observation weights: a one-sided formula ( |
offset |
Offset on the link scale: a one-sided formula, a column name or a vector. |
subset |
Rows to use: logical or integer vector, or a one-sided formula ( |
split, fsplit
|
A one-sided formula (or column name): one estimation per value of the
variable; |
cluster, se
|
Former fixest ways of requesting a variance type ( |
ssc |
Small-sample correction, see |
panel.id |
Panel identifiers, as in fixest: a formula |
fixef.rm |
|
fixef.tol, fixef.iter
|
Tolerance and iteration cap of the fixed-effects solver. |
collin.tol |
Collinearity tolerance (fixest rule). |
nthreads |
Number of threads; |
lean |
If |
notes |
Print notes about removed observations (option |
... |
Not used; unknown arguments are an error. |
An object of class fereg (or fereg_multi for multiple estimations).
data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) m summary(m, vcov = ~id)data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) m summary(m, vcov = ~id)
Drop-in replacements for fixest::fepois() and fixest::feglm() (Poisson and logit
families).
fepois( fml, data, vcov, offset, weights, subset, split, fsplit, cluster, se, ssc, panel.id, fixef.rm = "perfect_fit", fixef.tol = 1e-08, fixef.iter = 16000, glm.iter = 25, glm.tol = 1e-08, collin.tol = 1e-09, nthreads = getOption("fereg.nthreads", default_threads()), lean = FALSE, notes = getOption("fereg.notes", TRUE), ... ) feglm( fml, data, family = "logit", vcov, offset, weights, subset, split, fsplit, cluster, se, ssc, panel.id, fixef.rm = "perfect_fit", fixef.tol = 1e-08, fixef.iter = 16000, glm.iter = 25, glm.tol = 1e-08, collin.tol = 1e-09, nthreads = getOption("fereg.nthreads", default_threads()), lean = FALSE, notes = getOption("fereg.notes", TRUE), ... )fepois( fml, data, vcov, offset, weights, subset, split, fsplit, cluster, se, ssc, panel.id, fixef.rm = "perfect_fit", fixef.tol = 1e-08, fixef.iter = 16000, glm.iter = 25, glm.tol = 1e-08, collin.tol = 1e-09, nthreads = getOption("fereg.nthreads", default_threads()), lean = FALSE, notes = getOption("fereg.notes", TRUE), ... ) feglm( fml, data, family = "logit", vcov, offset, weights, subset, split, fsplit, cluster, se, ssc, panel.id, fixef.rm = "perfect_fit", fixef.tol = 1e-08, fixef.iter = 16000, glm.iter = 25, glm.tol = 1e-08, collin.tol = 1e-09, nthreads = getOption("fereg.nthreads", default_threads()), lean = FALSE, notes = getOption("fereg.notes", TRUE), ... )
fml |
A formula |
data |
A data frame (or a list of equal-length vectors). |
vcov |
Variance type, as in fixest: a string ( |
offset |
Offset on the link scale: a one-sided formula, a column name or a vector. |
weights |
Observation weights: a one-sided formula ( |
subset |
Rows to use: logical or integer vector, or a one-sided formula ( |
split, fsplit
|
A one-sided formula (or column name): one estimation per value of the
variable; |
cluster, se
|
Former fixest ways of requesting a variance type ( |
ssc |
Small-sample correction, see |
panel.id |
Panel identifiers, as in fixest: a formula |
fixef.rm |
|
fixef.tol, fixef.iter
|
Tolerance and iteration cap of the fixed-effects solver. |
glm.tol, glm.iter
|
IRLS convergence tolerance (relative deviance change) and iteration cap. |
collin.tol |
Collinearity tolerance (fixest rule). |
nthreads |
Number of threads; |
lean |
If |
notes |
Print notes about removed observations (option |
... |
Not used; unknown arguments are an error. |
family |
|
An object of class fereg (or fereg_multi).
data(trade_toy, package = "fereg") p <- fepois(count ~ x1 | id + year, trade_toy, nthreads = 2) pdata(trade_toy, package = "fereg") p <- fepois(count ~ x1 | id + year, trade_toy, nthreads = 2) p
A fereg_multi object is a list of fereg objects (one per estimation, fixest order:
sample, fixed effects, dependent variable, right-hand side). Methods apply to every
estimation.
## S3 method for class 'fereg_multi' print(x, ...) ## S3 method for class 'fereg_multi' x[i] ## S3 method for class 'fereg_multi' as.list(x, ...) ## S3 method for class 'fereg_multi' summary(object, ...) ## S3 method for class 'fereg_multi' coef(object, ...) ## S3 method for class 'fereg_multi' nobs(object, ...)## S3 method for class 'fereg_multi' print(x, ...) ## S3 method for class 'fereg_multi' x[i] ## S3 method for class 'fereg_multi' as.list(x, ...) ## S3 method for class 'fereg_multi' summary(object, ...) ## S3 method for class 'fereg_multi' coef(object, ...) ## S3 method for class 'fereg_multi' nobs(object, ...)
x, object
|
A |
... |
Passed to the methods of each estimation. |
i |
Indices or names of estimations. |
print(): x, invisibly. [ and summary(): a fereg_multi object. as.list():
a list of fereg objects. coef(): data frame with one row per estimation and one column
per coefficient. nobs(): number of observations of each estimation.
data(trade_toy, package = "fereg") ms <- feols(y ~ csw(x1, x2) | id + year, trade_toy, nthreads = 2) ms coef(ms) nobs(ms) summary(ms[2], vcov = ~id)data(trade_toy, package = "fereg") ms <- feols(y ~ csw(x1, x2) | id + year, trade_toy, nthreads = 2) ms coef(ms) nobs(ms) summary(ms[2], vcov = ~id)
Accessors, post-hoc variances, predictions and fixed effects of feols(), fepois() and
feglm() results, as in fixest.
## S3 method for class 'fereg' summary( object, vcov = NULL, ssc = NULL, cluster = NULL, se = NULL, stage = 2, ... ) ## S3 method for class 'fereg' coef(object, ...) ## S3 method for class 'fereg' vcov( object, vcov = NULL, ssc = NULL, attr = FALSE, cluster = NULL, se = NULL, ... ) ## S3 method for class 'fereg' confint( object, parm, level = 0.95, vcov = NULL, ssc = NULL, cluster = NULL, se = NULL, ... ) ## S3 method for class 'fereg' nobs(object, ...) ## S3 method for class 'fereg' residuals( object, type = c("response", "deviance", "pearson", "working"), na.rm = TRUE, ... ) ## S3 method for class 'fereg' fitted(object, type = c("response", "link"), na.rm = TRUE, ...) ## S3 method for class 'fereg' predict(object, newdata, type = c("response", "link"), ...) ## S3 method for class 'fereg' logLik(object, ...) ## S3 method for class 'fereg' AIC(object, ..., k = 2) ## S3 method for class 'fereg' BIC(object, ...) ## S3 method for class 'fereg' deviance(object, ...) ## S3 method for class 'fereg' sigma(object, ...)## S3 method for class 'fereg' summary( object, vcov = NULL, ssc = NULL, cluster = NULL, se = NULL, stage = 2, ... ) ## S3 method for class 'fereg' coef(object, ...) ## S3 method for class 'fereg' vcov( object, vcov = NULL, ssc = NULL, attr = FALSE, cluster = NULL, se = NULL, ... ) ## S3 method for class 'fereg' confint( object, parm, level = 0.95, vcov = NULL, ssc = NULL, cluster = NULL, se = NULL, ... ) ## S3 method for class 'fereg' nobs(object, ...) ## S3 method for class 'fereg' residuals( object, type = c("response", "deviance", "pearson", "working"), na.rm = TRUE, ... ) ## S3 method for class 'fereg' fitted(object, type = c("response", "link"), na.rm = TRUE, ...) ## S3 method for class 'fereg' predict(object, newdata, type = c("response", "link"), ...) ## S3 method for class 'fereg' logLik(object, ...) ## S3 method for class 'fereg' AIC(object, ..., k = 2) ## S3 method for class 'fereg' BIC(object, ...) ## S3 method for class 'fereg' deviance(object, ...) ## S3 method for class 'fereg' sigma(object, ...)
object |
A |
vcov, ssc, cluster, se
|
Post-hoc variance (same forms as in |
stage |
IV only: |
... |
Not used. |
attr |
Add the attributes |
parm |
Coefficients (names or indices); all by default. |
level |
Confidence level. |
type |
|
na.rm |
|
newdata |
A data frame for predictions; fixed-effect levels absent at estimation give NA. |
k |
AIC penalty per parameter. |
summary(): the fereg object with the requested variance (coefficient table in
$coeftable); for IV with stage = 1 or 1:2, the requested stages (a fereg_multi when
there are several). coef(): named vector of coefficients. vcov(): variance matrix.
confint(): data frame of lower and upper bounds, one row per coefficient. nobs(): number
of observations. resid(), fitted(), predict(): numeric vectors. logLik(): object of
class logLik. AIC(), BIC(), deviance(), sigma(): numbers.
data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) summary(m, vcov = "hetero") coef(m) vcov(m, vcov = ~id) confint(m, level = 0.9) head(predict(m, newdata = trade_toy)) c(AIC = AIC(m), BIC = BIC(m))data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) summary(m, vcov = "hetero") coef(m) vcov(m, vcov = ~id) confint(m, level = 0.9) head(predict(m, newdata = trade_toy)) c(AIC = AIC(m), BIC = BIC(m))
Same types and names as fixest's fitstat(): n, rmse, r2, ar2, wr2, war2, ll,
pr2, apr2, cor2 (sq.cor), aic, bic, f, my, g and, for IV, ivf1
(ivf), ivwald1 (ivwald), wh and sargan.
fitstat(x, type, simplify = FALSE, ...)fitstat(x, type, simplify = FALSE, ...)
x |
A |
type |
A character vector of types, or a one-sided formula ( |
simplify |
Return a plain vector when every statistic is a single number. |
... |
Not used. |
An object of class fereg_fitstat (a named list), or a vector if simplify.
data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) fitstat(m, ~ n + r2 + wr2)data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) fitstat(m, ~ n + r2 + wr2)
Fixed-effect coefficients with fixest's normalization: the first fixed effect is free, and in
every connected component one level of each other fixed effect is set to 0 (counted in the
references attribute). Varying slopes are listed as fe[[x]].
fixef(object, ...)fixef(object, ...)
object |
A |
... |
Not used. |
A list (class fereg.fixef) of named vectors, one per fixed effect / slope.
data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) fe <- fixef(m) summary(fe) head(fe$year)data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) fe <- fixef(m) summary(fe) head(fe$year)
R-squared variants
r2(x, type = "all")r2(x, type = "all")
x |
A |
type |
Types among |
A named numeric vector (NA where a type does not apply).
data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) r2(m)data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) r2(m)
se(), tstat(), pvalue() and coeftable() as in fixest.
se(object, ...) tstat(object, ...) pvalue(object, ...) coeftable(object, ...)se(object, ...) tstat(object, ...) pvalue(object, ...) coeftable(object, ...)
object |
A |
... |
Passed to summary() ( |
Named vectors, or the coefficient matrix for coeftable().
data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) se(m) pvalue(m, vcov = "hetero") coeftable(m, vcov = ~id)data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) se(m) pvalue(m, vcov = "hetero") coeftable(m, vcov = ~id)
Same arguments and defaults as fixest's ssc(). As in fixest, the correction depends on the
variance type: heteroskedasticity-robust, Newey-West, Driscoll-Kraay and Conley variances use
K.fixef = "full" (no nesting), Newey-West and Driscoll-Kraay apply G.adj with G = the
number of time periods, Conley uses n / (n - K), and HC2 / HC3 use no correction at all.
ssc( K.adj = TRUE, K.fixef = "nonnested", K.exact = FALSE, G.adj = TRUE, G.df = "min", t.df = "min", adj, fixef.K, cluster.adj, cluster.df )ssc( K.adj = TRUE, K.fixef = "nonnested", K.exact = FALSE, G.adj = TRUE, G.df = "min", t.df = "min", adj, fixef.K, cluster.adj, cluster.df )
K.adj |
Multiply the variance by |
K.fixef |
How fixed effects count in |
K.exact |
Count the exact number of redundant fixed-effect coefficients. |
G.adj |
Multiply clustered variances by |
G.df |
|
t.df |
Degrees of freedom of the t distribution with clustered, Newey-West and
Driscoll-Kraay variances: |
adj, fixef.K, cluster.adj, cluster.df
|
Former fixest names of |
An object of class ssc.type.
data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) summary(m, vcov = ~id, ssc = ssc(K.adj = FALSE, G.adj = FALSE))data(trade_toy, package = "fereg") m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2) summary(m, vcov = ~id, ssc = ssc(K.adj = FALSE, G.adj = FALSE))
A small simulated panel: 600 observations of 60 units over 10 years.
data(trade_toy)data(trade_toy)
A data frame with columns id, year, x1, x2, z (instrument), xe
(endogenous regressor), y, count (Poisson outcome) and binary (0/1 outcome).
fixest's request objects and helpers for the vcov argument of feols(), fepois(),
feglm(), summary(), vcov(), confint() and etable().
They return objects of class fixest_vcov_request (the same structure as fixest's, so both
packages' requests are accepted). Called with an estimation as first argument, the vcov_*()
functions return its variance matrix instead, as in fixest.
NW(lag = NULL) newey_west(lag = NULL) DK(lag = NULL) driscoll_kraay(lag = NULL) conley(cutoff = NULL, pixel = NULL, distance = NULL) vcov_hetero( x, type = "hc1", exact = TRUE, boot.size = NULL, ssc = NULL, vcov_fix = TRUE ) vcov_cluster(x, cluster = NULL, ssc = NULL, vcov_fix = TRUE) vcov_crv3(x, cluster = NULL, ssc = NULL) vcov_NW(x, unit = NULL, time = NULL, lag = NULL, ssc = NULL, vcov_fix = TRUE) vcov_DK(x, time = NULL, lag = NULL, ssc = NULL, vcov_fix = TRUE) vcov_conley( x, lat = NULL, lon = NULL, cutoff = NULL, pixel = 0, distance = "triangular", ssc = NULL, vcov_fix = TRUE )NW(lag = NULL) newey_west(lag = NULL) DK(lag = NULL) driscoll_kraay(lag = NULL) conley(cutoff = NULL, pixel = NULL, distance = NULL) vcov_hetero( x, type = "hc1", exact = TRUE, boot.size = NULL, ssc = NULL, vcov_fix = TRUE ) vcov_cluster(x, cluster = NULL, ssc = NULL, vcov_fix = TRUE) vcov_crv3(x, cluster = NULL, ssc = NULL) vcov_NW(x, unit = NULL, time = NULL, lag = NULL, ssc = NULL, vcov_fix = TRUE) vcov_DK(x, time = NULL, lag = NULL, ssc = NULL, vcov_fix = TRUE) vcov_conley( x, lat = NULL, lon = NULL, cutoff = NULL, pixel = 0, distance = "triangular", ssc = NULL, vcov_fix = TRUE )
lag |
Number of lags ( |
cutoff, pixel, distance
|
Conley options, see Details. |
x |
An estimation ( |
type |
|
exact, boot.size
|
|
ssc |
A small-sample correction ( |
vcov_fix |
Must be |
cluster |
Cluster variables: a character vector or a one-sided formula. |
unit, time
|
Unit and time variables of Newey-West / Driscoll-Kraay (names or one-sided
formulas); by default the variables of |
lat, lon
|
Latitude and longitude variables (names or one-sided formulas, degrees). |
NW(lag) / newey_west(lag): Newey-West (Bartlett kernel). With a unit and a time variable
(vcov = NW ~ id + period, or panel.id), only pairs of observations of the same unit enter;
with a time variable only (NW ~ period without panel.id) it is the time-series estimator.
Time is the dense rank of the time variable over the estimation sample (gaps are collapsed).
Default lag: floor(T^(1/4)) for panels, fixest's sandwich::bwNeweyWest() rule for a time
series. Label Newey-West (L=<lag>).
DK(lag) / driscoll_kraay(lag): Driscoll-Kraay on the per-period score sums; default lag
floor(T^(1/4)). Label Driscoll-Kraay (L=<lag>).
conley(cutoff, pixel, distance): Conley spatial HAC with fixest's uniform kernel. cutoff
is in kilometers (a number) or a string such as "100km" / "60mi"; NULL deduces it from
the coordinates as fixest does. pixel (same unit as cutoff, default 0) aggregates the
scores on a grid first; distance is "triangular" (default, fixest's flat-earth distance)
or "spherical" (great-circle). Latitude and longitude come from the formula
(conley(100) ~ lat + lon) or are guessed from the column names (lat, latitude, lat_*;
lon, lng, long, longitude, lon_*, ...). Label Conley (<cutoff><km|mi>).
vcov_hetero(type): "hc1" (heteroskedasticity-robust, default), "hc2" or "hc3". HC2 and
HC3 use the exact leverage of the full model (fixed effects included) and no small-sample
correction; they are not defined for IV estimations.
vcov_cluster(cluster): clustering on up to four variables (names or a formula; a^b
interacts).
vcov_crv3(cluster): fereg extension (fixest has no CRV3): leave-one-cluster-out
jackknife centered at the full-sample coefficients (pyfixest's CRV3), with fixest's
cluster small-sample correction and multiway inclusion-exclusion. Also requested with
vcov = "crv3" (clusters guessed as for "cluster") or vcov = crv3 ~ g1 + g2. CRV3 needs
the leave-one-out refits: after estimation (summary(m, vcov = "crv3")) the model is
re-estimated.
A fixest_vcov_request object, or the variance matrix of x.
data(trade_toy, package = "fereg") m <- feols(y ~ x1 | id + year, trade_toy, panel.id = ~id + year, nthreads = 2) summary(m, vcov = NW(1)) summary(m, vcov = DK ~ year) summary(m, vcov = vcov_hetero(type = "hc2"))data(trade_toy, package = "fereg") m <- feols(y ~ x1 | id + year, trade_toy, panel.id = ~id + year, nthreads = 2) summary(m, vcov = NW(1)) summary(m, vcov = DK ~ year) summary(m, vcov = vcov_hetero(type = "hc2"))