# Econometrust
A Python library for econometric regression analysis, implemented in Rust for computational efficiency.
[](LICENSE)
[](https://www.python.org/)
[](https://www.rust-lang.org/)
## Overview
EconoMetrust provides implementations of fundamental econometric estimators with comprehensive statistical inference capabilities. The library is designed for researchers, analysts, and practitioners who need reliable econometric tools with detailed diagnostic output.
## Estimators
- **OLS (Ordinary Least Squares)**: Standard linear regression with optional robust standard errors
- **WLS (Weighted Least Squares)**: Regression with known heteroskedastic error structure
- **GLS (Generalized Least Squares)**: Regression with known error covariance matrix
- **IV (Instrumental Variables)**: Consistent estimation for exactly identified endogenous models
- **TSLS (Two-Stage Least Squares)**: Consistent estimation for overidentified endogenous models
- **FE (Fixed Effects)**: Panel data regression with entity-specific fixed effects
## Installation
```bash
pip install econometrust
```
## Basic Usage
### Ordinary Least Squares
```python
import numpy as np
from econometrust import OLS
# Prepare data
X = np.random.randn(100, 3)
y = X @ [1.5, -2.0, 0.5] + np.random.randn(100) * 0.1
# Fit model
model = OLS(fit_intercept=True, robust=False)
model.fit(X, y)
# View results
print(model.summary())
print(f"R-squared: {model.r_squared:.4f}")
```
### Weighted Least Squares
```python
from econometrust import WLS
# Data with heteroskedastic errors
X = np.random.randn(100, 2)
weights = np.exp(X[:, 0]) # Known variance structure
y = X @ [1.0, -0.5] + np.random.randn(100) / np.sqrt(weights)
# Fit weighted model
model = WLS(fit_intercept=True)
model.fit(X, y, weights)
print(model.summary())
```
### Instrumental Variables
```python
from econometrust import IV
# Generate IV data
n = 200
Z = np.random.randn(n, 2) # Instruments
u = np.random.randn(n) # Unobserved confounder
# Endogenous regressors
X = Z @ [0.8, 0.6] + 0.5 * u + np.random.randn(n, 2) * 0.1
y = X @ [1.0, -0.5] + u + np.random.randn(n) * 0.1
# Fit IV model (exactly identified)
model = IV(fit_intercept=True)
model.fit(Z, X, y)
print(model.summary())
```
### Two-Stage Least Squares
```python
from econometrust import TSLS
# Overidentified case (more instruments than regressors)
n = 300
Z = np.random.randn(n, 4) # 4 instruments
u = np.random.randn(n)
# 2 endogenous regressors
X = Z @ [0.7, 0.5, 0.4, 0.3] + 0.6 * u + np.random.randn(n, 2) * 0.1
y = X @ [1.2, -0.8] + u + np.random.randn(n) * 0.1
# Fit TSLS model
model = TSLS(fit_intercept=True)
model.fit(Z, X, y)
print(model.summary())
```
### Fixed Effects
```python
from econometrust import FE
# Generate panel data: 100 entities, 8 time periods each
N, T = 100, 8
n_obs = N * T
# Entity identifiers
entity_id = np.repeat(np.arange(N), T)
# Generate data with entity fixed effects
np.random.seed(42)
alpha = np.random.randn(N) * 2.0 # Entity fixed effects
X = np.random.randn(n_obs, 3)
# Outcome with entity effects and time-varying component
y = np.repeat(alpha, T) + X @ [1.5, -2.0, 0.8] + np.random.randn(n_obs) * 0.1
# Fit Fixed Effects model with clustered standard errors
model = FE(robust=True)
model.fit(X, y, entity_id)
print(model.summary())
```
## API Reference
### Common Methods
All estimators share the following interface:
```python
# Initialization
model = Estimator(fit_intercept=True)
# Fitting
model.fit(...) # Parameters vary by estimator
# Prediction
predictions = model.predict(X)
# Results
print(model.summary())
model.coefficients # Coefficient estimates
model.intercept # Intercept term (if fitted)
model.residuals # Residuals
model.r_squared # R-squared
model.mse # Mean squared error
model.n_samples # Number of observations
model.n_features # Number of features
```
### Statistical Inference
```python
# Standard errors and significance tests
model.standard_errors() # Standard errors
model.t_statistics() # t-statistics
model.p_values() # p-values
model.confidence_intervals(alpha=0.05) # Confidence intervals
# Covariance matrix
model.covariance_matrix() # Parameter covariance matrix
```
### Estimator-Specific Parameters
#### OLS
```python
OLS(fit_intercept=True, robust=False)
# robust: Use heteroskedasticity-robust (HC0) standard errors
```
#### WLS
```python
WLS(fit_intercept=True)
model.fit(X, y, weights) # weights: positive sample weights
```
#### GLS
```python
GLS(fit_intercept=True)
model.fit(X, y, sigma) # sigma: error covariance matrix
```
#### IV
```python
IV(fit_intercept=True)
model.fit(instruments, regressors, targets)
# Requires: n_instruments == n_regressors (exactly identified)
```
#### TSLS
```python
TSLS(fit_intercept=True)
model.fit(instruments, regressors, targets)
# Requires: n_instruments >= n_regressors (identified)
```
#### FE
```python
FE(robust=False)
model.fit(X, y, entity_id)
# robust: Use clustered standard errors (cluster by entity)
# entity_id: Array of entity identifiers for panel structure
```
## Output Example
The `summary()` method provides comprehensive regression output:
```
====================================
OLS Regression Results
====================================
Dependent Variable: y No. Observations: 100
Model: OLS Degrees of Freedom: 96
Method: Least Squares R-squared: 0.830
Covariance Type: classical Adj. R-squared: 0.825
====================================
Coefficients
====================================
Variable Coef Std Err t-stat P>|t| [0.025 0.975]
--------------------------------------------------------------------
const 0.0234 0.0891 0.262 0.794 -0.1536 0.2004
x1 1.4987 0.0934 16.046 0.000 1.3131 1.6843
x2 -1.9876 0.0912 -21.786 0.000 -2.1688 -1.8064
x3 0.7899 0.0888 8.896 0.000 0.6135 0.9663
```
## Requirements
- Python 3.8+
- NumPy
- Rust toolchain (for building from source)
## License
This project is dual-licensed under MIT and Apache-2.0 licenses.
## Links
- [Repository](https://github.com/wdeligt/econometrust)
- [Issues](https://github.com/wdeligt/econometrust/issues)
Raw data
{
"_id": null,
"home_page": null,
"name": "econometrust",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "econometrics, regression, ols, gls, rust, python",
"author": "Wouter de Ligt <wouterdeligt3@gmail.com>",
"author_email": "Wouter de Ligt <wouterdeligt3@gmail.com>",
"download_url": null,
"platform": null,
"description": "# Econometrust\n\nA Python library for econometric regression analysis, implemented in Rust for computational efficiency.\n\n[](LICENSE)\n[](https://www.python.org/)\n[](https://www.rust-lang.org/)\n\n## Overview\n\nEconoMetrust provides implementations of fundamental econometric estimators with comprehensive statistical inference capabilities. The library is designed for researchers, analysts, and practitioners who need reliable econometric tools with detailed diagnostic output.\n\n## Estimators\n\n- **OLS (Ordinary Least Squares)**: Standard linear regression with optional robust standard errors\n- **WLS (Weighted Least Squares)**: Regression with known heteroskedastic error structure\n- **GLS (Generalized Least Squares)**: Regression with known error covariance matrix\n- **IV (Instrumental Variables)**: Consistent estimation for exactly identified endogenous models\n- **TSLS (Two-Stage Least Squares)**: Consistent estimation for overidentified endogenous models\n- **FE (Fixed Effects)**: Panel data regression with entity-specific fixed effects\n\n## Installation\n\n```bash\npip install econometrust\n```\n\n## Basic Usage\n\n### Ordinary Least Squares\n\n```python\nimport numpy as np\nfrom econometrust import OLS\n\n# Prepare data\nX = np.random.randn(100, 3)\ny = X @ [1.5, -2.0, 0.5] + np.random.randn(100) * 0.1\n\n# Fit model\nmodel = OLS(fit_intercept=True, robust=False)\nmodel.fit(X, y)\n\n# View results\nprint(model.summary())\nprint(f\"R-squared: {model.r_squared:.4f}\")\n```\n\n### Weighted Least Squares\n\n```python\nfrom econometrust import WLS\n\n# Data with heteroskedastic errors\nX = np.random.randn(100, 2)\nweights = np.exp(X[:, 0]) # Known variance structure\ny = X @ [1.0, -0.5] + np.random.randn(100) / np.sqrt(weights)\n\n# Fit weighted model\nmodel = WLS(fit_intercept=True)\nmodel.fit(X, y, weights)\nprint(model.summary())\n```\n\n### Instrumental Variables\n\n```python\nfrom econometrust import IV\n\n# Generate IV data\nn = 200\nZ = np.random.randn(n, 2) # Instruments\nu = np.random.randn(n) # Unobserved confounder\n\n# Endogenous regressors\nX = Z @ [0.8, 0.6] + 0.5 * u + np.random.randn(n, 2) * 0.1\ny = X @ [1.0, -0.5] + u + np.random.randn(n) * 0.1\n\n# Fit IV model (exactly identified)\nmodel = IV(fit_intercept=True)\nmodel.fit(Z, X, y)\nprint(model.summary())\n```\n\n### Two-Stage Least Squares\n\n```python\nfrom econometrust import TSLS\n\n# Overidentified case (more instruments than regressors)\nn = 300\nZ = np.random.randn(n, 4) # 4 instruments\nu = np.random.randn(n)\n\n# 2 endogenous regressors\nX = Z @ [0.7, 0.5, 0.4, 0.3] + 0.6 * u + np.random.randn(n, 2) * 0.1\ny = X @ [1.2, -0.8] + u + np.random.randn(n) * 0.1\n\n# Fit TSLS model\nmodel = TSLS(fit_intercept=True)\nmodel.fit(Z, X, y)\nprint(model.summary())\n```\n\n### Fixed Effects\n\n```python\nfrom econometrust import FE\n\n# Generate panel data: 100 entities, 8 time periods each\nN, T = 100, 8\nn_obs = N * T\n\n# Entity identifiers\nentity_id = np.repeat(np.arange(N), T)\n\n# Generate data with entity fixed effects\nnp.random.seed(42)\nalpha = np.random.randn(N) * 2.0 # Entity fixed effects\nX = np.random.randn(n_obs, 3)\n\n# Outcome with entity effects and time-varying component\ny = np.repeat(alpha, T) + X @ [1.5, -2.0, 0.8] + np.random.randn(n_obs) * 0.1\n\n# Fit Fixed Effects model with clustered standard errors\nmodel = FE(robust=True)\nmodel.fit(X, y, entity_id)\nprint(model.summary())\n```\n\n## API Reference\n\n### Common Methods\n\nAll estimators share the following interface:\n\n```python\n# Initialization\nmodel = Estimator(fit_intercept=True)\n\n# Fitting\nmodel.fit(...) # Parameters vary by estimator\n\n# Prediction\npredictions = model.predict(X)\n\n# Results\nprint(model.summary())\nmodel.coefficients # Coefficient estimates\nmodel.intercept # Intercept term (if fitted)\nmodel.residuals # Residuals\nmodel.r_squared # R-squared\nmodel.mse # Mean squared error\nmodel.n_samples # Number of observations\nmodel.n_features # Number of features\n```\n\n### Statistical Inference\n\n```python\n# Standard errors and significance tests\nmodel.standard_errors() # Standard errors\nmodel.t_statistics() # t-statistics\nmodel.p_values() # p-values\nmodel.confidence_intervals(alpha=0.05) # Confidence intervals\n\n# Covariance matrix\nmodel.covariance_matrix() # Parameter covariance matrix\n```\n\n### Estimator-Specific Parameters\n\n#### OLS\n```python\nOLS(fit_intercept=True, robust=False)\n# robust: Use heteroskedasticity-robust (HC0) standard errors\n```\n\n#### WLS\n```python\nWLS(fit_intercept=True)\nmodel.fit(X, y, weights) # weights: positive sample weights\n```\n\n#### GLS\n```python\nGLS(fit_intercept=True)\nmodel.fit(X, y, sigma) # sigma: error covariance matrix\n```\n\n#### IV\n```python\nIV(fit_intercept=True)\nmodel.fit(instruments, regressors, targets)\n# Requires: n_instruments == n_regressors (exactly identified)\n```\n\n#### TSLS\n```python\nTSLS(fit_intercept=True)\nmodel.fit(instruments, regressors, targets)\n# Requires: n_instruments >= n_regressors (identified)\n```\n\n#### FE\n```python\nFE(robust=False)\nmodel.fit(X, y, entity_id)\n# robust: Use clustered standard errors (cluster by entity)\n# entity_id: Array of entity identifiers for panel structure\n```\n\n## Output Example\n\nThe `summary()` method provides comprehensive regression output:\n\n```\n====================================\n OLS Regression Results\n====================================\n\nDependent Variable: y No. Observations: 100\nModel: OLS Degrees of Freedom: 96\nMethod: Least Squares R-squared: 0.830\nCovariance Type: classical Adj. R-squared: 0.825\n\n====================================\n Coefficients\n====================================\nVariable Coef Std Err t-stat P>|t| [0.025 0.975]\n--------------------------------------------------------------------\nconst 0.0234 0.0891 0.262 0.794 -0.1536 0.2004\nx1 1.4987 0.0934 16.046 0.000 1.3131 1.6843\nx2 -1.9876 0.0912 -21.786 0.000 -2.1688 -1.8064\nx3 0.7899 0.0888 8.896 0.000 0.6135 0.9663\n```\n\n## Requirements\n\n- Python 3.8+\n- NumPy\n- Rust toolchain (for building from source)\n\n## License\n\nThis project is dual-licensed under MIT and Apache-2.0 licenses.\n\n## Links\n\n- [Repository](https://github.com/wdeligt/econometrust)\n- [Issues](https://github.com/wdeligt/econometrust/issues)\n\n",
"bugtrack_url": null,
"license": "MIT OR Apache-2.0",
"summary": "High-performance econometrics library written in Rust with Python bindings.",
"version": "0.2.3",
"project_urls": {
"documentation": "https://wdeligt.github.io/econometrust/",
"homepage": "https://github.com/wdeligt/econometrust",
"repository": "https://github.com/wdeligt/econometrust"
},
"split_keywords": [
"econometrics",
" regression",
" ols",
" gls",
" rust",
" python"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "7d66f2969dbd803453615e6ef760e5bda6b860e70c8a4ad95db805b0b2d3eaab",
"md5": "0bcdb2d47efd136b0a2c3b37236b740d",
"sha256": "37863356e3f4d436f03fba656579ca4f36d7dba5cd8a639ff32aa2f88ad374e8"
},
"downloads": -1,
"filename": "econometrust-0.2.3-cp312-cp312-macosx_10_12_x86_64.whl",
"has_sig": false,
"md5_digest": "0bcdb2d47efd136b0a2c3b37236b740d",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.8",
"size": 461598,
"upload_time": "2025-07-22T12:33:27",
"upload_time_iso_8601": "2025-07-22T12:33:27.003671Z",
"url": "https://files.pythonhosted.org/packages/7d/66/f2969dbd803453615e6ef760e5bda6b860e70c8a4ad95db805b0b2d3eaab/econometrust-0.2.3-cp312-cp312-macosx_10_12_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "458efabc724b4b7fad3b3856fb251e0d645214543032d19b723b20eaa6eefaeb",
"md5": "29efeb343137740da35c96395413965f",
"sha256": "d52d522bc556d354ef26c72e20be90bb02a626b22a59b48807c6f9f78d58e551"
},
"downloads": -1,
"filename": "econometrust-0.2.3-cp312-cp312-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "29efeb343137740da35c96395413965f",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.8",
"size": 405683,
"upload_time": "2025-07-22T12:33:28",
"upload_time_iso_8601": "2025-07-22T12:33:28.677764Z",
"url": "https://files.pythonhosted.org/packages/45/8e/fabc724b4b7fad3b3856fb251e0d645214543032d19b723b20eaa6eefaeb/econometrust-0.2.3-cp312-cp312-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "084951f50144b5eda8baf8fa0c29c6609174cf7ceeed1585dd6e0914ca80254b",
"md5": "4e6455662ab04b98004175c8e57a78de",
"sha256": "c921dc95dc45c0b8699033c47424fc65459a476f9c7105ffafec95a0d8732dfe"
},
"downloads": -1,
"filename": "econometrust-0.2.3-cp312-cp312-manylinux_2_34_x86_64.whl",
"has_sig": false,
"md5_digest": "4e6455662ab04b98004175c8e57a78de",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": ">=3.8",
"size": 12479928,
"upload_time": "2025-07-22T12:33:24",
"upload_time_iso_8601": "2025-07-22T12:33:24.429503Z",
"url": "https://files.pythonhosted.org/packages/08/49/51f50144b5eda8baf8fa0c29c6609174cf7ceeed1585dd6e0914ca80254b/econometrust-0.2.3-cp312-cp312-manylinux_2_34_x86_64.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-22 12:33:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "wdeligt",
"github_project": "econometrust",
"github_not_found": true,
"lcname": "econometrust"
}