Autocorrelation in Regression
Regression Analysis
When Residuals Are Not Independent
Autocorrelation in time-series regression inflates t-statistics and shrinks standard errors, leading to false confidence in predictors. Durbin-Watson tests and Newey-West corrections address this pervasive problem.
- Macroeconomics — Model GDP growth where errors correlate across quarters
- Energy Markets — Forecast demand where daily patterns create serial dependence
- Environmental Studies — Analyze pollution trends with temporally correlated residuals
Time-ordered data demands attention to the correlation structure hidden in residuals.
What You'll Learn
- 1Explain why serial correlation biases standard errors while leaving coefficients unbiased
- 2Compute the Durbin-Watson statistic by hand and read it against its critical bounds
- 3Distinguish Durbin-Watson, Breusch-Godfrey and the residual ACF plot by what each one detects
- 4Choose among Newey-West standard errors, Cochrane-Orcutt and lag augmentation for a given data-generating process
Autocorrelation means the residuals are correlated across time (or space). It violates the independence assumption and biases standard errors. Two observations of the same series a month apart usually share influences that never appear in your regressors — weather, policy inertia, measurement drift — and those shared influences land in the error term, where the ordinary least squares assumptions forbid them.
Where Serial Correlation Comes From
The independence assumption is the easiest of the classical assumptions to lose, because almost anything that generates a time series can break it.
- An omitted variable that moves slowly. If a trending or persistent driver is left out of the model, its effect is absorbed into the errors, and because the driver is persistent so are they.
- Wrong functional form. Fitting a straight line to a curved relationship leaves residuals that drift in blocks: negative for a while, then positive.
- Carrying dynamics forward. Two-day weather, inventory adjustment, and habit formation all make today's shock partly tomorrow's shock.
- Smoothing and aggregation. Rolling averages and interpolated series mechanically induce correlation between neighbours.
- Spatial and network effects. Neighbouring regions, adjacent grid cells, and connected users violate independence across space exactly the same way.
Correcting the statistic does not fix the underlying cause, so diagnosing autocorrelation should always trigger a question about which of these mechanisms is at work.
The AR(1) Error Model and What It Costs
The textbook case assumes the errors follow a first-order autoregressive process:
where is the autocorrelation coefficient and is white noise. When is positive, consecutive errors share a sign, and the true variance of an OLS coefficient can exceed the variance the regression reports. For a regressor that changes smoothly over time, the inflation factor is approximately
With , this is , so the honest standard error is about times the one printed by default. A reported t-statistic of 3.0 is really about 1.4 — below any conventional threshold. The coefficients themselves stay unbiased and consistent under standard conditions; it is only the inference that collapses. That asymmetry is what makes autocorrelation so easy to miss: the model still looks like it fits.
Detecting Serial Dependence
Three diagnostics answer overlapping questions, and a serious analysis uses all of them.
The Durbin-Watson statistic compares each residual with its predecessor:
Expanding the numerator shows why it works: it equals roughly , where is the lag-1 residual correlation. Values near 2 indicate independence, values near 0 strong positive autocorrelation, and values near 4 strong negative autocorrelation.
| Durbin-Watson value | Reading | Action |
|---|---|---|
| d close to 0 | Strong positive autocorrelation | Correct before trusting any t-statistic |
| d below dL | Significantly positive | Reject independence at the chosen level |
| Between dL and dU | Inconclusive region | No decision possible; run Breusch-Godfrey |
| Around 2 | Consistent with independence | Proceed, then confirm with the residual ACF |
| Between 2 minus dU and 2 | Inconclusive region | Run Breusch-Godfrey |
| d above 2 minus dL | Significantly negative | Look for differencing or over-correction |
The lower and upper critical bounds dL and dU depend on the sample size, the number of regressors, and the significance level, and they are tabulated rather than computed. The inconclusive zones are a real limitation: with modest samples the test often refuses to decide.
The Breusch-Godfrey test regresses the residuals on their own lags and on the original regressors, then tests whether the lag coefficients are jointly zero using an LM statistic with a chi-square reference distribution. Unlike Durbin-Watson it detects correlation beyond lag one and remains valid when a lagged dependent variable appears on the right-hand side.
The residual ACF plot shows the correlation at each lag with confidence bands at approximately . A single significant spike at lag one suggests an AR(1) error; a slowly decaying tail suggests a unit root or an omitted trend; a spike at lag 7 or 12 points to seasonality the model never represented.
A Worked Durbin-Watson Calculation
Consider the residuals from a regression fitted to 8 annual observations:
| t | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| e | 0.50 | 0.70 | 0.30 | 0.60 | 0.10 | 0.40 | -0.10 | 0.20 |
Step 1 — squared residuals. Their sum is .
Step 2 — squared first differences. The differences are 0.20, -0.40, 0.30, -0.50, 0.30, -0.50 and 0.30, whose squares sum to .
Step 3 — the ratio. .
Step 4 — read it. Since d is far below 1.5, the residuals are positively autocorrelated. Inverting the approximation, , which is strong dependence. Any confidence interval computed from the default standard errors is far too narrow; with the inflation factor of about 2.17 derived above, a nominal 95 percent interval behaves more like one covering only the central 65 percent.
Choosing a Correction
The right response depends on whether you care about the coefficients, the inference, or both.
| Method | Changes coefficients? | Fixes standard errors? | Best used when |
|---|---|---|---|
| Newey-West HAC | No | Yes | You want valid inference with minimal assumptions |
| Cochrane-Orcutt | Yes | Yes | You are confident the errors are AR(1) and want efficiency |
| Prais-Winsten | Yes | Yes | Same, but the first observation must be kept |
| Generalised least squares | Yes | Yes | The full error covariance structure is known or estimable |
| Add lagged dependent variable | Yes | Yes | The dependence reflects genuine dynamics, not just error correlation |
| Difference or de-trend the model | Yes | Yes | The autocorrelation came from misspecified functional form |
| Cluster-robust standard errors | No | Yes | Correlation has an arbitrary form within blocks you can identify |
Newey-West estimation, also called heteroskedasticity and autocorrelation consistent covariance, estimates the long-run variance of the score contributions and leaves the coefficients untouched. Its bandwidth, the number of lags included, grows slowly with sample size; a common default is , which is 4 lags at and 6 at . Too small a bandwidth leaves correlation uncorrected, too large throws away precision.
Cochrane-Orcutt iterates between estimating from the residuals and re-fitting the transformed model on similarly transformed regressors. It converges quickly but drops the first observation, which Prais-Winsten avoids by keeping it with a scaling.
Detection and Correction in Code
import numpy as np
import statsmodels.api as sm
from statsmodels.stats.stattools import durbin_watson
from statsmodels.stats.diagnostic import acorr_breusch_godfrey
from statsmodels.graphics.tsaplots import plot_acf
import matplotlib.pyplot as plt
rng = np.random.default_rng(42)
n = 120
t = np.arange(n)
rho = 0.65
# AR(1) errors
eps = np.zeros(n)
eps[0] = rng.normal()
for i in range(1, n):
eps[i] = rho * eps[i - 1] + rng.normal()
x = np.linspace(0, 10, n) + rng.normal(0, 0.4, n)
y = 2 + 1.5 * x + eps
ols = sm.OLS(y, sm.add_constant(x)).fit()
dw = durbin_watson(ols.resid)
print(f"Durbin-Watson d = {dw:.4f} -> rho ~ {1 - dw/2:.4f}")
print(f"t on x (naive) = {ols.tvalues['x1']:.3f}, p = {ols.pvalues['x1']:.4f}")
bg = acorr_breusch_godfrey(ols, nlags=3)
print(f"Breusch-Godfrey LM = {bg[0]:.3f}, p = {bg[1]:.4f}")
# Correction 1: Newey-West HAC, point estimates unchanged
hac = sm.OLS(y, sm.add_constant(x)).fit(cov_type='HAC',
cov_kwds={'maxlags': 4})
print(f"t on x (HAC) = {hac.tvalues['x1']:.3f}, SE {hac.bse['x1']:.4f}"
f" vs OLS {ols.bse['x1']:.4f}")
# Correction 2: Cochrane-Orcutt via iterated GLS
co = sm.OLS(y, sm.add_constant(x)).fit()
for _ in range(20):
r = co.resid
rho_hat = np.corrcoef(r[1:], r[:-1])[0, 1]
yt = y[1:] - rho_hat * y[:-1]
xt = sm.add_constant(x[1:] - rho_hat * x[:-1])
co = sm.OLS(yt, xt).fit()
print(f"rho hat = {rho_hat:.4f}, slope = {co.params['x1']:.4f}, "
f"t = {co.tvalues['x1']:.3f}")
fig, ax = plt.subplots(figsize=(9, 4))
ax.scatter(t, ols.resid, s=12, alpha=0.7, label="OLS residuals")
ax.axhline(0, color="red", ls="--")
ax.set_title("Residuals over time: blocks of shared sign signal autocorrelation")
plt.tight_layout(); plt.show()
plot_acf(ols.resid, lags=20, alpha=0.05)
plt.show()
fit <- lm(y ~ x)
dwtest(fit, alternative = "two.sided") # Durbin-Watson
bgtest(fit, order = 3) # Breusch-Godfrey
# Newey-West standard errors, coefficients untouched
coeftest(fit, vcov = NeweyWest(fit, lag = 4, prewhite = FALSE))
# Cochrane-Orcutt and Prais-Winsten
library(car)
co <- cochrane.orcutt(fit)
summary(co)
⚠️Never apply Durbin-Watson to a model with a lagged dependent variable
y at time t-1 appears among the regressors, the Durbin-Watson statistic is biased toward 2 and will understate the correlation. Use the Breusch-Godfrey LM test instead, which is valid in that setting.When the Correlation Is the Point, Not the Nuisance
Not every model with serial correlation is misspecified. In a forecasting model, today's error genuinely helps predict tomorrow's level, and the right response is to model that dependence explicitly with an autoregressive or ARIMA structure rather than to correct standard errors around a static equation. The dividing question is whether the correlation is a nuisance in the errors of a relationship you want to interpret, or the mechanism you are trying to estimate. Interpretable structural coefficients on slowly moving macroeconomic series usually want HAC inference; pure one-step-ahead forecasts usually want the dynamics in the mean equation.
Common Mistakes
Reporting naive t-statistics from time-series OLS
Fix: Estimate Newey-West HAC standard errors, or fit the error process explicitly, before drawing any inference.
Using Durbin-Watson when a lagged dependent variable is present
Fix: Switch to the Breusch-Godfrey LM test, which does not inherit that bias.
Correcting for autocorrelation without asking why it is there
Fix: Check for an omitted trending variable or wrong functional form first; the coefficient may be the thing that is wrong.
Choosing the HAC bandwidth by eye
Fix: Use a standard rule such as 4(T/100) to the power 2/9, and report the bandwidth you used.
Best Practices
- Plot residuals against time and their ACF before reading any regression table
- Report both the OLS and the corrected standard errors so readers can see the sensitivity
- State the number of HAC lags and the estimator name in the methods section
- Run a structural break check alongside autocorrelation tests on long macroeconomic samples
Key Takeaways
- Autocorrelation leaves coefficients unbiased but distorts their standard errors, usually making them too small
- Durbin-Watson equals about 2 times 1 minus the lag-1 residual correlation, so near 2 is good and near 0 is badly positive
- Durbin-Watson only tests lag one and has inconclusive regions; Breusch-Godfrey tests arbitrary order and handles lagged dependent variables
- Newey-West HAC fixes inference without touching coefficients, while Cochrane-Orcutt and Prais-Winsten change both
- The inflation factor (1+rho)/(1-rho) explains why a t-statistic of 3 can really be under 1.5
Interview Questions
Q1: Does autocorrelation bias the OLS coefficients?
No. Under exogeneity the estimators remain unbiased and consistent. What breaks is the estimated variance: the reported standard errors are wrong, typically too small under positive correlation, so t-statistics and confidence intervals are misleading.
Q2: How is Durbin-Watson related to the lag-1 residual correlation?
The statistic d equals the sum of squared first differences of the residuals over the sum of squared residuals, which approximates 2(1 - rho-hat). That is why 2 means no correlation, values below 2 mean positive correlation, and values above 2 mean negative correlation.
Q3: When do you prefer Newey-West over Cochrane-Orcutt?
When you want valid inference but do not want to assume a specific error process. Newey-West leaves the point estimates alone and is consistent for a broad class of dependence; Cochrane-Orcutt is more efficient if AR(1) is genuinely correct, and less trustworthy if it is not.
Q4: What does a slowly decaying residual ACF suggest?
Usually a unit root or an omitted trend rather than short-memory correlation. Differencing or adding a deterministic trend often removes it entirely, whereas an AR(1) correction would leave the deeper problem in place.
Frequently Asked Questions
How is autocorrelation different from multicollinearity?
They are unrelated problems. Autocorrelation concerns the errors being correlated across observations, which invalidates standard errors. Multicollinearity concerns the regressors being correlated with each other, which inflates coefficient variance and destabilises estimates. A model can suffer from either, both, or neither, and each has its own diagnostic.
Can clustered standard errors handle serial correlation?
Yes, if the clusters are the blocks within which correlation lives — quarters within a firm, years within a country. Clustering allows arbitrary correlation inside a cluster while assuming independence across clusters. When correlation spans cluster boundaries, as in a single continuous time series, there is only one cluster and the approach fails; use HAC instead.
Does adding more observations solve the problem?
No, and often the opposite. As the sample grows, the bias in the reported standard errors does not vanish, and with highly persistent errors the effective sample size grows far more slowly than n. Four hundred quarterly observations with carry less independent information than sixty independent observations.
Should I always difference the data before regressing?
Only if the variables are non-stationary. Differencing destroys long-run relationships and can turn a meaningful levels model into noise. If the series are stationary, correct the error covariance instead; if they are unit-root processes, a cointegration framework is preferable to blind differencing.