Tutorials › Regression Analysis (Undergraduate) › A Worked Heteroskedasticity Diagnostic

Unequal Variance and Robust Uncertainty · Tutorial 526 of 991

A Worked Heteroskedasticity Diagnostic

Follow a complete hypothetical regression diagnosis, from checking residual patterns to interpreting a variance test and deciding how to report uncertainty.

Advanced 9 min read

What You'll Learn

  • Inspect residuals against the predictor for systematic changes in spread.
  • State the assumptions behind the fitted regression and the Breusch–Pagan test.
  • Calculate the auxiliary-regression \(R^2\), LM statistic, degrees of freedom, and p-value.
  • Combine visual and test evidence without treating either as definitive.
  • Decide when the evidence supports using robust uncertainty estimates.

From a Residual Pattern to a Diagnostic Decision

A residual plot can suggest that the variability of outcomes changes with a predictor, but a visual impression is not a complete analysis. A variance test adds a numerical summary of evidence against constant variance. The useful diagnostic decision comes from considering both: the pattern in the plot and the test result, while checking that the regression mean model is plausible.

This tutorial works through a small hypothetical example using the Breusch–Pagan test. The aim is not to select a remedy automatically from a p-value. It is to decide whether the evidence gives reason to avoid relying only on conventional least-squares uncertainty estimates.

Model and assumptions: For observations \(i=1,\ldots,n\), consider \(Y_i=\beta_0+\beta_1x_i+\varepsilon_i\). The conditional mean is linear, \(E(\varepsilon_i\mid x_i)=0\), and observations are independent. Under the constant-variance null, \(\operatorname{Var}(\varepsilon_i\mid x_i)=\sigma^2\) for every \(i\). The Breusch–Pagan test’s usual chi-square reference is an approximation, conventionally justified under the null with normally distributed errors. The test does not check whether the mean model is correctly specified.

After fitting the line by least squares, the residual for observation \(i\) is \(\hat e_i=y_i-\hat y_i\). A residual-versus-predictor plot places \(x_i\) horizontally and \(\hat e_i\) vertically. If the mean model is adequate, residuals should fluctuate around zero without a systematic curve. Constant variance additionally implies that their vertical spread should be roughly similar across the predictor range. A widening or narrowing band is evidence to investigate, not proof by itself: a few unusual observations or a misspecified mean pattern can also affect the appearance.

A Worked Example: Reading the Residual Plot

Worked Example: A Widening Residual Band

Suppose a hypothetical data set has four observations at each of \(x=0,1,2,3,4\). The fitted regression line is \(\hat y=10+2x\). Within each group, the residuals are two copies of \(+a\) and two copies of \(-a\), where \(a\) is respectively \(1,1,2,3,4\).

\(x\)Fitted valueResiduals within groupSquared residual for each observation
010\(-1,-1,1,1\)1
112\(-1,-1,1,1\)1
214\(-2,-2,2,2\)4
316\(-3,-3,3,3\)9
418\(-4,-4,4,4\)16

The residuals are centered at zero within every \(x\) group, so this constructed example gives no group-level indication of a curved mean. Their magnitudes, however, grow from \(1\) at the low end to \(4\) at the high end. A residual plot would show a noticeably wider vertical band as \(x\) increases. That is the visual pattern expected when the error variance increases with \(x\).

The fitted line is consistent with the specified residuals: at each \(x\), their sum is zero, and hence both \(\sum_i\hat e_i=0\) and \(\sum_i x_i\hat e_i=0\). These are the least-squares residual orthogonality conditions for a regression with an intercept and one predictor. They help confirm that the example’s stated line and residuals agree.

Applying the Breusch–Pagan Test

The Breusch–Pagan test formalizes a particular question: do the squared residuals show a linear relationship with the predictor or predictors used to explain variance? For this example there is one predictor, \(x\). The auxiliary regression has an intercept and uses \(\hat e_i^2\) as its response. Its slope tests whether the squared residuals tend to change linearly with \(x\).

Definition: In the one-predictor Breusch–Pagan test, fit the auxiliary regression \(\hat e_i^2=\gamma_0+\gamma_1x_i+v_i\), and let \(R^2_{\text{aux}}\) be its coefficient of determination. The null hypothesis is \(H_0:\gamma_1=0\), corresponding to no linear relationship between squared residuals and \(x\); the alternative is \(H_a:\gamma_1\ne 0\). The test statistic is \(LM=nR^2_{\text{aux}}\). Under \(H_0\), it is compared approximately with a chi-square distribution with \(df=1\), the number of slope terms in the auxiliary regression.

The auxiliary regression is a diagnostic device, not a second model for the original outcome. A small p-value means that, if the constant-variance null and the test’s reference assumptions held, a statistic at least as large as the observed \(LM\) would be unusual. It does not give the probability that constant variance is true.

Worked Example: Calculating the Variance Test

Use the 20 observations in the preceding example. The squared residuals at \(x=0,1,2,3,4\) are \(1,1,4,9,16\), respectively, with each value repeated four times. Their overall mean is \[ \overline{\hat e^2}=\frac{4(1+1+4+9+16)}{20}=\frac{124}{20}=6.2. \]

Because the repeated values have equal counts, the least-squares auxiliary regression has the same coefficients as the regression through the five group values. Its slope and intercept are \[ \hat\gamma_1=\frac{\sum (x-\bar x)(\hat e^2-\overline{\hat e^2})}{\sum(x-\bar x)^2} =\frac{38}{10}=3.8,\qquad \hat\gamma_0=6.2-(3.8)(2)=-1.4. \] Thus the fitted auxiliary values are \(-1.4,2.4,6.2,10,13.8\). The residuals from this auxiliary regression, one per distinct \(x\) value, are \(2.4,-1.4,-2.2,-1,2.2\). In particular, the last is \(16-13.8=2.2\).

The auxiliary residual sum of squares, accounting for the four repetitions of each value, is \[ SSE_{\text{aux}}=4\left(2.4^2+(-1.4)^2+(-2.2)^2+(-1)^2+2.2^2\right) =4(18.4)=73.6. \] The total sum of squares for the auxiliary response is \[ SST_{\text{aux}}=4\left((1-6.2)^2+(1-6.2)^2+(4-6.2)^2+(9-6.2)^2+(16-6.2)^2\right)=651.2. \] Therefore, \[ R^2_{\text{aux}}=1-\frac{SSE_{\text{aux}}}{SST_{\text{aux}}} =1-\frac{73.6}{651.2}\approx 0.8870, \qquad LM=20(0.8870)\approx17.74. \]

With \(df=1\), the chi-square reference gives \(p\approx0.000025\). At significance level \(\alpha=0.05\), this is strong evidence against the constant-variance null in this example. The direction is also visible in the auxiliary slope: squared residuals tend to increase as \(x\) increases. This conclusion concerns evidence about variance, not proof that variance changes linearly at every value of \(x\).

Why the Test Uses \(nR^2_{\text{aux}}\)

The auxiliary regression compresses the relationship between squared residuals and the variance predictors into a single quantity, \(R^2_{\text{aux}}\). If those predictors explain little of the variation in squared residuals, this \(R^2\) is small; if they explain more, it is larger. Multiplying by the sample size gives the Lagrange multiplier statistic used by the test.

For the example, this calculation is \(20(0.8870)\approx17.74\). Under the null and the stated regularity conditions, the statistic has an approximate chi-square distribution with one degree of freedom. The reference distribution supplies the p-value; it is not a separate measure of how large or important the variance change is. This is why the diagnostic should retain the plot and the scale of the residuals as context.

A Worked Example: Turning Evidence Into a Decision

Worked Example: A Weaker Diagnostic Signal

Consider a second, hypothetical regression with \(n=24\) observations. Suppose its residual plot shows a roughly even band without an obvious systematic widening, and the fitted Breusch–Pagan auxiliary regression reports \(R^2_{\text{aux}}=0.018\). The test statistic is \[ LM=nR^2_{\text{aux}}=24(0.018)=0.432. \]

There is one slope term, so \(df=1\). Comparing \(0.432\) with a chi-square distribution on one degree of freedom gives \(p\approx0.511\). Since \(0.511>0.05\), this test does not provide evidence against constant variance at the 5% level. Together with the unremarkable residual plot, that result offers no particular warning about changing spread in this example.

It would still be incorrect to conclude that the variance has been proved constant. A test can fail to detect a departure, especially when the sample is small or the pattern is not well represented by the chosen auxiliary predictors. If uncertainty estimates are especially consequential, analysts may examine sensitivity to robust uncertainty estimates even without a small p-value. The diagnostic result informs that decision; it does not dictate it.

Combining Visual and Numerical Evidence

The first example gives mutually reinforcing evidence: the residual plot widens with \(x\), and the test strongly rejects its constant-variance null. The second gives no clear visual or test signal. In an actual analysis the two sources may disagree. A plot can reveal a nonlinear spread pattern that a simple linear variance test misses, while a small p-value can reflect a detectable but practically minor pattern in a large sample.

A responsible report therefore names the diagnostic, states the observed pattern, and describes the decision without overstating it. For example: “The residual spread increased across the predictor range, and the Breusch–Pagan test gave \(LM=17.74\), \(df=1\), \(p\approx0.000025\); we therefore report robust uncertainty estimates as a sensitivity to the constant-variance assumption.” This does not claim the test proves a specific variance function or that the regression mean is correct.

Robust uncertainty estimates address uncertainty calculations under unequal variance; they do not repair a curved or otherwise misspecified mean relationship. If the residual plot also has a systematic curve, that issue needs separate attention. Nor does a variance test establish independence or rule out influential observations. These checks remain part of the broader regression diagnosis.

Common Mistakes and a Practical Sequence

  • Reading a funnel as proof. A widening plot suggests unequal spread, but it can also be affected by outliers or mean-model problems. Describe the pattern as evidence, then check the model and use a variance test where appropriate.
  • Treating a large p-value as proof of equal variance. A non-small p-value means the test did not find sufficient evidence against its null; it does not show that the null is true.
  • Reporting the wrong degrees of freedom. For the stated test, \(df\) is the number of slope terms in the auxiliary regression. With one predictor, \(df=1\), not the residual degrees of freedom from the original regression.
  • Confusing the variance diagnostic with a mean-model check. A squared-residual regression tests a feature of spread. It does not test whether the original conditional mean is linear.
  • Using a significance decision without context. A p-value does not measure the size or practical importance of a variance change. Pair it with the residual plot and the consequences of uncertainty for the analysis.
1
Check the mean pattern.
Look for systematic curvature or another structure in residuals before interpreting spread.
2
Inspect residual spread.
Describe whether the vertical residual band appears stable, widening, or narrowing across the predictor range.
3
Run and report the variance test.
Give the test statistic, degrees of freedom, p-value, and significance level, and interpret them in context.
4
Make a measured uncertainty decision.
Combine the plot and test evidence, and consider robust uncertainty estimates when unequal variance is a credible concern.
Key takeaway: A sound heteroskedasticity diagnosis is not a p-value alone. Check the mean pattern, inspect residual spread, use a variance test with its assumptions stated, and let the combined evidence guide how uncertainty is reported.

Check Your Understanding

Use the definitions and worked calculations above to answer these questions.

  1. In the first example, what feature of the residual plot suggests unequal variance, and why does centering around zero not rule it out?
  2. For the one-predictor Breusch–Pagan test, what determines the degrees of freedom of the chi-square reference distribution?
  3. Explain why \(p\approx0.000025\) in the first example is not the probability that the constant-variance null is true.
  4. What is the corrected auxiliary residual at \(x=4\), and how does it contribute to \(SSE_{\text{aux}}\)?
  5. If a residual plot shows curvature but a variance test is not significant, what concern remains that robust uncertainty estimates alone would not fix?