Lawfare Academy · Complete Regression and Business Forecasting edition 6

Diagnostics, validation and a defensible model-selection pipeline

Diagnose distinct failures rather than deleting difficult rows

A residual-versus-fitted curve challenges the conditional mean. A funnel challenges constant residual variance. Residual runs in observation order challenge independence or a stable mean. A quantile plot investigates the distribution relevant to small-sample inference and tails; normally distributed outcomes are not a general requirement of least-squares fitting. Inspect the collection process, units and time boundary before choosing a mathematical remedy. A transformed mean, a variance model, group-cluster covariance and a new data collection answer different problems. Heteroskedasticity-robust errors cannot correct an omitted cause or a predictor unavailable at deployment.

For full-rank X, H=X(X'X)^-1 X' maps outcomes to fitted values. Diagonal h_i measures leverage, lies between 0 and 1 and sums to p. Residual variance under a classical common-variance model is sigma²(1-h_i). An internally standardized residual is e_i/[s*sqrt(1-h_i)]. This is a diagnostic, not a universal normal tail test: s was estimated using the same outcomes and model selection changes the reference. External studentization refits the error scale leaving the observation out. Leverage is a design property; changing an outcome leaves h unchanged.

Cook's distance can be computed as D_i=[e_i²/(p*s²)]*[h_i/(1-h_i)²], when the stated fit and nonzero residual scale exist. It measures the combined coefficient/prediction movement in a defined geometry after deletion. A rule such as 4/n can prompt examination but is not an evidence-based automatic deletion policy for every design. Preserve the all-record fit, the sensitivity result, provenance findings and the selection rule. If rank disappears after deleting a sole category observation, a standard deleted-fit calculation may be undefined; that itself exposes weak design support.

Worked diagnostic: a small ordinary residual hides sensitivity

The preserved five-record application has x=(1,2,3,4,20), y=(2,4,6,8,0), slope-.24, intercept 5.44, SSE 25.6 and p 2. Its fifth residual is-.64 and h 5=.984. The residual variance estimate is 25.6/3=8.533333333. Its standardized residual is-.64/sqrt((25.6/3)*.016)=-sqrt(3), approximately-1.73205. That is not an innocuous observation simply because an ordinary residual threshold is small.

The deleted residual is e 5/(1-h 5)=-40; refitting the first four gives y=2 x and a prediction 40 atx 20. Cook's distance is[.4096/(2*(25.6/3))]*[.984/.016²]=92.25. This large sensitivity does not prove which observation is invalid. The four-record sensitivity fit extrapolates fromx 1 through 4 tox 20, and its zero residual scale cannot support an ordinary noisy-process confidence claim. Changing onlyy 5 to 40 keeps leverage.984 while every point lies on y=2 x; residual influence vanishes for that exact fixture. Preserve this distinction between geometric potential and actual outcome disagreement.

Investigate whether 0 was a valid processing time, a canceled job or a failed-timer sentinel. If an original log proves the timer failed, document recoding and missingness rather than erasing the original. If the measurement is valid, revisit the intended process model and collect reliable large-batch observations. A desired positive slope cannot be the exclusion rule. A robust fit or ridge changes an optimization objective; it does not adjudicate provenance or turn a coefficient into a causal effect.

Explain variance and dependence remedies at their actual scope

Weighted least squares minimizes sum(w_i*e_i²). If Var(e_i|X)=sigma²/w_i and the mean is correctly specified, this can reflect known relative precision. Multiplying all weights by a common constant leaves coefficients unchanged. Estimated weights add estimation choices and must be learned within training. A row weighted 10 times as heavily has ten times its residual-squared contribution; it is not necessarily ten independent observations. Survey inclusion weights target representation and inverse-variance weights target precision; do not swap them because both are called weights.

With covariance Omega, the least-squares coefficient covariance is (X'X)^-1 X'Omega X(X'X)^-1. The familiar sigma²(X'X)^-1 is a special case. A heteroskedasticity-consistent sandwich replaces Omega using residual-based terms with finite-sample variants; clustered and time-dependent estimators need group or lag structures. Their asymptotic approximations can be unreliable with few independent groups. The point estimator, error covariance, design and causal target should all be named. Full numerical implementation of every robust estimator is outside this introductory/intermediate course's accepted scope; understanding why a naive standard error fails is required here.

A pipeline is more than the final regression equation

Freeze an observation eligibility rule and an issue-time information ledger. Reserve a final chronological block appropriate to the operational horizon. Inside earlier history, choose expanding or sliding origins. At each origin fit imputation, scaling, feature construction and penalty selection using only the permitted training history. Compute candidates on common future targets with a common loss. A scaler fitted on the whole dataset leaks distributional information even without reading future labels. A physical conversion fixed by definition does not have that learned-data defect.

For an explicit comparison use the preserved holdout actuals(4,6,8,10). A predicts(5,5,9,9), B predicts(4,6,8,14). Both MAE 1; RMSE is 1 forAand 2 forB. Let underforecasting cost 3 perunit and overforecasting cost 1. A errors(-1,1,-1,1) give losses(1,3,1,3), total 8. B errors(0,0,0,-4) give total 4. Thus squared-error preferenceA and declared asymmetric-cost preferenceB can differ. Do not choose the cost after seeing which candidate wins. If a hard capacity or service constraint is the actual decision, evaluate that constraint explicitly rather than assuming a linear error cost.

Compare final-test and subsequent production errors with the frozen method version, not a hindsight refit. A sample RMSE is not the uncertainty of the estimated RMSE, and overlapping multi-step errors are dependent. Report the number of origins, horizon, subgroup support and the range of conditions. Monitor bias, calibration and data changes. If a threshold triggers retraining, preserve the trigger, old forecasts and new method version. The new model needs its own future evaluation; overwriting old forecasts hides the very evidence needed to judge improvement.

Optional practice

Guided model: diagnose, do not discard

For the fifth preserved record, residual-.64,leverage.984,deleted residual-40 andCookD 92.25 quantify different aspects of sensitivity. Changed fact: source logs prove a wrong unit conversion. Correct with a documented mapping, preserve the raw record and rerun all affected fits and evaluations. Do not retain only the favorable model while hiding the verified correction.

Independent model: tuning uses the test twice

Choosing a ridge penalty by the final four outcomes makes those outcomes part of development. Refit preprocessing and tuning within earlier folds, lock the procedure and seek a new untouched evaluation. Changed fact: a calculation typo in reporting is fixed without changing frozen predictions or selection. Document it; a clerical correction need not be model tuning. Reconstruct the actual action rather than applying a label automatically.

Transfer model: a loss reversal

A beatsBunderRMSE 1 versus 2, but BbeatsAunder declared shortage 3/surplus 1 loss 4 versus 8. Changed fact: shortage and surplus both cost 1. Both total absolute loss 4; this record no longer identifies a winner under that loss. Prefer a justified simpler process or collect more evidence rather than claiming superiority from a tied metric.

Unit rubric: 20 points

Four points each for distinct diagnostic meanings and provenance; correct influence arithmetic; variance/dependence remedy boundaries; complete training-only selection with frozen final evaluation; and declared decision-loss/monitoring response. Complete model retains the original difficult record, exposes its 92.25 CookD, gives both holdout metric and loss comparisons and proposes relevant future collection. It claims neither independent human review nor future performance from fitting identities.