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
  • Ridge (Ridge Regression): L2 regularized linear regression for multicollinearity and overfitting
  • 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())

Ridge Regression

from econometrust import Ridge

# Generate data with multicollinearity
np.random.seed(42)
X = np.random.randn(100, 5)
X[:, 4] = X[:, 0] + 0.1 * np.random.randn(100)  # Correlated feature
beta_true = [1.5, -2.0, 0.5, 1.0, 0.0]
y = X @ beta_true + 0.1 * np.random.randn(100)

# Fit Ridge regression with L2 regularization
model = Ridge(alpha=1.0, fit_intercept=True)
model.fit(X, y)
print(model.summary())
print(f"Regularization strength: {model.alpha}")

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

Ridge

Ridge(alpha=1.0, fit_intercept=True)
# alpha: regularization strength (higher = more regularization)
# Handles multicollinearity and overfitting through L2 penalty

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

Ridge regression provides similar output with regularized coefficients:

====================================
        Ridge Regression Results
====================================

Dependent Variable: y              No. Observations: 100
Model: Ridge Regression            Alpha (λ): 1.000
Method: Ridge Regression           R-squared: 0.825
Covariance Type: nonrobust         Adj. R-squared: 0.820

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.10-cp312-cp312-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.12Windows x86-64

econometrust-0.2.10-cp312-cp312-manylinux_2_34_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

econometrust-0.2.10-cp312-cp312-macosx_11_0_arm64.whl (419.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

econometrust-0.2.10-cp312-cp312-macosx_10_12_x86_64.whl (482.5 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

econometrust-0.2.10-cp311-cp311-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.11Windows x86-64

econometrust-0.2.10-cp311-cp311-manylinux_2_34_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

econometrust-0.2.10-cp311-cp311-macosx_11_0_arm64.whl (420.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

econometrust-0.2.10-cp311-cp311-macosx_10_12_x86_64.whl (483.1 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

econometrust-0.2.10-cp310-cp310-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.10Windows x86-64

econometrust-0.2.10-cp310-cp310-manylinux_2_34_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

econometrust-0.2.10-cp310-cp310-macosx_11_0_arm64.whl (420.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

econometrust-0.2.10-cp310-cp310-macosx_10_12_x86_64.whl (483.2 kB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

econometrust-0.2.10-cp39-cp39-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.9Windows x86-64

econometrust-0.2.10-cp39-cp39-manylinux_2_34_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

econometrust-0.2.10-cp39-cp39-macosx_11_0_arm64.whl (420.9 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

econometrust-0.2.10-cp39-cp39-macosx_10_12_x86_64.whl (483.5 kB view details)

Uploaded CPython 3.9macOS 10.12+ x86-64

File details

Details for the file econometrust-0.2.10-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5b25f4c47e33c53905625140f64f4825db114f32eb6272f72756257bf7e0dcaf
MD5 821ecbe93741a0e88e73e44825837d33
BLAKE2b-256 bae01788787277230260bf15bfa596dba537f1a0033b9c5f317257a524e958df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for econometrust-0.2.10-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d9b3cfd71adf5cc9bcc382efa65fcde40d21890e976d659cd394956e5df9d55f
MD5 1d6049b8a7901483b8a6b4804822c967
BLAKE2b-256 e935c970c0ee1548c5290b2d96316313d2183d4b0239b27a5750c5bc62bb44ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for econometrust-0.2.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3215e6c991d40fd2b44bb3d100adbc508e7a42d7494d1338a62b06c28bc33003
MD5 80d25be37d6e889c2376a2b3bb48f2dd
BLAKE2b-256 dfe36bdee20a708b4b7f421f2cad8ec6ad4868b77af99fe1cfce82745666bc54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for econometrust-0.2.10-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 25d09fb73015e526896111fe6f2c411dbc8cd2dfc7a477861ef216c9eadba042
MD5 b7a8765f51b0eb02bc7940483dd9ee17
BLAKE2b-256 261795ff79e4ff8660ea3b4baf82407ddd769600f2d6c9c356d1c976097e8364

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e60209b60ce1a275d11ef71bf0a5a492840eb14218fa9bb94c74ec4c93482cb0
MD5 a7929d2bb83542b950b1ba0014fc15f2
BLAKE2b-256 a4b20ae0598caad2c21c4043020d69a8c653bc60e14f82d413f1824e42c2796d

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5f720572c0b7b2ffcdbb7f40fa2738bf7e42bd279a3c54e51a85e369b41730e4
MD5 1f06ffbfc0de6e07b0a3991dabf697f8
BLAKE2b-256 e5f8b488e307a4f200fd1bac7ceb7f8d06975d8054c32ae2e0bfce76d96c0ba9

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a3af4e951d87c73265dc849d4198ec3d476763b79d25db3a3769f3dae7f5892
MD5 ffbcf7edd41d050c5ea9bf355d0284c8
BLAKE2b-256 d5bfbd86fb910e27149c5bcf8e70880ad29c84e777da762878fcb6789bfac976

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 23e956bddbfd681d002eeab47ee3207fe6b7a8fe19904078185b3e4db690a0c0
MD5 7270a9f195ef894209b4a0e0c7825390
BLAKE2b-256 872243a8056ac9bdc89e3952362242f976256f7d85165078aed1e92c1e0f59b5

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 226491bd768a5bc1e2505257debbd809f39be700c57ad0a7073a67c0dbd225e1
MD5 dc0de1f251226da38ac1562553910106
BLAKE2b-256 4eba50c58ad351742eb19c4f67d3e607eea1fafcc799447526ee0a719e2dafda

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 eab4046787aa0754ffe2d22ea58a32b1494dd21a2151d09dbe2396f4a6f92a11
MD5 95bb7c5bb46eed9f4c0fbc9e41ccd39c
BLAKE2b-256 fcd8868ad940c056cf2f9a6a6c015452f1a71cee46bbacb448532ab7c11baca9

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c745a104dc97d8562db957092524269da82f67600a17a8189e9141bf999e2fa
MD5 a5a0d183fd6ab714dffb4daf5a2ad45b
BLAKE2b-256 6be1f1b4754b92472b5f479d6225817c844e544809320e54d751f5f6e615906f

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e4996376cef6252d829e2d86ea3700054c75f1d91a0fc1b7fbd0a1c7abad1061
MD5 2e380558eeac56d18789ca0a58a5a7f5
BLAKE2b-256 c64d7a41da4a5ecf0e4a59b966dc03b36362de38f36fceac534d39f70dd389f6

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5538af655deb9eed18f6a557081ec17a766b57b86855eed3dca90fcb206a545e
MD5 b10e42a4d902e9513c7d8d6542a05a24
BLAKE2b-256 aa28420307643a6aea89bc7f477c085391b7a19ff9c24769fe7c831738af4758

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a0bae9ad5f013af92562c45c809544313fd50d6300c420ecb6e4e5ce8f07128d
MD5 a1da8c35dca39537666669fee6c251a9
BLAKE2b-256 12d1cc1cf8f68beb3e0eb8a47e9db6709f935d984b151a5964f69af5195362f8

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 844cadb5052d02f7c437336d4378e188f6f33dcc02f26f658148e20acb9d6765
MD5 dc18adafe3900de9b3b8edf01c6a1659
BLAKE2b-256 c2403965333ea1d9144020ab4df6ae2e9886eaba8f4bca02a94d8acdc526f549

See more details on using hashes here.

File details

Details for the file econometrust-0.2.10-cp39-cp39-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for econometrust-0.2.10-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cda051b7b18d55923fe44fad30e5ecf0d5c4794c37c01d04409953c3555860b0
MD5 f6409abc1d8af075d0519af1ad0fc147
BLAKE2b-256 d9f7f72bbcacd714614f68bda8c87d255d2a836544ace9d0fd460fdd3ff48f2c

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