Skip to main content

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())

Anytime-valid OLS inference is available from OLS.summary(...):

import numpy as np
import crabbymetrics as cm

rng = np.random.default_rng(1)
n = 100
x = rng.normal(size=(n, 3))
x = x - x.mean(axis=0)
trt = rng.choice([0.0, 1.0], size=n)
y = (
    1.0
    + 1.4 * x[:, 2]
    + 2.3 * trt
    + 2.0 * x[:, 0] * trt
    + 3.0 * x[:, 1] * trt
    + rng.normal(size=n)
)
design = np.column_stack([x, trt, x * trt[:, None]])

model = cm.OLS()
model.fit(design, y)
g_star = cm.optimal_g(n, design.shape[1] + 1, alpha=0.05)
summary = model.summary(vcov="vanilla", anytime_valid=True, g=g_star)
print(summary["p_value"])
print(summary["confint"])

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.

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.8.0.tar.gz (410.4 kB view details)

Uploaded Source

Built Distributions

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

crabbymetrics-0.8.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

crabbymetrics-0.8.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

crabbymetrics-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

crabbymetrics-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

crabbymetrics-0.8.0-cp311-cp311-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

crabbymetrics-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

crabbymetrics-0.8.0-cp310-cp310-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for crabbymetrics-0.8.0.tar.gz
Algorithm Hash digest
SHA256 fe201df637c3e5c6f32c21747f9be9fcee80c21b3b2efb0e89a0c20052676a29
MD5 4f5423737878f4546cf570c9582b4e9e
BLAKE2b-256 50b6de545f2992a5c5e878d508b2b0db3968bb18b1d0177f4c198e6a95bd665a

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.8.0.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.8.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f2561a856ee14bc060f5eceb25352291efa5f20390f75817908d1b0bdd79b51d
MD5 6a877dfe56eec013fee2f561d091735c
BLAKE2b-256 6d41f79a04e98de048a77dd6640a863a491d145e8eb3ec1e62af6f5367d064af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72d5d19a17e0274d92d3c0070d771dda32e04ffc66086ecf03afec0f2649a783
MD5 0944c8638d83a5ec45ef28fe9eecd7d6
BLAKE2b-256 a2278dd895d1d4266e467488cb37615783ebc6c7f61695b526eb38ad9cac38e3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b602bece09b8f5dc7f8434940d8593470ba004301fa7a0c590d25b0f79b0e3f4
MD5 79a31c16357ccfaafb8d80c1daa3e5a3
BLAKE2b-256 5d812128c15de7cbb19fd7866729665bfbde1ef70dbdca400a9e704b65574490

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 46ef299dfb671b88b3ca28d4e967b6f17763de14090d0ad5ce3551c21420a796
MD5 610c1115adc19146aecd15a9c673e83c
BLAKE2b-256 c19ae4a9856a9673f5dba12cf67b6018d73f9070a01f88a8faaecf146b8f0c97

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4fc72263bb8740ce44ecbb5d1b327450cc3559b2b1d4090140da2ef12f0263ac
MD5 ce94d5dd5abe4d274926d17a281a213e
BLAKE2b-256 4b61e7a20cb7faa79d3e9f037ab0098b4d2462f2defc9d0d7101cfe4009fbe49

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a85f59f9fb86ab9ce438ff3a15e08e46766d3c57ea85434224fc4a1aba39dad
MD5 bf9a5c2d0601ad16d96090ffc07cff2b
BLAKE2b-256 6dfe7daeab2b704916426beb52b680697063028186c0b0830904a91c0e8604b6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 042bfe6ae4301f0502353333cd6bdcebc2631015464728182ec1145671c43dae
MD5 ea36ef509eda20410f84a72f1457bcd3
BLAKE2b-256 194bba96ce6f7ae309f37369e0ae03eac0dee3aff8830b0ff7d33b98f2f048b6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ff99951c0cc209c15f837a61a8f8d2e0eb50c43938a472e301b980124a463496
MD5 0254129d0d717bf0a9bf810116531349
BLAKE2b-256 88f89c394d719895d3de823e4acde70eaf8ee96a267d899be34540951c899bfb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3a79aafcb3deab3a0256b21af214d7c51b1b9b593a79d874b9c5ba83b27df3ea
MD5 f35c9d76237d199e0b09cd578c160326
BLAKE2b-256 b3dc0ec49fb66240bc1e0c5bd9ecb79173fb6939dfc6fde795766530ebe3dc87

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0c89bc74db2a19c5dd262ba4cf3daad50712dc9273fabd9426009646fae49b54
MD5 2363de509e7c2618cb817818f4c67401
BLAKE2b-256 0a708e9ab50d9d00c9a27a016b3157798c5123a145837dd2845457f9746da2ac

See more details on using hashes here.

Provenance

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

Release history Release notifications | RSS feed

0.8.2

11 files

0.8.1

11 files

This release

0.8.0 This release

11 files

0.7.1

11 files

0.7.0

11 files

0.6.7

11 files

0.6.6

10 files

0.6.5

11 files

0.6.4

11 files

0.6.3

11 files

0.6.2

11 files

0.6.1

11 files

0.6.0

11 files

0.5.1

11 files

0.5.0

11 files

0.4.1

11 files

0.4.0

11 files

0.3.6

11 files

0.3.5

11 files

0.3.1

11 files

0.3.0

11 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page