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, AugmentedBalancing, MatrixCompletion, InteractiveFixedEffects
  • Common panel causal API: HorizontalPanelRidge, SyntheticDID, AugmentedBalancing, and MatrixCompletion use 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
  • 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.

AugmentedBalancing.fit(Y, W, outcome_model=None) composes supplied untreated-outcome predictions with unit or unit-and-time residual balancing. Constructor options select cohort versus individual unit-weight targets and raw versus residualized weight fitting.

The Augmented Balancing vignette shows a staggered-adoption workflow with a matrix-completion nuisance surface, estimator comparisons, event-time plots, and weight-target diagnostics. The class reference documents every constructor option and summary() field.

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.2.tar.gz (506.5 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.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

crabbymetrics-0.8.2-cp314-cp314-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

crabbymetrics-0.8.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

crabbymetrics-0.8.2-cp313-cp313-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

crabbymetrics-0.8.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

crabbymetrics-0.8.2-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

crabbymetrics-0.8.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

crabbymetrics-0.8.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

crabbymetrics-0.8.2-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.2.tar.gz.

File metadata

  • Download URL: crabbymetrics-0.8.2.tar.gz
  • Upload date:
  • Size: 506.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for crabbymetrics-0.8.2.tar.gz
Algorithm Hash digest
SHA256 02d4d88f936a63181575d7f9b9b4f46cd173d68f29666c346ef075a942125abe
MD5 fefc62b9355856bc4cbd218a15161319
BLAKE2b-256 089b4ff4f6cc0ce5059eca927d42544b4e8031183fd0e3d0ed64502a4237419b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5400f4a8b9c81d6b80ac18ee989dfd2c1480ddc709e35d898b2f725dc33eea00
MD5 e2ace2b9efcfb9c2d4d62ae9b05714db
BLAKE2b-256 925124393c954f07a6fa219f674fa15989523d6e9726fa42cb6e07a717ef4776

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dc29d1babde947769bf9f594c8aa941ee3d41424064c9eb571ff145750f57324
MD5 eff8c632adc9ba0c0981f8050e4e8147
BLAKE2b-256 7b486377460fb1ca2b64e6b03519fcbf44bc1853493e677d427291ea0297a168

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 883c1e21ae83e1a29b8a2a33a5ec0105d28b41f802bf33d23cb8f6ad0e53b002
MD5 4ee6d0014e655f729e6267c089fe24f0
BLAKE2b-256 c27c18ba1a166c7a1b7c6abfcf6efadc7dca98e54d9ff2382743a1c9aea90913

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd42ec230cdc51fad22a35a37f66fd17a4fd3ad02f8933709ad89c622ea070ac
MD5 1dfbb5c3232d79d1f3816273e3d89709
BLAKE2b-256 0fd211e47ce8d1863f1f612bf2f89c20da60e8b37fa4795baf1f06c93574f340

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 69d9ca114e2048e162bbebc238f13ec445651f42d16b972c6bf0f1e26ffcdcee
MD5 ba8f0fc0cf6e1e5310c4943133ce7509
BLAKE2b-256 3c63824c8b8bb3e8fc27def22396279d9123da7fa09dea92ca98e476749b9f28

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f3e1ed971d75a64b25c924e254f2f6d5d055825e381d1ac10afa55c28c3f7a8a
MD5 8bad81599de3c319b1ab34f373301d7f
BLAKE2b-256 98be31760188f9a6be18d7167767972942987e0bedead20b8c3b4be070263933

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a773d3dbbe4b86310d8dcf127aac560ef9d13f80065662e0e70e072c11ebb50
MD5 fcf785666ea4b6e7c440ce2fe5f68d37
BLAKE2b-256 c2a1dc3fc0e92c0cb6652f2be788db50eab4afb783c64e65b430860cf2c15a3d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ba01befd85660f136297977949be738a7c5a6c0962038552513167c14f12c48a
MD5 7c87b777b7145efb759c6626e767c6d4
BLAKE2b-256 5f6a636750b41bd299d0e3463e2057bbcc68704ec431589420f16ad71b569a5b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f0d386294c0178b7ca1752c8eab6dad732064eda9911f3ce28c2ea022e19e64
MD5 53c0d39c512acb5507486e657cee8849
BLAKE2b-256 6b8e1aed8523953fae0c7f1b3a9c968aa363b6cea2c5e705393d373e213b67a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for crabbymetrics-0.8.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca2f982ba56930b53959b480ae40ed4a44b0d6b603ea00c996f7be43dcaadfd2
MD5 d1ecd78d34375886ce8ba896985083f3
BLAKE2b-256 f43dbfcef4c6bda9946add328640a91b40fccdeb154debd751db2b13629dec49

See more details on using hashes here.

Provenance

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

This release

0.8.2 This release

11 files

0.8.1

11 files

0.8.0

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