DEVELOPED COURSE TEXT
Diagnose influence and choose an uncertainty calculation
Read residual patterns as evidence about a model
A residual is observed sales minus the fitted conditional mean, not the true structural error. Plot residuals against fitted sales, each continuous predictor and month. Curvature can suggest a misspecified mean; a widening spread can suggest changing variance; runs over time can suggest dependence or an omitted changing process. These are diagnostic clues, not mechanical proof of a particular cause. The Harbor generator contains heteroscedastic innovations and serial persistence, but a short fitted residual sequence can mask or distort those features.
The baseline residual lag-one correlation is about .089 in this realization. This small sample value does not establish independent errors, especially after fitting a trend and correlated predictors. A diagnostic statistic has its own uncertainty and power. The model's known construction provides a stronger teaching explanation than a single observed correlation. In a real study, process knowledge and the sampling design should accompany residual checks rather than be replaced by them.
Separate leverage, unusual outcomes and influence
The hat matrix H=X(X transposed X) inverse X transposed maps outcomes to fitted values. Its diagonal h_i measures leverage from a row's predictor position. A high-leverage observation can pull the fitted surface strongly if its outcome is also inconsistent with the rest. A large residual with ordinary predictors can be an outcome outlier without high leverage. Influence concerns how much fitted quantities or coefficients change when a row is perturbed or removed; these concepts should not be collapsed into one outlier label.
Cook's distance in the conventional linear model is e_i squared h_i divided by k sigma-hat squared (1-h_i) squared. The formula combines residual size and leverage. It is a screening summary, not an automatic deletion rule. In this record month 8 has the largest Cook distance. Deleting it changes the price coefficient from approximately -1.417 to -1.349 and the promotion coefficient from 6.859 to 7.902. Those changes should be reported with the reason for any exclusion, not hidden to improve a preferred result.
Derive sandwich covariance and its limits
Under independent but heteroscedastic errors, the coefficient covariance has the sandwich form A X transposed Omega X A, where A=(X transposed X) inverse and Omega is the error covariance. HC3 substitutes diagonal terms e_i squared/(1-h_i) squared. This leverage adjustment can matter in small samples or with unusual predictor rows. The fitted coefficients do not change; only the uncertainty estimate changes. The actual baseline price SE is about .348 conventionally and .375 under HC3.
HC3 does not account for arbitrary serial correlation, and it does not remove omitted-variable bias. A heteroscedasticity-and-autocorrelation-consistent calculation includes weighted cross-products of score contributions across lags. The supplied analysis uses Bartlett weights through lag two, with no additional finite-sample correction, and labels the output HAC(2). Its price SE is about .311 here. Robust SEs need not be larger than conventional ones in every finite sample. Reporting the smallest available SE without a design-based reason would be specification shopping.
Decide what to repair and preserve a sensitivity record
If month 8 contains a verified recording error, correct the source record and document the correction. If it is a valid unusual business month, deletion changes the population or operating regime represented. Present a sensitivity fit and investigate whether the model needs a known event indicator or a different process. Adding such an indicator after looking at the residuals is a development revision and requires honest evaluation. It is not a neutral data cleaning step.
A diagnostic report should state the suspected failure, the evidence, the proposed repair and which conclusions change. Mean misspecification may require different predictors or transformations. Dependence may require a covariance model, a forecasting model or a different evaluation design. Influential rows may require verification and sensitivity analysis. No single diagnostic threshold proves the model acceptable. The objective is a defensible account of where the fitted relationship is stable, where it depends on a few observations and what uncertainty procedure matches the actual question.
Worked records
Record 1
Baseline development fit; all 24 months are retained in the primary record. Month 8 has the largest computed Cook distance. HC3 and HAC(2) use the explicit formulas in mba614-analysis.py.
Develop the reasoning
Baseline price estimate=-1.416908, conventional SE=0.348011, HC3 SE=0.375050, HAC(2) SE=0.311185. Deleting the most influential row gives price=-1.349327 and promotion=7.901577. The deletion is a sensitivity comparison, not an approved cleaning decision. Preserve the full-data result as the primary fit.
Progressive practice — optional
1. Foundation
Can a row have high leverage and a small residual?
Compare the worked reasoning
Yes. Leverage depends only on predictors; an unusual predictor row can lie close to the fitted surface.
Change the record
Its outcome is moved far from the fitted surface.
Compare the changed-record reasoning
Residual size and influence can rise substantially; refit or compute influence rather than infer it from leverage alone.
2. Application
Does changing conventional covariance to HC3 alter OLS coefficients?
Compare the worked reasoning
No. The least-squares fit is unchanged; the covariance estimate changes.
Change the record
The analyst instead performs weighted least squares.
Compare the changed-record reasoning
Weights change the estimation objective and can change coefficients and fitted values. This is a different operation requiring a justified variance model.
3. Transfer
Should month 8 be deleted because Cook distance is the largest?
Compare the worked reasoning
No. Verify its record and substantive meaning, then report sensitivity and any justified correction.
Change the record
A duplicate transaction is independently verified in its sales total.
Compare the changed-record reasoning
Correct the documented duplication, preserve an audit trail and refit. The justification is source accuracy, not the desire to reduce influence or improve significance.
Sources and scope
- NIST/SEMATECH: Linear Least Squares Regression: Official statistical-methods reference verified for least-squares regression. Assigned methodological reading; all data and calculations below are original fictional examples.
- NIST: Regression Diagnostics: Official reference verified for influence and diagnostic concepts. Compare with the explicitly defined leverage/Cook calculations in this original record.
- NumPy: numpy.linalg.lstsq: Official API documentation verified for reproducible least-squares computation. The supplied analysis uses this routine and separately calculates diagnostics.