Econometric models in PyTorch
Trex brings familiar econometric objectives into tensor-based workflows: least squares with fixed effects, moment restrictions, choice probabilities, panel counterfactuals and learned simulation models.
The library is useful when an estimator needs to share data, derivatives or hardware with a PyTorch model. It is also a research collection: interfaces, computational costs and available inference differ across modules. These guides explain those distinctions alongside worked examples.
Regression & inference
Fit weighted and fixed-effect regressions, binary/count likelihoods, or learn a robust regression score. Understand which covariance each fit returns.
Moment restrictions
Build GMM or GEL from observation-level moments. Move to conditional moments when instruments impose a function-valued restriction.
Structural choice
Estimate static choice probabilities, or solve and estimate dynamic replacement decisions with NFXP and Hotz–Miller.
Panel counterfactuals
Compare SC and synthetic DID, reconstruct missing cells, or fit latent-factor GLMs and grouped heterogeneity.
Simulation models
Learn tabular distributions with WGAN, PTGAN and diffusion, evaluate their diagnostics, and understand the separate role of optional language-model generators.
Interfaces & examples
Start with a complete regression fit, consult the method selection guide, then use the API reference for signatures and options.
A recommended reading path
- Install from the repository. The unrelated PyPI package named
trexis not this library. - Work through the quickstart and numerical conventions.
- Pick a method by its assumptions and target, not merely its ability to fit a tensor. Every method guide connects a criterion to code, diagnostics and interpretation.
What the examples establish
For hardware choices, see the CPU, Metal and CUDA performance study: identical input files, 14 workloads at three sizes, repeated timings, and explicit solution-agreement and backend-support checks.
Numerical vignettes execute against the documented source and show their actual results. Small synthetic examples illustrate identification and computation; they are not broad claims about estimator rankings or accelerator speed. The panel vignette additionally uses the attributed California Proposition 99 fixture.
The reference-test record documents comparisons with R, Statsmodels, SciPy and linearmodels. Dynamic-choice and low-rank-logit standard errors are not implemented; generative-model fit quality does not establish causal validity. These limits are discussed where they affect an example.
Build provenance records the source revision and software environment used for this site. Contributing explains how documentation changes reach gh-pages.