| Title: | Fast Fixed-Effects Estimation with the 'fixest' Interface |
| Version: | 0.4.0 |
| 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. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/leoliu0/fereg |
| BugReports: | https://github.com/leoliu0/fereg/issues |
| Depends: | R (≥ 4.2) |
| Imports: | stats |
| Suggests: | fixest, testthat (≥ 3.0.0), data.table, generics, Matrix |
| SystemRequirements: | Cargo (Rust's package manager), rustc (>= 1.85) |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| LazyData: | true |
| Config/roxygen2/version: | 8.1.1 |
| NeedsCompilation: | yes |
| Packaged: | 2026-10-14 12:13:57 UTC; leo |
| Author: | 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 <auleo.liu@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-22 16:30:02 UTC |
fereg: fast fixed-effects estimation with fixest's interface
Description
OLS, IV/2SLS, Poisson and logit estimation with any number of fixed effects, interactions and
varying slopes, weights and iid / heteroskedasticity-robust / multiway-clustered variances.
The interface and the numbers are those of fixest (feols(), fepois(), feglm(),
etable(), fixef(), ...); estimation runs in a parallel Rust core that eliminates the
largest fixed effect exactly and solves the rest by preconditioned conjugate gradient.
Details
Options: fereg.nthreads (threads, 0 = all cores; default all cores, capped at
OMP_THREAD_LIMIT, and 2 under R CMD check) and fereg.notes (print notes on removed
observations).
Author(s)
Maintainer: Leo Liu auleo.liu@gmail.com [copyright holder]
Authors:
Leo Liu auleo.liu@gmail.com [copyright holder]
Other contributors:
Authors of the bundled Rust crates (see inst/AUTHORS for each crate's authors and license) [contributor, copyright holder]
See Also
Useful links:
Table of estimation results
Description
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.
Usage
etable(
...,
vcov = NULL,
ssc = NULL,
tex = FALSE,
digits = 4,
digits.stats = 5,
fitstat = NULL,
keep = NULL,
drop = NULL,
family = NULL
)
Arguments
... |
|
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. |
Value
A data frame (class fereg_etable) or, with tex = TRUE, a character string (class
fereg_etable_tex).
Examples
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)
Fixed-effects OLS and IV estimation
Description
Drop-in replacement for fixest::feols(): same formula syntax, arguments and defaults, same
numbers. Estimation runs in the fereg Rust core.
Usage
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),
...
)
Arguments
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. |
Value
An object of class fereg (or fereg_multi for multiple estimations).
Examples
data(trade_toy, package = "fereg")
m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2)
m
summary(m, vcov = ~id)
Fixed-effects Poisson and logit estimation
Description
Drop-in replacements for fixest::fepois() and fixest::feglm() (Poisson and logit
families).
Usage
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),
...
)
Arguments
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 |
|
Value
An object of class fereg (or fereg_multi).
Examples
data(trade_toy, package = "fereg")
p <- fepois(count ~ x1 | id + year, trade_toy, nthreads = 2)
p
Methods for fereg objects
Description
Accessors, post-hoc variances, predictions and fixed effects of feols(), fepois() and
feglm() results, as in fixest.
Usage
## 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, ...)
Arguments
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. |
Value
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.
Examples
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))
Multiple estimations
Description
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.
Usage
## 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, ...)
Arguments
x, object |
A |
... |
Passed to the methods of each estimation. |
i |
Indices or names of estimations. |
Value
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.
Examples
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)
Fit statistics
Description
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.
Usage
fitstat(x, type, simplify = FALSE, ...)
Arguments
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. |
Value
An object of class fereg_fitstat (a named list), or a vector if simplify.
Examples
data(trade_toy, package = "fereg")
m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2)
fitstat(m, ~ n + r2 + wr2)
Fixed effects of an estimation
Description
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]].
Usage
fixef(object, ...)
Arguments
object |
A |
... |
Not used. |
Value
A list (class fereg.fixef) of named vectors, one per fixed effect / slope.
Examples
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
Description
R-squared variants
Usage
r2(x, type = "all")
Arguments
x |
A |
type |
Types among |
Value
A named numeric vector (NA where a type does not apply).
Examples
data(trade_toy, package = "fereg")
m <- feols(y ~ x1 + x2 | id + year, trade_toy, nthreads = 2)
r2(m)
Coefficient table accessors
Description
se(), tstat(), pvalue() and coeftable() as in fixest.
Usage
se(object, ...)
tstat(object, ...)
pvalue(object, ...)
coeftable(object, ...)
Arguments
object |
A |
... |
Passed to summary() ( |
Value
Named vectors, or the coefficient matrix for coeftable().
Examples
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)
Small-sample correction
Description
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.
Usage
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
)
Arguments
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 |
Value
An object of class ssc.type.
Examples
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))
Simulated panel for examples
Description
A small simulated panel: 600 observations of 60 units over 10 years.
Usage
data(trade_toy)
Format
A data frame with columns id, year, x1, x2, z (instrument), xe
(endogenous regressor), y, count (Poisson outcome) and binary (0/1 outcome).
Variance requests
Description
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.
Usage
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
)
Arguments
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). |
Details
-
NW(lag)/newey_west(lag): Newey-West (Bartlett kernel). With a unit and a time variable (vcov = NW ~ id + period, orpanel.id), only pairs of observations of the same unit enter; with a time variable only (NW ~ periodwithoutpanel.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'ssandwich::bwNeweyWest()rule for a time series. LabelNewey-West (L=<lag>). -
DK(lag)/driscoll_kraay(lag): Driscoll-Kraay on the per-period score sums; default lagfloor(T^(1/4)). LabelDriscoll-Kraay (L=<lag>). -
conley(cutoff, pixel, distance): Conley spatial HAC with fixest's uniform kernel.cutoffis in kilometers (a number) or a string such as"100km"/"60mi";NULLdeduces it from the coordinates as fixest does.pixel(same unit ascutoff, default 0) aggregates the scores on a grid first;distanceis"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_*, ...). LabelConley (<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^binteracts). -
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 withvcov = "crv3"(clusters guessed as for"cluster") orvcov = crv3 ~ g1 + g2. CRV3 needs the leave-one-out refits: after estimation (summary(m, vcov = "crv3")) the model is re-estimated.
Value
A fixest_vcov_request object, or the variance matrix of x.
Examples
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"))