crabbymetrics / hyptests branch
Hypothesis tests in crabbymetrics
A small user-facing layer for Wald tests on fitted estimators, plus scalar likelihood-ratio helpers for nested likelihood comparisons.
Design choice. Wald tests are methods on fitted estimators, because the estimator owns the covariance calculation. The array-level function remains available for manual workflows. Likelihood-ratio tests stay as scalar helpers for now, because they compare two nested likelihood values rather than one covariance summary.
Estimator-level Wald tests
For intercept-bearing estimators, restrictions use coefficient order [intercept, slopes...]. For fixed-effects summaries without an intercept, use the slope order.
import numpy as np
import crabbymetrics as cm
rng = np.random.default_rng(123)
x = rng.normal(size=(300, 3))
y = 1.0 + x @ np.array([0.0, 0.0, 0.8]) + rng.normal(scale=0.7, size=300)
model = cm.OLS()
model.fit(x, y)
# H0: beta_1 = beta_2 = 0
R = np.array([
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
])
model.wald_test(R, vcov="hc1")
# {'statistic': ..., 'df': 2, 'p_value': ..., 'test': 'wald'}
Supported fitted classes
OLS.wald_test(R, q=None, vcov="hc1", lags=None, clusters=None)FixedEffectsOLS.wald_test(R, q=None, vcov="hc1", lags=None, clusters=None)TwoSLS.wald_test(R, q=None, vcov="hc1", lags=None, clusters=None)Logit.wald_test(R, q=None)Poisson.wald_test(R, q=None, vcov="vanilla")GMM.wald_test(R, q=None, vcov="sandwich", omega="iid", lags=None, clusters=None)
Array-level primitive
Use this when coefficients and covariance come from a custom calculation or from a summary dictionary.
summary = model.summary(vcov="hc1")
coef = np.r_[summary["intercept"], summary["coef"]]
cm.wald_test(coef, summary["vcov"], R)
Likelihood-ratio helper
cm.lr_test(unrestricted_loglik=-100.0, restricted_loglik=-103.0, df=2)
# same as cm.likelihood_ratio_test(...)
Local branch: hyptests. Main gate at time of writing: uv run pytest -q passes 99 tests.