Skip to main content

Rust-backed econometrics models with a scikit-adjacent Python API.

Project description

crabbymetrics

Tests Build wheels PyPI version

crabbymetrics logo

Rust-backed econometrics 🦀🔢 models with a scikit-adjacent Python API. Focus: extremely low runtime dependency footprint, simple NumPy-facing estimators, robust standard errors, and bootstrap support where it fits the estimator.

Features

  • Linear, IV, and panel causal estimators: OLS, Ridge, FixedEffectsOLS, TwoSLS, HorizontalPanelRidge, SyntheticControl, SyntheticDID, MatrixCompletion, InteractiveFixedEffects
  • Common panel causal API: HorizontalPanelRidge, SyntheticDID, and MatrixCompletion use fit(Y, W) with balanced outcome and absorbing treatment matrices, then expose ATT, counterfactuals, treatment effects, event-study summaries, and group means through summary()
  • Regularized and likelihood estimators: ElasticNet, Logit, Multinomial Logit, Poisson, FTRL
  • Moment and semiparametric estimators: GMM, BalancingWeights, EPLM, AverageDerivative, PartiallyLinearDML, AIPW
  • Shared robust covariance options for the main linear estimators: vanilla, HC1, Newey-West, and cluster
  • Weighted fits for OLS, Ridge, FixedEffectsOLS, and TwoSLS
  • ElasticNet spans the ridge and lasso corners: use l1_ratio=0.0 for ridge-style shrinkage and l1_ratio=1.0 for lasso-style shrinkage
  • PCA and KernelBasis for feature engineering before regression-style estimation
  • Optimizers namespace exposing LBFGS, BFGS, NonlinearConjugateGradient, Gauss-Newton least squares, and SimulatedAnnealing
  • fit, predict, summary, and bootstrap where meaningful for the estimator

Install

This package is built with pyo3/maturin and ships as native wheels.

PyPI: https://pypi.org/project/crabbymetrics/

uv pip install crabbymetrics

Example

import numpy as np
from crabbymetrics import OLS

x = np.random.randn(200, 3)
beta = np.array([1.0, -2.0, 0.5])
y = 0.3 + x @ beta + np.random.randn(200) * 0.1

model = OLS()
model.fit(x, y)
print(model.summary())

Panel causal estimators take matrices directly rather than long data frames:

import numpy as np
import crabbymetrics as cm

Y = np.random.randn(20, 12)
W = np.zeros_like(Y)
W[15:, 8:] = 1.0  # absorbing treatment matrix

model = cm.SyntheticDID()
model.fit(Y, W)
out = model.summary()
print(out["att"], out["event_study"].keys(), out["group_means"].keys())

BalancingWeights remains available as the lower-level calibration/reweighting API, but the paved panel path is estimator-first.

The direct optimizer wrappers live under Optimizers and follow a lightweight scipy-style interface:

import numpy as np
from crabbymetrics import Optimizers

def objective(theta):
    return float((theta[0] - 1.0) ** 2 + 2.0 * (theta[1] + 2.0) ** 2)

def gradient(theta):
    return np.array([2.0 * (theta[0] - 1.0), 4.0 * (theta[1] + 2.0)])

result = Optimizers.minimize_lbfgs(objective, np.array([4.0, 3.0]), gradient)
print(result["x"], result["fun"])

Benchmarks

The latest cross-library runtime snapshot is checked in as benchmarks/runtime_comparison.png.

Runtime comparison across crabbymetrics, scikit-learn, and statsmodels

This benchmark used synthetic problems with p=5, sample sizes from 10^3 to 10^6, fit-only timing, and a 45-second per-fit timeout.

  • OLS is competitive already and was faster than both scikit-learn and statsmodels at n=10^6.
  • Poisson beats statsmodels comfortably but still trails scikit-learn at larger n.
  • Logit and especially MultinomialLogit are the main performance gaps to close before adding more iterative GLM-style estimators.

Development

Create and populate the project virtual environment, then build the extension into that venv.

uv sync
uv run maturin develop

uv run maturin develop is sufficient for rebuilding and reinstalling the package in .venv once the environment exists. If you change Python dependencies or the pyproject.toml metadata, run uv sync again first.

Package versioning is sourced from Cargo.toml; the Python package metadata is dynamic.

To release to PyPI, use the Build wheels GitHub Actions workflow manually from master and enter the next version without the leading v (for example 0.6.1). The workflow bumps Cargo.toml, commits to master, creates the vX.Y.Z tag, runs tests, builds wheels and an sdist, publishes the GitHub Release, and publishes to PyPI. The older commit_tag_release.sh script remains as a local fallback for manually tagging the current Cargo.toml version.

Rendered examples and API docs live under docs/. Rebuild the site with uv run quarto render docs. For docs work, install the docs extra first: uv sync --extra docs.

Wheels

Wheels are platform-specific and included in GitHub releases. See the releases tab.

Project details


Download files

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

Source Distribution

crabbymetrics-0.6.4.tar.gz (100.0 MB view details)

Uploaded Source

Built Distributions

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

crabbymetrics-0.6.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.4-cp314-cp314-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

crabbymetrics-0.6.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.4-cp313-cp313-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

crabbymetrics-0.6.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.4-cp312-cp312-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

crabbymetrics-0.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.4-cp311-cp311-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

crabbymetrics-0.6.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.4-cp310-cp310-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file crabbymetrics-0.6.4.tar.gz.

File metadata

  • Download URL: crabbymetrics-0.6.4.tar.gz
  • Upload date:
  • Size: 100.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for crabbymetrics-0.6.4.tar.gz
Algorithm Hash digest
SHA256 fbcf25ea27ae82f6cce4c0fa4e5fd43c891a565297d68c68674597e83734ceec
MD5 8865408df0948b44a3e47a4899f81686
BLAKE2b-256 b9dcb983b167207964cf8307cd2563e05019e90aa34bad5d2d09231b723798b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4.tar.gz:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 edf859d397678d68562baea42dc00445f63d9a77d2392ccbd1eab37e0b81c206
MD5 34f58123e4a6127d09a37320ae4be15d
BLAKE2b-256 aa888ceb6d24a1bf909e58138afc0b3faa6b7e283dec5f506297a91585c90805

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c5ecd9401efc21626e22d6653b9abcbf67796a90a6224c12aaacc63f039cb1f3
MD5 8552ed9dca682ca21124eb83f6d1aae9
BLAKE2b-256 ba0a34e9261e7856203fed4aa13bd2d5f18392363b8c1cc9b90f9322d2d5fd4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b94fac43c8a70e11f897d6067486adda3df1826d20aabb6cfd588c228753c33f
MD5 5cbece33eff90abe854d46c49027c38b
BLAKE2b-256 b1603c13ab5cacf93b83c1f31de07f9466ad0cafdc538d685e348c3b0757f6b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aaf8fe587126b175efb4287fb42511c68fce4b2ec5269cee8b4f9761f6003fd1
MD5 458728be58880b1fb06df3493000f81d
BLAKE2b-256 1524ff81cc29be2583a42480aa648e810a85d043004c3385f93585d83cf00106

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a417abd1b843cf707ab2b77b1c029a773d2538d16a4c8c193f27533368dc5fc7
MD5 3c240b50d6b4854a27e60501473be2db
BLAKE2b-256 b6b4208a0cb7ed6b9c5b6e2921f47391f5e5b7aab3083284b802ee9b3130ae2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2fe5ff28e5f2de639a10649e2e366243e60d257e53672a87a1c9405cb74fd0af
MD5 4a69e4f59ad000654c4b41bdcf963924
BLAKE2b-256 6c588621cd303157d8498839029b79da5b5735aa1a4b5e9e5b981b6789e74459

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5fc8538d53727fa65dcc7660c9350580f4f8d43cccfa2da81a690513481abc4
MD5 a617ba313d74e23a7497bcbfd4677578
BLAKE2b-256 88fe7e4de6ec7af4a021dfc26f97a057cd7e6590793d8e1f55edee41f34b9724

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 714af46e5b570a42c0329625093db1604fefb88c2765f44c35e5cfb7a5042cb6
MD5 2e53332ec674ffa3e2bdb0be677ac4f0
BLAKE2b-256 be2ad885fd688301dace42cd460846698d64872d5b16353f53eb69729e696cbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c5840d6f37150b4d009183fb2889535ee8fce52f72d7ff536de57a61360b276
MD5 a58c45e3651b4717846426459ed1e619
BLAKE2b-256 76b8ddcc74978c65231ab8f28a5d32e19c2a0f796f7420355c748e1fc8591a3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.6.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5398f181009a6c5cac010a295359ddc33d17563074fd82e41a8f736d2da21f5e
MD5 1187381f688e84659e52dbb2f0917eab
BLAKE2b-256 e073732d43055383e950cb59511bdeb1d6f22346b9b635785ec75501c5f8f10d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.4-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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