Skip to main content

High-performance econometrics library written in Rust with Python bindings.

Project description

Econometrust

A Python library for econometric regression analysis, implemented in Rust for computational efficiency.

License Python Rust

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

pip install econometrust

Basic Usage

Ordinary Least Squares

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

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

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

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

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:

# 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

# 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

OLS(fit_intercept=True, robust=False)
# robust: Use heteroskedasticity-robust (HC0) standard errors

WLS

WLS(fit_intercept=True)
model.fit(X, y, weights)    # weights: positive sample weights

GLS

GLS(fit_intercept=True)
model.fit(X, y, sigma)      # sigma: error covariance matrix

IV

IV(fit_intercept=True)
model.fit(instruments, regressors, targets)
# Requires: n_instruments == n_regressors (exactly identified)

TSLS

TSLS(fit_intercept=True)
model.fit(instruments, regressors, targets)
# Requires: n_instruments >= n_regressors (identified)

FE

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

econometrust-0.2.4-cp312-cp312-manylinux_2_34_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

econometrust-0.2.4-cp312-cp312-macosx_11_0_arm64.whl (406.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

econometrust-0.2.4-cp312-cp312-macosx_10_12_x86_64.whl (462.6 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file econometrust-0.2.4-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f5d4a7d475b5d770f21ef6fc6b2dee6188cc94cdc76ab690eb15fd553e70ad77
MD5 58df9cc5f83150fdeddff6df4695956f
BLAKE2b-256 edfe4f6a06abf12b678a5a85491706334c0420baf7d24d5b3ba149b5cd40038c

See more details on using hashes here.

File details

Details for the file econometrust-0.2.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b7ddda7426b0ca3b0456175777175ee63e145973db897a2a3033f56c6db149b
MD5 96b36cff271003d2cbc04a559623d811
BLAKE2b-256 c12b4d1046468c63d52418412ea1b3730231fb06386dd8824ac07d905b748eaf

See more details on using hashes here.

File details

Details for the file econometrust-0.2.4-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b8f491aed57366bc8221a732aec9e0dbc0e68aad2a26d7252dec4f7405e0c6a3
MD5 42a6a008b281df07ad3f7b6ccdd4ad4e
BLAKE2b-256 b48d27cfd7b95515866e3b623db7905a7961ace2ada2a52bcf662b5b79860936

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page