Choose your reading route
eduKateSG · Why Mathematics? · White Sandwich Covariance: Heteroscedasticity-Robust Standard Errors
Start with the question, audit the worked example, or jump to the assumptions and practice. Every chapter stays open for uninterrupted reading.
Understand the question
Define the quantity and follow the mechanism.Route 2 · Chapters 6–11
Reproduce the example
Audit the numbers one step at a time.Route 3 · Chapters 12–18
Check assumptions
See where design and calibration matter.Route 4 · Chapters 19–24
Explore applications
Connect the method to a concrete investigation.Route 5 · Chapters 25–36
Study and verify
Practise, inspect failure cases and read further.
Full chapter index · Practice and checking · Mathematics Learning Hub
Why is mathematics important when the familiar regression standard error assumes a constant error variance that the data may not have? White's sandwich covariance estimator keeps the ordinary least-squares coefficients but rebuilds their estimated covariance from the observed residual pattern. The result is often called a heteroscedasticity-consistent or heteroscedasticity-robust standard error.
Did You Know? The nickname “sandwich” describes the matrix shape: an empirical residual cross-product, the meat, sits between two copies of the inverse design cross-product, the bread. It is memorable, but every layer has a precise job.
Full chapter index
Chapters 1–5 · Understand the question
Chapters 6–11 · Reproduce the example
Chapters 12–18 · Check assumptions
Chapters 19–24 · Explore applications
Chapters 25–36 · Study and verify
- Applications and careers
- A student investigation
- Common misconceptions
- Connection to recent mathematics articles
- Guidance for students and parents
- Practice questions
- Frequently asked questions
- A reporting checklist
- Why row contributions matter
- Communicating threshold changes
- Final White-covariance audit
- Useful next reading
A fitted line answers where the estimated conditional mean lies. A standard error answers how much that coefficient estimate would vary across repeated samples under a specified sampling model. Unequal error variances do not automatically change the OLS coefficient calculation, but they can make the usual homoscedastic covariance formula a poor description of that sampling variation.
Halbert White's 1980 Econometrica paper developed a covariance estimator that is consistent under heteroscedasticity when the mean model and regularity conditions are suitable. Read the paper. Current statsmodels documentation groups HC0, HC1, HC2 and HC3 under sandwich covariance estimators. Read the documentation.
For OLS with design matrix X and residuals e_i, HC0 estimates Cov(beta-hat) as (X^T X)^−1 X^T diag(e_i²) X (X^T X)^−1. The two inverse cross-product matrices translate observation-level score variation into coefficient space. The middle matrix lets observations contribute different squared residual magnitudes.
| XTX | Meat | Bread |
|---|---|---|
| 10 | 40 | 0.1 |
Use a deliberately simplified one-parameter illustration. Suppose X^T X=10, the scalar meat X^T diag(e_i²)X=40 and therefore each bread factor is 1/10. The HC0 variance estimate is (1/10)×40×(1/10)=0.4. Its standard error is sqrt(0.4)=0.6325, rounded to four decimal places.
| Variance | Standard error |
|---|---|
| 0.4 | 0.6325 |
Changing the covariance estimator after an OLS fit does not refit the line. The coefficient estimates, fitted values and raw residuals remain the same. The estimated covariance matrix changes, so standard errors, test statistics, confidence intervals and p-values may change. That distinction prevents the common claim that robust standard errors repair biased coefficients.
Heteroscedasticity means the conditional error variance differs across observations or predictor settings. A residual-versus-fitted plot may show a funnel, bands or changing spread, but the pattern should be interpreted alongside the data-generating process. A formal test can support diagnosis; it cannot replace a substantive model of why variance changes.
The conventional OLS covariance formula multiplies (X^T X)^−1 by one common residual variance estimate. When large residual variance is concentrated in influential parts of the predictor space, a single scale can misrepresent coefficient uncertainty. The sandwich meat retains which design rows carried which squared residuals.
If X has n rows and p columns, X^T X is p by p, the meat is p by p and the final covariance matrix is p by p. Every diagonal entry estimates a coefficient variance; every off-diagonal entry estimates covariance between coefficient estimates. Checking dimensions is a fast way to catch a transposition error.
True disturbances are unobserved because population coefficients are unknown. HC0 substitutes fitted residuals. This plug-in step is asymptotically justified under conditions, but residuals can be systematically shrunken at high-leverage observations. HC2 and HC3 address that issue more directly.
Heteroscedasticity-consistent describes an asymptotic property. It does not promise exact finite-sample coverage. Adequate sample size depends on leverage, the number of fitted parameters, tail behaviour and design balance, not on one universal observation count.
Robust standard errors do not make residual plots optional. A plot can reveal curvature, missing groups, outliers, variance changes or data coding problems. Some of those issues threaten the mean model or the coefficient itself, which a covariance adjustment cannot solve.
The Breusch–Pagan test asks whether residual variance is systematically related to specified variables. A small p-value can motivate closer inspection, while a large p-value does not prove equal variance. The robust covariance estimator answers a different question: how to estimate coefficient uncertainty without imposing one constant variance.
A robust coefficient standard error concerns uncertainty in estimated mean parameters. A prediction interval for a new outcome must also represent the new observation's error variance. If variance changes with predictors, a single constant-width prediction band remains inappropriate even when coefficient inference is robust.
Squared residuals can give an unusual observation a large role in the meat. HC estimators protect against a variance pattern under regularity conditions; they are not robust regression estimators against contamination. Influence diagnostics and data validation still matter.
Imagine modelling delivery time against travel distance. Longer routes may have more variable delays. OLS can still estimate the mean linear trend under an appropriate conditional-mean model, while a sandwich covariance can reflect the unequal spread when reporting uncertainty for the slope.
Measurement precision can worsen at high concentrations or larger signals. Before choosing robust inference, scientists should ask whether a transformation, a mechanistic variance model or weighted least squares better expresses the measurement process. The sandwich estimate is a useful protection, not a substitute for scientific structure.
Weighted least squares changes the coefficient estimator by assigning inverse-variance weights when a credible variance model is available. HC covariance keeps the OLS estimator and changes its estimated uncertainty. WLS may improve efficiency when its weights are right; misspecified weights can be misleading.
CHAPTER 18 OF 36 · Check assumptions
18. A comparison with generalized least squares
GLS models a full covariance structure and can handle correlation as well as unequal variance. White's basic HC estimator permits heteroscedasticity across independent observations but does not by itself handle serial or within-cluster dependence. Dependence requires HAC, cluster-robust or another suitable structure.
Report conventional and HC estimates, inspect leverage and residuals, try a defensible HC small-sample correction, and explain whether a practical decision changes. If only a threshold p-value changes, show the interval and effect size rather than presenting a dramatic yes-or-no story.
State that OLS coefficients were retained while a heteroscedasticity-consistent sandwich covariance was used to estimate their uncertainty under unequal variance.
White standard errors do not cure omitted variables, measurement error, simultaneity, nonlinearity, selection bias, dependent observations or poor external validity. They also do not guarantee reliable inference with very small samples, extreme leverage or weak identification.
Students can connect matrices, residuals, variance, asymptotic reasoning and model criticism by calculating the scalar sandwich first, then building the full matrix one row contribution at a time.
Create columns for each design value, residual, squared residual and row contribution e_i² x_i x_i^T. Sum the row contributions to form the meat, multiply by the bread on both sides and take square roots of diagonal entries. Keep unrounded values until the final display.
Fit OLS once, then request an HC covariance through a documented routine rather than coding matrix inversion casually. Statsmodels exposes robust covariance results through `get_robustcov_results`; verify the covariance type and compare with a hand-worked case. Read the API.
Sandwich covariance methods appear in economics, epidemiology, education research, environmental modelling, business analytics and engineering. Careers also require subject knowledge, communication, data governance and careful study design; mathematics supports those decisions without guaranteeing a job outcome.
Simulate x values from 0 to 10 and errors whose standard deviation grows with x. Fit OLS repeatedly. Compare the empirical spread of slopes with conventional and HC standard errors, then repeat with one high-leverage x value. Explain why the second experiment is harder.
“Robust” does not mean every assumption disappears. It does not change the slope, validate linearity, make dependent rows independent, prove causality or neutralise influential data. HC0 is also not automatically the best finite-sample choice.
The Breusch–Pagan guide explains a variance diagnostic. The Generalized Least Squares guide explains covariance weighting. The Gauss–Markov guide explains efficiency assumptions.
Students should show which matrix is the bread and which is the meat, then say what inferential quantity changed. Parents can ask, “Does this method repair the model, or only estimate uncertainty differently?” That question encourages accurate language without turning the exercise into a hunt for a preferred p-value.
- Recalculate the scalar variance and standard error.
- Explain why coefficients stay fixed.
- Name one problem HC0 cannot fix.
- Compare HC inference with weighted least squares.
- Describe a residual plot that would prompt a mean-model revision.
### Does HC0 change fitted values? No.
### Is White's estimator exact in small samples? No; its main guarantee is asymptotic under suitable conditions.
### Can it handle clustered observations? Not the basic HC form.
### Should I stop checking residuals? No.
Name the sampling unit, regression formula, target coefficient, dependence structure, covariance estimator and finite-sample choices. Show the conventional and robust uncertainty side by side when that comparison is useful. State what changed, what did not change and which assumptions remain open.
Write the meat as a sum over observations: Σ e_i² x_i x_i^T. This view shows that uncertainty depends jointly on residual size and design position. Two observations with equal residuals need not contribute equally because their predictor vectors differ.
If a conventional interval excludes zero but an HC interval includes it, report both intervals and the design reason for preferring the robust one. Avoid saying the effect vanished: the point estimate did not move. The evidence about its precision was reassessed.
Confirm independent sampling at the observation level, a defensible conditional-mean specification, enough information relative to leverage and parameters, a documented HC variant and reproducible calculations. Then state remaining threats openly.
Continue through the Mathematics Learning Hub. Reproduce the arithmetic by hand, then compare it with documented software output and explain any difference before relying on the result.
Extended practice laboratory
Practice case 1: Define the sampling unit
Setup: Start from the article’s White sandwich covariance worked mechanism for case 1. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 2: Fit the mean model
Setup: Start from the article’s White sandwich covariance worked mechanism for case 2. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 3: Save residuals
Setup: Start from the article’s White sandwich covariance worked mechanism for case 3. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 4: Build design rows
Setup: Start from the article’s White sandwich covariance worked mechanism for case 4. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 5: Square residuals
Setup: Start from the article’s White sandwich covariance worked mechanism for case 5. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 6: Form row outer products
Setup: Start from the article’s White sandwich covariance worked mechanism for case 6. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 7: Assemble the meat
Setup: Start from the article’s White sandwich covariance worked mechanism for case 7. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 8: Calculate the bread
Setup: Start from the article’s White sandwich covariance worked mechanism for case 8. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 9: Multiply the sandwich
Setup: Start from the article’s White sandwich covariance worked mechanism for case 9. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 10: Extract variances
Setup: Start from the article’s White sandwich covariance worked mechanism for case 10. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 11: Take square roots
Setup: Start from the article’s White sandwich covariance worked mechanism for case 11. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 12: Compare conventional SE
Setup: Start from the article’s White sandwich covariance worked mechanism for case 12. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 13: Plot residual spread
Setup: Start from the article’s White sandwich covariance worked mechanism for case 13. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 14: Run a variance diagnostic
Setup: Start from the article’s White sandwich covariance worked mechanism for case 14. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 15: Inspect leverage
Setup: Start from the article’s White sandwich covariance worked mechanism for case 15. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 16: Change variance pattern
Setup: Start from the article’s White sandwich covariance worked mechanism for case 16. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 17: Add an outlier
Setup: Start from the article’s White sandwich covariance worked mechanism for case 17. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 18: Try weighted least squares
Setup: Start from the article’s White sandwich covariance worked mechanism for case 18. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 19: Check prediction limits
Setup: Start from the article’s White sandwich covariance worked mechanism for case 19. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 20: Audit independence
Setup: Start from the article’s White sandwich covariance worked mechanism for case 20. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 21: Reject a causal shortcut
Setup: Start from the article’s White sandwich covariance worked mechanism for case 21. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 22: Reject an outlier-proof claim
Setup: Start from the article’s White sandwich covariance worked mechanism for case 22. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 23: Report both intervals
Setup: Start from the article’s White sandwich covariance worked mechanism for case 23. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 24: Name remaining assumptions
Setup: Start from the article’s White sandwich covariance worked mechanism for case 24. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 25: Write the conclusion
Setup: Start from the article’s White sandwich covariance worked mechanism for case 25. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.