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 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.

crabbymetrics-0.6.6-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.6-cp314-cp314-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

crabbymetrics-0.6.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.6-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

crabbymetrics-0.6.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.6-cp312-cp312-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

crabbymetrics-0.6.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.6-cp311-cp311-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

crabbymetrics-0.6.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

crabbymetrics-0.6.6-cp310-cp310-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d948e0f16e57e4607c3f2979b84f32721e67d636ea1802b6fd7cf57d32873e16
MD5 9be1235fb4bf96ee63408becd16b289a
BLAKE2b-256 64d4a8e4459fc8088d23a1dd6a8ecba98ad368f0327090f908aea8a51fc0352d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e8d1b78c4548de37d7b3f4a44aeafb141d42a9a7fafd5bf1950e5f98fafa145
MD5 95ccb401626a6a0b1a193656f523896f
BLAKE2b-256 abce7f2cf305d14f0fbddb12b4e5051a47bf7e50ee414f8b3014c632207ed845

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0df8e544e11eccae21c64c1827368604ce1b756f1f347c4de6896b3592f7e3bf
MD5 d24b64634dd1e9ba5b2c2674a7010623
BLAKE2b-256 ac806ba9f07385e53d0ad3050d063b4cf3f72599c45f2d7feab228681337def2

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3cca378e12cd0cdb6fe9453498ac9b92fcd88d6f1cadde88e296a22a9c46e28f
MD5 093c81b4e6aa2e6eeb7a457c828f18fb
BLAKE2b-256 4b706e947a167051fd3b9df037f6c751824875721b7f7f3e5622b346cb4cd6cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8214dd33e95f23bc09b4644dae52b3f080810ba2f97cc4ac75fb49fba1d868bb
MD5 8461932dc4676c45875e1c2971713554
BLAKE2b-256 645cd00d57ec2b2b7c3529862b6f1836f8205e476091fc41cb0bfcc6bfb2d9d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4eb080ae612d4274631130a3be98a4ce7a90f71277a32ead3950ee461da37f1
MD5 660b561517d2c8ea8ab21f70b82cc812
BLAKE2b-256 d105dbd6cbe2ae6ef0253567bb41d0cbf05b09d66ca80c6b90c92f2595da946c

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1bcdc2731b200ebadf3d48da1f8366be79cc8743651eb57386ec90b5b9e9d956
MD5 bb9b989ab4d065b0c3d47fb550c33426
BLAKE2b-256 f37f0c5d83bc4043eec460337386596a32a83e428e591b12eacab0fb32190430

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e86bfd1a7845c626745ffc323500a7349f699f04f9ac55cb97334d32592fad8
MD5 2d1ccdc71621c2f8527509074ec82031
BLAKE2b-256 1e1209356091be82f58035658ced3816a079814a3bcc327c00fa9142b9306806

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 43e2e13f118a4626c9924570c9917cdf160beb8863e90e2514e3a3edab430a32
MD5 b97bc62270edf8c0217d9689df6625dc
BLAKE2b-256 78cefd206cc97a78737839afbf3b20e20c088d92a136245e7a338d4eb5d04fdb

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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.6-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.6.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2eed6773c6e90614d6befabbe0a7bebc5b22d0ca19ed73f387e820ad89961432
MD5 7a3227666630afabd76f1e03c2a58807
BLAKE2b-256 43f4e04042cd1beb7e3b55bf7c45d784d22f54d604b4d4e132a9e1506207e5fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.6.6-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