crabbymetrics
  • Home
  • API
    • API Overview
    • Regression And GLMs
    • Survival / Event-Time
    • Causal Inference And Panels
    • MPE_CBPS
    • Hypothesis Testing And Utilities
    • Transforms
    • Estimation Interfaces
  • Internals
  • Regression
    • OLS
    • ABC OLS
    • Anytime-Valid Confidence Sequences
    • Ridge
    • Bagged Polynomial Regression
    • Fixed Effects OLS
    • ElasticNet
    • Logit
    • Multinomial Logit
    • Poisson
    • MLE Prediction Interface
    • Survival / Recurrent Events
    • GMM
    • MEstimator Poisson
  • Causal / Panels
    • Balancing Weights
    • Chronos LTV Balancing
    • Cressie-Read And Rényi Balancing
    • EPLM
    • Average Derivative
    • Double ML And AIPW
    • Richer Regression
    • TwoSLS
    • Synthetic Control
    • Synthetic DID
    • Augmented Balancing For Panel Data
    • Horizontal Panel Ridge
    • Matrix Completion
    • Interactive Fixed Effects
    • Staggered Panel Event Study
    • Joint Hypothesis Tests
    • Dynamic Treatment Effects
  • Transforms
    • PCA And Kernel Basis
    • Sparse Factor Rotations
  • Ablations
    • Variance Estimators
    • Semiparametric Estimator Comparisons
    • Two-Period Semiparametric DID
    • Bridging Finite And Superpopulation
    • Panel Estimator DGP Comparisons
    • Same Root Panel Case Studies
    • Randomized Sketching And Least Squares
    • Estimator Scaling And References
  • Optimization
    • Optimizers
    • GMM With Optimizers
  • Ding
    • Chapter Index
    • Foundations (1-4)
    • Design And Adjustment (5-8)
    • Finite And Superpopulation (9)
    • Observational Studies (11-13, 27)
    • Instrumental Variables (21, 23)

On this page

  • 1 Overview
  • 2 Shared contracts
  • 3 Regression and GLMs
  • 4 Survival, time-to-event, and recurrent-event models
  • 5 Causal inference and panels
    • 5.1 Treatment effects, IV, and balancing
    • 5.2 Dynamic treatment regimes
    • 5.3 Panel estimators
  • 6 Hypothesis testing and utilities
  • 7 Transforms
  • 8 Estimation interfaces and optimizers

crabbymetrics API Reference

Public classes, signatures, and data contracts

1 Overview

crabbymetrics is a compact Rust-backed econometrics library exposed to Python through pyo3 and packaged with maturin. The public API is intentionally small: estimator classes, transformer classes, an Optimizers helper namespace, numpy arrays as the only runtime dependency, and a scikit-adjacent fit / predict / summary pattern.

The linked class pages describe each estimator’s objective, assumptions, inference, and limitations. Tables below are generated from the installed v0.9.0 module.

2 Shared contracts

  • Pass NumPy arrays with the dtype and shape documented on the class page.
  • Fits mutate the object in place; summaries return dictionaries.
  • A failed validation or numerical refit clears learned state once Rust fit code is entered.
  • Regularized or rank-deficient likelihood fits can have valid predictions without available standard errors.
  • Cox-style models return relative risk; their baseline hazard is not estimated.
  • See the v0.9 migration guide for weighting, callback, and convergence changes.

3 Regression and GLMs

This is the general supervised-learning part of the library: regression, classification, count models, and related coefficient-inference utilities. Anytime-valid confidence sequences currently enter through the fitted OLS summary interface.

Reference pages:

  • OLS
  • ABCOLS
  • Anytime-Valid Confidence Sequences
  • Ridge
  • FixedEffectsOLS
  • ElasticNet
  • BaggedPolynomialRegressor
  • Logit
  • MultinomialLogit
  • Poisson

Worked docs:

  • ABC OLS
  • Bagged Polynomial Regression
  • Anytime-Valid Confidence Sequences
  • MLE Prediction Interface
  • Logit
  • Multinomial Logit
  • Poisson
Show code
display(HTML(html_table(
    ["Constructor", "Methods"],
    class_rows([
        cm.OLS,
        cm.ABCOLS,
        cm.Ridge,
        cm.FixedEffectsOLS,
        cm.ElasticNet,
        cm.BaggedPolynomialRegressor,
        cm.Logit,
        cm.MultinomialLogit,
        cm.Poisson,
    ])
)))
Constructor Methods
OLS() bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, x, y)
fit_sketch(self, /, x, y, sketch_size, seed=None)
fit_weighted(self, /, x, y, sample_weight)
predict(self, /, x)
summary(self, /, vcov='hc1', lags=None, clusters=None, anytime_valid=False, g=1.0, level=0.95)
wald_test(self, /, r, q=None, vcov=None, lags=None, clusters=None)
ABCOLS() column_names(self, /)
constraint_matrix(self, /)
design_matrix(self, /)
fit(self, /, y, x, categories, cont_cat_interactions=None, cat_cat_interactions=None, center_continuous=True)
fitted_values(self, /)
predict(self, /, x, categories)
residuals(self, /)
summary(self, /)
Ridge(penalty=None, cv=5) bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, x, y)
fit_weighted(self, /, x, y, sample_weight)
predict(self, /, x)
summary(self, /, vcov='hc1', lags=None, clusters=None)
FixedEffectsOLS() bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, x, fe, y)
fit_weighted(self, /, x, fe, y, sample_weight)
summary(self, /, vcov='hc1', lags=None, clusters=None)
wald_test(self, /, r, q=None, vcov=None, lags=None, clusters=None)
ElasticNet(penalty=1.0, l1_ratio=0.5, tolerance=0.0001, max_iterations=1000) bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, x, y)
predict(self, /, x)
summary(self, /)
BaggedPolynomialRegressor(n_estimators=50, degree=2, max_features=None, max_samples=None, bootstrap=True, penalty=1.0, seed=42) fit(self, /, x, y)
predict(self, /, x)
summary(self, /)
Logit(alpha=0.0, max_iterations=100, gradient_tolerance=0.0001) bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, x, y)
predict(self, /, x)
predict_label(self, /, x, cutoff=0.5)
predict_lin(self, /, x)
summary(self, /)
wald_test(self, /, r, q=None)
MultinomialLogit(alpha=0.0, max_iterations=100, gradient_tolerance=0.0001) bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, x, y)
predict(self, /, x)
predict_label(self, /, x)
predict_lin(self, /, x)
summary(self, /)
Poisson(alpha=0.0, max_iterations=100, tolerance=0.0001) bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, x, y)
predict(self, /, x)
predict_lin(self, /, x)
summary(self, /, vcov='vanilla')
wald_test(self, /, r, q=None, vcov='vanilla')

4 Survival, time-to-event, and recurrent-event models

Reference pages:

  • ExponentialPH
  • WeibullPH
  • CoxPH
  • AndersenGill

Worked docs:

  • Survival / Time-to-Event / Recurrent Events
  • Survival Models (compact worked example)
Show code
display(HTML(html_table(
    ["Constructor", "Methods"],
    class_rows([
        cm.ExponentialPH,
        cm.WeibullPH,
        cm.CoxPH,
        cm.AndersenGill,
    ])
)))
Constructor Methods
ExponentialPH() fit(self, /, x, time, event, max_iterations=100, tolerance=1e-08)
predict(self, /, x, time)
predict_cumulative_hazard(self, /, x, time)
predict_hazard(self, /, x)
predict_lin(self, /, x)
predict_log_hazard(self, /, x)
predict_survival(self, /, x, time)
summary(self, /)
survival(self, /, x, time)
WeibullPH() fit(self, /, x, time, event, max_iterations=100, tolerance=1e-08)
predict(self, /, x, time)
predict_cumulative_hazard(self, /, x, time)
predict_hazard(self, /, x, time)
predict_lin(self, /, x, time)
predict_log_hazard(self, /, x, time)
predict_survival(self, /, x, time)
summary(self, /)
survival(self, /, x, time)
CoxPH() fit(self, /, x, time, event, max_iterations=50, tolerance=1e-08)
predict(self, /, x)
predict_lin(self, /, x)
predict_log_hazard_ratio(self, /, x)
predict_relative_risk(self, /, x)
summary(self, /)
AndersenGill() fit(self, /, x, start, stop, event, max_iterations=50, tolerance=1e-08)
predict(self, /, x)
predict_lin(self, /, x)
predict_log_hazard_ratio(self, /, x)
predict_relative_risk(self, /, x)
summary(self, /)

5 Causal inference and panels

5.1 Treatment effects, IV, and balancing

Reference pages:

  • TwoSLS
  • BalancingWeights
  • MPE_CBPS
  • EPLM
  • AverageDerivative
  • PartiallyLinearDML
  • AIPW

Worked docs:

  • TwoSLS
  • Balancing Weights
  • Chronos LTV Balancing
  • Cressie–Read and Rényi Balancing
  • EPLM
  • Average Derivative
  • Double ML and AIPW
Show code
display(HTML(html_table(
    ["Constructor", "Methods"],
    class_rows([
        cm.TwoSLS,
        cm.BalancingWeights,
        cm.MPE_CBPS,
        cm.EPLM,
        cm.AverageDerivative,
        cm.PartiallyLinearDML,
        cm.AIPW,
    ])
)))
Constructor Methods
TwoSLS() anderson_rubin_test(self, /, beta=0.0, vcov='hc1', lags=None, clusters=None)
bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, x_endog, x_exog, z, y)
fit_sketch(self, /, x_endog, x_exog, z, y, sketch_size, seed=None)
fit_weighted(self, /, x_endog, x_exog, z, y, sample_weight)
predict(self, /, x)
summary(self, /, vcov='hc1', lags=None, clusters=None)
wald_test(self, /, r, q=None, vcov=None, lags=None, clusters=None)
BalancingWeights(objective='quadratic', solver='auto', autoscale=False, min_weight=0.0, max_weight=1.0, l2_norm=0.0, max_iterations=200, tolerance=1e-08, divergence_power=0.0, dual_ridge=0.0) fit(self, /, covariates, target_covariates, baseline_weights=None, target_weights=None)
get_weights(self, /)
summary(self, /)
MPE_CBPS(standardize=True, max_iterations=500, tolerance=1e-08, max_log_weight=50.0) estimate(self, /, outcome, denominator=None)
fit(self, /, covariates, treatment, policy_derivative=None)
get_weights(self, /, arm)
summary(self, /)
EPLM(fd_eps=1e-06) fit(self, /, y, d, w)
summary(self, /, vcov=None, lags=None, clusters=None)
AverageDerivative(method='dr', fd_eps=1e-06) fit(self, /, y, d, w)
summary(self, /, vcov=None, lags=None, clusters=None)
PartiallyLinearDML(penalty=None, cv=5, n_folds=5, seed=42) fit(self, /, y, d, x)
summary(self, /, vcov=None, lags=None, clusters=None)
AIPW(penalty=None, cv=5, n_folds=5, propensity_clip=0.02, seed=42) fit(self, /, y, d, x)
summary(self, /, vcov=None, lags=None, clusters=None)

5.2 Dynamic treatment regimes

The three longitudinal estimators have deliberately different timing contracts. RegressionBlip takes same-shaped outcome and treatment panels because treatment at \(t\) may affect \(Y_t\). ParallelTrendsSNMM takes an outcome panel with one extra column because treatment at \(t\) first affects \(Y_{t+1}\). DynamicCovariateBalance takes a scalar final outcome and estimates one path-specific mean per fitted object.

  • RegressionBlip, ParallelTrendsSNMM, and DynamicCovariateBalance
Show code
display(HTML(html_table(
    ["Constructor", "Methods"],
    class_rows([
        cm.RegressionBlip,
        cm.ParallelTrendsSNMM,
        cm.DynamicCovariateBalance,
    ])
)))
Constructor Methods
RegressionBlip(max_lag=1, time_effects=True) blip_down(self, /, y, treatment)
fit(self, /, y, treatment, history=None)
summary(self, /)
ParallelTrendsSNMM(max_horizon=1, treatment_mode='blip', n_folds=2, nuisance_penalty=1e-06, propensity_clip=0.01, seed=42) fit(self, /, y, treatment, history=None)
summary(self, /)
DynamicCovariateBalance(nuisance_penalty=1e-06, autoscale=True, max_weight=1.0, max_iterations=300, tolerance=1e-06) fit(self, /, outcome, treatment, history, target_path)
get_weights(self, /)
summary(self, /)

5.3 Panel estimators

  • SyntheticControl
  • HorizontalPanelRidge
  • SyntheticDID
  • AugmentedBalancing
  • MatrixCompletion
  • InteractiveFixedEffects

Worked docs:

  • Synthetic Control
  • Horizontal Panel Ridge
  • Synthetic DID
  • Augmented Balancing for Panel Data
  • Matrix Completion
  • Interactive Fixed Effects
  • Staggered Panel Event Study
Show code
display(HTML(html_table(
    ["Constructor", "Methods"],
    class_rows([
        cm.SyntheticControl,
        cm.HorizontalPanelRidge,
        cm.SyntheticDID,
        cm.AugmentedBalancing,
        cm.MatrixCompletion,
        cm.InteractiveFixedEffects,
    ])
)))
Constructor Methods
SyntheticControl(max_iterations=500) bootstrap(self, /, n_bootstrap, seed=None)
fit(self, /, donors, treated)
predict(self, /, donors)
summary(self, /)
HorizontalPanelRidge(penalty=1.0) fit(self, /, y, w)
predict(self, /)
summary(self, /)
treatment_effect(self, /)
SyntheticDID(zeta_omega=None, zeta_lambda=None, max_iterations=1000) fit(self, /, y, w)
predict(self, /)
se(self, /, method='bootstrap', replications=200, seed=None)
summary(self, /)
treatment_effect(self, /)
vcov(self, /, method='bootstrap', replications=200, seed=None)
AugmentedBalancing(balance='double', unit_target='cohort', time_target='all', balance_on='raw', unit_loss='ridge', unit_penalty=0.0001, zeta_omega=None, zeta_lambda=None, max_iterations=1000) fit(self, /, y, w, outcome_model=None)
predict(self, /)
summary(self, /)
treatment_effect(self, /)
MatrixCompletion(lambda_l=None, lambda_fraction=0.25, fit_unit_effects=True, fit_time_effects=True, max_iterations=500, effect_iterations=2, tolerance=1e-06, svd_method=Ellipsis, svd_rank=None, svd_oversamples=10, svd_power_iter=1, svd_seed=None) fit(self, /, y, w)
predict(self, /)
summary(self, /, *, include_matrices=True)
InteractiveFixedEffects(rank=0, force=3, factor_method=Ellipsis, factor_oversamples=10, factor_power_iter=1, factor_seed=None) fit(self, /, y)
predict(self, /)
summary(self, /)

6 Hypothesis testing and utilities

  • Hypothesis Tests

7 Transforms

  • PCA and RandomizedPCA
  • KernelBasis, NystromBasis, and RandomFourierFeatures
  • Sparse Factor Rotations
Show code
display(HTML(html_table(
    ["Constructor", "Methods"],
    class_rows([
        cm.PCA,
        cm.RandomizedPCA,
        cm.KernelBasis,
        cm.NystromBasis,
        cm.RandomFourierFeatures,
    ])
)))
Constructor Methods
PCA(n_components, whiten=False) fit(self, /, x)
fit_transform(self, /, x)
inverse_transform(self, /, scores)
summary(self, /)
transform(self, /, x)
RandomizedPCA(n_components, oversamples=10, power_iter=1, seed=None) fit(self, /, x)
fit_transform(self, /, x)
inverse_transform(self, /, scores)
summary(self, /)
transform(self, /, x)
KernelBasis(kernel='gaussian', bandwidth=0.5, coef0=1.0, degree=2.0) fit(self, /, x)
fit_transform(self, /, x)
summary(self, /)
transform(self, /, x)
NystromBasis(n_components, kernel='gaussian', bandwidth=0.5, coef0=1.0, degree=2.0, ridge=1e-10, seed=None) fit(self, /, x)
fit_transform(self, /, x)
summary(self, /)
transform(self, /, x)
RandomFourierFeatures(n_components, bandwidth=0.5, seed=None) fit(self, /, x)
fit_transform(self, /, x)
summary(self, /)
transform(self, /, x)

Function utilities:

  • varimax_rotation(loadings, normalize=False)
  • l1_sparse_rotation(loadings, n_starts=None, seed=None, max_iter=None, tol=1e-7)
  • count_small_loadings(loadings, threshold=None)
  • local_factor_diagnostic(loadings, threshold=None, alpha=0.05, gamma0=0.03)
  • inverse_participation_ratio(loadings, axis=0)
  • cumulative_participation(loadings)

8 Estimation interfaces and optimizers

  • GMM
  • MEstimator
  • Optimizers
Show code
display(HTML(html_table(
    ["Constructor", "Methods"],
    class_rows([cm.GMM, cm.MEstimator, cm.Optimizers]),
)))
Constructor Methods
GMM(moment_fn, jacobian_fn=None, max_iterations=100, tolerance=1e-06, ridge=1e-08, fd_eps=1e-06) fit(self, /, data, theta0, weighting='auto')
fit_sketch(self, /, data, theta0, sketch_size, weighting='auto', seed=None)
summary(self, /, vcov='sandwich', omega='iid', lags=None, clusters=None, *, assume_optimal_weighting=False)
wald_test(self, /, r, q=None, vcov='sandwich', omega='iid', lags=None, clusters=None, *, assume_optimal_weighting=False)
MEstimator(objective_fn, score_fn, max_iterations=100, tolerance=1e-06, derivative_step=1e-06) bootstrap(self, /, n_bootstrap, seed=None)
compute_vcov(self, /)
fit(self, /, data, theta0)
summary(self, /)
Optimizers() minimize_bfgs(fun, x0, grad, max_iterations=100, tolerance=1e-06)
minimize_gauss_newton_ls(residual_fn, x0, jacobian_fn, max_iterations=100, tolerance=1e-06)
minimize_lbfgs(fun, x0, grad, max_iterations=100, tolerance=1e-06)
minimize_nonlinear_cg(fun, x0, grad, max_iterations=100, restart_iters=10, restart_orthogonality=0.1, tolerance=1e-06)
minimize_simulated_annealing(fun, x0, lower=None, upper=None, temp=15.0, step_size=0.1, max_iterations=5000, seed=None)

crabbymetrics 0.9.0

 
  • v0.9 migration

  • Reproduction