← All resources

Heteroscedasticity Fixes: Robust SEs, WLS, Transformations

13 min read
Heteroscedasticity Fixes: Robust SEs, WLS, Transformations

Heteroscedasticity Fixes: Robust SEs, WLS, Transformations

Fan-shaped residuals around a fitted regression line

For most regression work, the fix for heteroscedasticity is to keep your OLS coefficients and repair the inference: report heteroscedasticity-consistent (robust) standard errors, with HC3 as the usual default in small and moderate samples. Use weighted least squares only when you can defend a model for the variance, and transform the outcome only when the transformed scale makes scientific sense. This guide shows how to choose, how to run each fix in R, and how to document the choice so a reviewer or supervisor can reproduce it. Doing this as a planned, reviewable analysis is what we built agentic analytics for researchers to support in PlotStudio AI.

Plotstudio
plotstudio.ai
Make Your Regression Fix Reproducible
PlotStudio AI plans research analyses, runs Python and R code, and keeps methods, outputs, and results available for review.
Visit

TL;DR

  • Heteroscedasticity leaves OLS coefficients unbiased but makes the usual standard errors wrong, usually too small, so p-values look better than they should.
  • Default fix: OLS with HC3 robust standard errors. It needs no model of the variance.
  • Use WLS or feasible GLS only if the variance structure is known or well justified. With wrong weights, you can lose efficiency and get wrong standard errors again.
  • Transformations (such as logs) can stabilize variance but change what the coefficients mean.
  • Whatever you choose, record the diagnostic, the remedy and the code so the result can be reproduced.

Table of Contents

What heteroscedasticity does to your results

The OLS assumption is that the error variance is constant across observations. Heteroscedasticity means it is not: the variance of the errors changes with the regressors. A classic example is income and spending, where high earners vary far more in how much they spend than low earners do.

The damage is specific. With E[u|x]=0 intact, OLS coefficients remain unbiased, but the estimated standard error is wrong, so confidence intervals and hypothesis tests cannot be relied on. When errors are more variable at high or low predictor values, OLS standard errors tend to be underestimated, giving intervals that are too narrow and p-values that are too small. The same paper reports that more data does not make this go away.

How bad can it get? In a 2025 simulation with 10,000 samples per scenario and sample sizes from 25 to 500, classical inference showed Type I error rates as high as 26% when the variance was tied to the predictor of interest, regardless of sample size. The same study found that when the variance depends on a different, correlated predictor, the Type I error rate stays close to the nominal 5%, although power is still reduced.

Type I error rates across two variance scenarios

So the problem is mostly one of inference, not of the fitted line. That framing decides which fix you reach for.

Step 1: Confirm it before you fix it

Start with the residuals against the fitted values. A funnel or fan shape, with the spread widening as fitted values grow, is the pattern to look for. Then, if you want a formal check, pick one test in advance.

Test What it does Watch for
Breusch-Pagan Regresses squared residuals on the regressors only Assumes normal errors; Koenker’s studentized variant controls Type I error better under heavy tails
White Adds squares and cross-products of the regressors, with nR² asymptotically chi-squared under the null Many terms when you have many predictors
car::ncvTest Tests variance against fitted values or chosen predictors In one worked example, testing against fitted values and against a different variable gave opposite conclusions

Two cautions apply. First, formal tests flag trivial deviations in large samples and can miss consequential ones in small samples, so read the plot as well as the p-value. Second, do not chain Goldfeld-Quandt, then Breusch-Pagan, then White and report whichever rejects first. That amounts to p-hacking. Choose one test from prior suspicion, or skip testing and report robust standard errors by default, which is common modern practice.

For the full diagnostic walkthrough with code, see our guide to heteroscedasticity in regression. If you want the reference point, what homoscedasticity is and why it matters covers the assumption itself.

Fix 1: Robust standard errors (the default)

Heteroscedasticity-consistent standard errors keep your OLS estimates and replace only the variance estimate. They need no knowledge of the functional form of the variance, no transformation of Y and no simulation. The trade-off, per the same authors, is that they are not a panacea and have larger sampling variability than a correctly specified WLS or GLS.

The variants differ in how they correct the squared residuals. In the sandwich package documentation:

  • HC0 uses the squared residuals directly (White, 1980).
  • HC1 scales by n/(n-k).
  • HC2 divides by 1-h, where h is the observation’s leverage.
  • HC3 divides by (1-h) squared. It performs best in small samples and is the default in vcovHC.
  • HC4 uses a leverage-dependent exponent, aimed at data with high-leverage points.

Which to report? HC0 is downwardly biased in small to moderate samples, and HC3 is recommended when the sample is under 250. In the 2025 simulations, HC3 and HC4 behaved very similarly, with HC4 slightly closer to the simulated standard error in small samples. The same study advised against using a bootstrap as the default in small samples.

In R:

library(sandwich)
library(lmtest)

mod <- lm(y ~ x1 + x2, data = d)
coeftest(mod, vcov = vcovHC(mod, type = "HC3"))

The point estimates are identical to plain OLS. Only the standard errors, t-statistics and p-values change. A useful habit is to report both and look at the ratio. In a worked R lab on 120 households, the income slope’s standard error moved from 0.0296 under OLS to 0.0314 under HC1, a ratio of about 1.06, with the point estimate unchanged. A ratio that large would not change a conclusion. A ratio well above that tells you the classical p-values were over-rejecting.

Robust standard errors are not a guarantee either. Recent theory work shows that conventional critical values for heteroskedasticity-robust tests can still produce severe size distortions in difficult designs. With a small sample and a few high-leverage points, prefer HC3 or HC4 over HC0 or HC1. More on this in our robust standard errors guide.

Fix 2: Weighted or feasible generalized least squares

WLS goes further than repairing the standard errors: it uses the variance structure to get a more efficient estimator. If Var(u|x) = σ²h(x), you divide the regression by √h(x), which gives weights of 1/h(x). With correctly specified weights, WLS is BLUE and has smaller standard errors than OLS.

The catch is the word “correctly”. Feasible GLS estimates the variance function from the data. A reproducible workflow from a University of Chicago methods companion fits OLS, regresses log(residuals²) on x, sets the weights to 1/exp(fitted values) and refits. In a 2,000-iteration simulation, this cut the slope’s sampling standard deviation from 0.0841 to 0.0687, an efficiency gain of 1.23. The same source warns that the gain holds only if the variance model is right. If it is wrong, estimates stay consistent but may be less efficient than OLS, and the reported standard errors may be wrong.

ols <- lm(y ~ x, data = d)
d$w <- 1 / exp(fitted(lm(log(resid(ols)^2) ~ x, data = d)))
wls <- lm(y ~ x, data = d, weights = w)

A practical decision rule, from the same econometrics course notes used above:

  1. Variance structure known and trustworthy (for example, each observation is a group mean of known size): WLS.
  2. Structure unknown: OLS with robust standard errors.
  3. In doubt: robust standard errors.

Base the choice on subject knowledge, not on a test run on the same data. If you do use WLS, a common safeguard is to report robust standard errors on the weighted fit too, so a misjudged weight does not silently invalidate your intervals.

Fix 3: Transform the outcome or respecify the model

Sometimes the variance problem is a symptom of the model. A skewed, strictly positive outcome such as costs, concentrations or lengths of stay often has variance that grows with its mean. Logging the outcome can stabilize the spread and reduce skew. Omitted variables, a missing interaction or an unmodelled nonlinearity can also produce fan-shaped residuals, so check the specification before you transform anything.

The trade-off is interpretation. One applied econometrics study found that log transformations can help with heteroskedasticity, but they alter coefficient interpretation, a trade-off between statistical robustness and economic meaning. A coefficient on a logged outcome is roughly a percentage change, not a unit change, and back-transforming predictions needs care. If your clinical or policy question is about absolute differences, a transformed model may answer a different question than the one your reviewer cares about.

Two further options are worth knowing:

  • A different model family. A generalized linear model with a variance function suited to the outcome (counts, positive skewed data) builds the non-constant variance into the model instead of fighting it. The Wisconsin regression diagnostics guide lists modifying the model, fitting a GLM or running WLS as ways to address violations.
  • Modelled variance and correlation structures. In mixed or longitudinal data, variance functions and correlation structures in the model can handle heteroscedasticity and autocorrelation together. For panel designs with unit effects, see our note on fixed effects regression.

Which fix for which situation

Situation Reasonable fix
Cross-sectional regression, variance structure unknown OLS with HC3
Small sample or high-leverage points HC3 or HC4; avoid a default bootstrap
Known grouping or variance proportional to a variable WLS, with robust SEs as a safeguard
Skewed positive outcome, ratio-scale question Log transform or GLM, with interpretation stated
Fan pattern disappears after adding a term Respecify the model
Repeated measures with correlated errors Mixed model with variance and correlation structure

Reporting the fix so it survives review

A reviewer asking for method justification wants three things: the diagnostic you used, the remedy you chose and why, and evidence the remedy worked. A three-step process from the applied literature fits this: fit a theory-based model and save residuals, analyze the residuals, then make inferences about the parameters.

In practice, write down:

  1. The residual plot and the single pre-chosen test, with its statistic and p-value.
  2. The remedy and the reason (for example, “variance structure unknown, so OLS with HC3”).
  3. OLS and robust standard errors side by side, so readers see what changed.
  4. For WLS, a re-test of the residuals. In the lab cited earlier, a Breusch-Pagan re-test after weighting gave p=0.9237.
  5. The package versions and the script, so a supervisor can rerun it and get the same numbers.

R packages such as lmtest, estimatr and hcci cover the Breusch-Pagan test, robust standard errors via lm_robust and the wild bootstrap respectively, which makes each step scriptable.

Where PlotStudio AI fits

R, Python, SPSS, SAS and Jupyter give you the statistical computing. PlotStudio AI adds an agentic layer on top: specialized agents plan an investigation, write and run real code, inspect intermediate results and synthesize the findings into a reproducible analysis. It does not replace those tools.

For a heteroscedasticity workflow, that maps onto the steps above. With Plan Mode you can review and modify the proposed analytical approach, including methods and assumptions, before anything executes, so you decide whether the plan uses HC3, WLS or a transformation. PlotStudio AI supports Python and R workflows, can run analyses locally on your machine for privacy-sensitive data, and preserves completed work as searchable Analysis Pages that export to notebooks and PDF reports. Skills let a lab encode its own statistical conventions, for example “report robust standard errors alongside OLS”, so every analysis follows the same rule.

There is a free trial, and the Bring Your Own Key plan is $39.99 per month, or $399.90 per year on the academic plan. Managed Credits is $69.99 per month. Details are on the pricing page.

Plotstudio

Our perspective

Most heteroscedasticity problems are not hard statistically. The remedy is a few lines of R. What goes wrong is the paper trail: the diagnostic someone ran at 11 p.m., the weights nobody can explain, the standard errors that changed between drafts.

We built PlotStudio AI as agentic analytics for researchers because a defensible analysis is a sequence of decisions, not a single output. Plan Mode puts the method and its assumptions in front of you before code runs. The code, statistics and charts stay attached to the result, so a supervisor or reviewer can see how each number was produced.

We see it as a layer in the modern research toolkit alongside R, Python, SPSS, SAS and Jupyter. Those tools compute. An agentic layer can plan, execute, inspect and document the whole analysis, including the unglamorous step of showing that the fix worked.

Aymen

FAQ

Does heteroscedasticity bias my regression coefficients?

No. If the errors have zero conditional mean, OLS coefficients stay unbiased and consistent. What breaks is the standard error, and with it the t-statistics, p-values and confidence intervals. OLS also stops being the most efficient linear estimator.

Should I test for heteroscedasticity or just use robust standard errors?

Either is defensible. Testing is useful for diagnosing a model problem, but tests are sensitive to sample size and chaining several of them invites p-hacking. Many applied researchers report robust standard errors by default and show the residual plot.

Which robust standard error should I use, HC1 or HC3?

For small and moderate samples, HC3 is the usual choice and is the default in R’s vcovHC. HC1 mainly applies a degrees-of-freedom correction and can be too liberal in small samples. With high-leverage observations, HC4 is worth comparing.

When is WLS better than robust standard errors?

When you know, from the design or subject matter, how the variance behaves, for example when each row is an average over a known number of units. Then correctly specified weights give smaller standard errors. If you only have a vague idea of the variance structure, robust standard errors are the safer route.

Sources