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, FEImputation
  • 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()
  • FEImputation fits untreated-only unit/time effects with missing cells, reversals, covariates and weights; point estimates only. See the worked example.
  • 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.

Metadata

Release files for crabbymetrics 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crabbymetrics 0.9.1
File Size Uploaded
crabbymetrics-0.9.1.tar.gz 730.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for crabbymetrics 0.9.1
File
crabbymetrics-0.9.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
crabbymetrics-0.9.1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
crabbymetrics-0.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
crabbymetrics-0.9.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
crabbymetrics-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
crabbymetrics-0.9.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
crabbymetrics-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
crabbymetrics-0.9.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
crabbymetrics-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
crabbymetrics-0.9.1-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details

Total release size: 23.2 MB

Release files / crabbymetrics-0.9.1.tar.gz

Download URL crabbymetrics-0.9.1.tar.gz
Size 730.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0475984213e7f5f8f9fc4b56f01ac647ad21575e53aa0b0e22b7cdd7387aae1b
BLAKE2b-256 checksum
How to use checksums
8762212ce1c2335c4d40548018765460ac0f2bfb8e570c0e5adf3d13542177fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL crabbymetrics-0.9.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.6 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b9e3a8e6fa9839ec2c4d10243577cca98f46a08891454e11c0e6f8422b48c686
BLAKE2b-256 checksum
How to use checksums
84e925303438858acecc2c6348814dce5ea03b3280d66bb8030547f13ca4ea4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp314-cp314-macosx_11_0_arm64.whl

Download URL crabbymetrics-0.9.1-cp314-cp314-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
802a51b7b3ebe5582e4686205d405ac7f0c1e41bf82e227788cce71060d124b1
BLAKE2b-256 checksum
How to use checksums
3d10ed5df695dc8a43e302c2606a1ce4a3b5618351c1560f7cb325af4f753c9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL crabbymetrics-0.9.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.6 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b6b9d21f7f5e22ad2138158fbb0b8c125a7e99bb2eae1c6091e66e418c9f803c
BLAKE2b-256 checksum
How to use checksums
a1cfa222bd1991f814d1a792f22a3e13ba88634c59e089e6fc430090d1c5f455
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL crabbymetrics-0.9.1-cp313-cp313-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ea6f96eb4041d9bef5443b62c28ddd14eef6b15dc9187d1835b935ce35700bbe
BLAKE2b-256 checksum
How to use checksums
3735abe69b75ac20b99e24a5917f35d3501130158982d999b2aa61baee151d7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL crabbymetrics-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.6 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
e3e8156db04bb800fd5df995d179e4f1fef7006916d2b2b0e394a297f45da10c
BLAKE2b-256 checksum
How to use checksums
9618f78554d15d935c3baf57feab4c9442444eaaf58ab0b0e2220cda8c4b6b88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL crabbymetrics-0.9.1-cp312-cp312-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b4659128c4f434f3c71cd0383ab71c6d0e325eb834f34caf5fffe116d5ecdaf6
BLAKE2b-256 checksum
How to use checksums
826afc26a8fed358ac3c8a832b0429ce810b7d9c8538bdf65b59f791b896e9cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL crabbymetrics-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.6 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
46f54b643b32c2b5168245db9d9f0c64314a5d655ceaec931cda2f4fdfea7f82
BLAKE2b-256 checksum
How to use checksums
d3a2305eff30bc7d272451ac30af39ef2aee010eb0a2f1aa0f14c6348b72fce0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL crabbymetrics-0.9.1-cp311-cp311-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d1c0132d3d78f2248e89ca76790c3daac093d47200207e96da4190885e5642bf
BLAKE2b-256 checksum
How to use checksums
412bed30be0a000f43fc05531bfda427229cb26c90e0e831db7a0d1550356bf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL crabbymetrics-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.6 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9a356f0191c81e882bbade0068fda9b602511301b7cbed51c246169e1d5900b9
BLAKE2b-256 checksum
How to use checksums
aa023f62dd75566a30e658b32a383623570d86d7f4a4189e51c6f0eac49043c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / crabbymetrics-0.9.1-cp310-cp310-macosx_11_0_arm64.whl

Download URL crabbymetrics-0.9.1-cp310-cp310-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7d2db48dc38727b7319cd30f0f6bacbbd8a761f1504882c8cbf9278d877ea06a
BLAKE2b-256 checksum
How to use checksums
25ae63644ed5321265032aefbfaf4d4f760480ef4e5b5544d4bc47197455122e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.1 This release

11 release files

0.8.2

11 release files

0.8.1

11 release files

0.8.0

11 release files

0.7.1

11 release files

0.7.0

11 release files

0.6.7

11 release files

0.6.6

10 release files

0.6.5

11 release files

0.6.4

11 release files

0.6.3

11 release files

0.5.1

11 release files

0.5.0

11 release files

0.4.1

11 release files

0.4.0

11 release files

0.3.6

11 release files

0.3.5

11 release files

0.3.1

11 release files

0.3.0

11 release 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