Sequentially valid coefficient inference from the OLS summary interface
1 Why Anytime-Valid?
Ordinary linear regression summaries are fixed-sample summaries. They are calibrated for a sample size chosen before looking at the data. Anytime-valid inference is useful when the same analysis might be checked repeatedly as observations arrive, because its p-values and confidence intervals are calibrated for optional stopping.
crabbymetrics exposes this through the usual OLS.summary(...) method rather than through a separate model class:
out = model.summary(vcov="vanilla", anytime_valid=True, g=g_star)
The coefficient estimates are still the ordinary least-squares estimates. The extra fields in the summary are the anytime-valid p-values, confidence intervals, and omnibus F-test p-value.
2 Data-Generating Example
This mirrors the structure of the avlm README example: three centered covariates, a binary treatment, and treatment-by-covariate interactions. The coefficient on trt is a baseline treatment effect, while the interaction coefficients allow that effect to vary with the covariates.
Show code
import numpy as npfrom html import escapefrom IPython.display import HTML, displayimport crabbymetrics as cmnp.set_printoptions(precision=4, suppress=True)def html_table(headers, rows): parts = ["<table>", "<thead>", "<tr>"] parts.extend(f"<th>{escape(str(header))}</th>"for header in headers) parts.extend(["</tr>", "</thead>", "<tbody>"])for row in rows: parts.append("<tr>") parts.extend(f"<td>{cell}</td>"for cell in row) parts.append("</tr>") parts.extend(["</tbody>", "</table>"])return"".join(parts)rng = np.random.default_rng(1)n =100x = rng.normal(size=(n, 3))x = x - x.mean(axis=0)trt = rng.choice([0.0, 1.0], size=n)noise = rng.normal(size=n)y = (1.0+1.4* x[:, 2]+2.3* trt+2.0* x[:, 0] * trt+3.0* x[:, 1] * trt+ noise)design = np.column_stack([x, trt, x * trt[:, None]])coef_names = ["Intercept", "X1", "X2", "X3", "trt", "X1:trt", "X2:trt", "X3:trt"]
3 Fit OLS Once
The fitted model is just cm.OLS(). The optimal_g(...) helper chooses the mixture precision parameter that minimizes the anytime-valid confidence-interval width at this target sample size and significance level.
The second argument to optimal_g is the total coefficient count, including the intercept fitted internally by OLS.