10 Autocorrelated Errors
One of the assumptions of Section 1.5 is that the errors are uncorrelated, \(Cov(\varepsilon_i,\varepsilon_j)=0\) for \(i\neq j\). This assumption is often violated when the data are collected in sequence over time (time series data: annual yields, monthly prices, daily weather) or over space (adjacent field plots). Correlation between errors in successive observations is called autocorrelation or serial correlation (Montgomery, Peck, and Vining 2021; Gujarati and Porter 2009; Koutsoyiannis 1977).
10.1 Sources of autocorrelation
- Omitted variables that themselves change slowly over time, such as technology, irrigation development or price trends. Their effect enters the error and makes successive errors similar. This is the most common cause in agricultural time series.
- Wrong functional form, such as fitting a straight line to a curved trend, which produces runs of residuals of the same sign.
- Inertia in economic and biological systems: a good year for coconut palms affects the nut set of the next year.
- Spatial correlation: neighbouring plots share soil fertility, so plot errors are correlated in the direction of the fertility gradient.
- Data manipulation: interpolation, smoothing or averaging of time series.
10.2 The first order autoregressive error model
The simplest and most widely used model for autocorrelated errors is
\[y_t=\beta_0+\beta_1x_t+\varepsilon_t,\qquad \varepsilon_t=\rho\,\varepsilon_{t-1}+a_t,\qquad |\rho|<1, \tag{10.1}\]
where \(a_t\sim\text{iid }N(0,\sigma_a^2)\) and \(\rho\) is the autocorrelation coefficient. Then
\[E(\varepsilon_t)=0,\qquad V(\varepsilon_t)=\frac{\sigma_a^2}{1-\rho^2},\qquad Cov(\varepsilon_t,\varepsilon_{t-s})=\rho^s\frac{\sigma_a^2}{1-\rho^2},\qquad Corr(\varepsilon_t,\varepsilon_{t-s})=\rho^s.\]
The covariance matrix of \(\boldsymbol\varepsilon\) is \(\sigma^2\mathbf V\) with \(V_{ts}=\rho^{|t-s|}\), not \(\sigma^2\mathbf I\).
10.3 Consequences of autocorrelation for OLS
- The OLS estimators remain unbiased (unbiasedness needs only \(E(\boldsymbol\varepsilon)=\mathbf 0\)), but they are no longer BLUE: the Gauss–Markov conditions fail.
- The true covariance matrix is \(V(\hat{\boldsymbol\beta})=\sigma^2(\mathbf X'\mathbf X)^{-1}\mathbf X'\mathbf V\mathbf X(\mathbf X'\mathbf X)^{-1}\), not \(\sigma^2(\mathbf X'\mathbf X)^{-1}\). With positive autocorrelation and a trending regressor, the usual formula underestimates the standard errors.
- \(MS_{Res}\) underestimates \(\sigma^2\), so \(t\) and \(F\) statistics are inflated, confidence intervals are too narrow, and regressors appear significant when they are not (spurious regression).
- \(R^2\) is often misleadingly high.
10.4 Detecting autocorrelation
Graphical methods
Plot the residuals \(e_t\) against time \(t\). With positive autocorrelation, residuals tend to be followed by residuals of the same sign, producing long runs above and below zero. With negative autocorrelation, residuals alternate in sign. A plot of \(e_t\) against \(e_{t-1}\) shows a positive or negative trend.
Runs test
Count the number of runs (sequences of residuals of the same sign). Too few runs indicate positive autocorrelation; too many indicate negative autocorrelation. For \(n_1\) positive and \(n_2\) negative residuals, the number of runs \(R\) has mean \(\frac{2n_1n_2}{n_1+n_2}+1\) under randomness.
10.4.1 The Durbin–Watson test
Durbin and Watson (Durbin and Watson 1950) proposed the statistic
\[d=\frac{\sum_{t=2}^n(e_t-e_{t-1})^2}{\sum_{t=1}^ne_t^2} \tag{10.2}\]
for testing \(H_0:\rho=0\) against \(H_1:\rho>0\) in the model Equation 10.1. Expanding the numerator,
\[d=\frac{\sum e_t^2+\sum e_{t-1}^2-2\sum e_te_{t-1}}{\sum e_t^2}\approx2(1-\hat\rho),\qquad \hat\rho=\frac{\sum_{t=2}^ne_te_{t-1}}{\sum_{t=1}^ne_t^2}. \tag{10.3}\]
Since \(-1\le\hat\rho\le1\), \(0\le d\le4\):
- \(d\approx2\): no autocorrelation (\(\hat\rho\approx0\));
- \(d\to0\): strong positive autocorrelation (\(\hat\rho\to1\));
- \(d\to4\): strong negative autocorrelation (\(\hat\rho\to-1\)).
The exact distribution of \(d\) depends on \(\mathbf X\), but Durbin and Watson showed that it lies between two bounding distributions with critical values \(d_L\) and \(d_U\) that depend only on \(n\), the number of regressors \(k\) and \(\alpha\). The decision rule is:
| Value of \(d\) | Decision |
|---|---|
| \(0<d<d_L\) | Reject \(H_0\): positive autocorrelation |
| \(d_L\le d\le d_U\) | Inconclusive |
| \(d_U<d<4-d_U\) | Do not reject \(H_0\): no autocorrelation |
| \(4-d_U\le d\le4-d_L\) | Inconclusive |
| \(4-d_L<d<4\) | Reject \(H_0\): negative autocorrelation |
| \(n\) | \(k=1\): \(d_L\) | \(k=1\): \(d_U\) | \(k=2\): \(d_L\) | \(k=2\): \(d_U\) | \(k=3\): \(d_L\) | \(k=3\): \(d_U\) |
|---|---|---|---|---|---|---|
| 15 | 1.08 | 1.36 | 0.95 | 1.54 | 0.82 | 1.75 |
| 20 | 1.20 | 1.41 | 1.10 | 1.54 | 1.00 | 1.68 |
| 25 | 1.29 | 1.45 | 1.21 | 1.55 | 1.12 | 1.66 |
| 30 | 1.35 | 1.49 | 1.28 | 1.57 | 1.21 | 1.65 |
| 40 | 1.44 | 1.54 | 1.39 | 1.60 | 1.34 | 1.66 |
| 50 | 1.50 | 1.59 | 1.46 | 1.63 | 1.42 | 1.67 |
Limitations of the Durbin–Watson test
- It has an inconclusive region (modern software computes exact \(p\)-values, removing this problem).
- It tests only first order autocorrelation.
- The model must contain an intercept, and it is invalid when a lagged dependent variable (\(y_{t-1}\)) is a regressor; Durbin’s \(h\) test or the Breusch–Godfrey LM test is then used.
Example 10.1 Annual coconut yield (nuts/palm) and rainfall (mm) at a research station for 1995–2024 are in csv/coconut.csv. Fit the regression of yield on rainfall and test for autocorrelation.
Solution
The OLS fit is \(\widehat{\text{nuts}}=20.034+0.01172\,\text{rainfall}\) with \(R^2=0.690\). From the residuals, \(\sum(e_t-e_{t-1})^2=202.873\) and \(\sum e_t^2=235.791\), so by Equation 10.2
\[d=\frac{202.873}{235.791}=0.860,\qquad \hat\rho=0.544.\]
With \(n=30\), \(k=1\), \(d_L=1.35\) and \(d_U=1.49\) at 5%. Since \(d=0.860<d_L\), \(H_0\) is rejected: the errors are positively autocorrelated. The time plot of residuals (Figure 10.1) shows long runs of positive and negative residuals.
10.5 Removing autocorrelation by transformation
If \(\rho\) were known, the model Equation 10.1 could be transformed to one with uncorrelated errors. Lag the model by one period and multiply by \(\rho\):
\[\rho y_{t-1}=\rho\beta_0+\rho\beta_1x_{t-1}+\rho\varepsilon_{t-1}.\]
Subtracting from \(y_t=\beta_0+\beta_1x_t+\varepsilon_t\):
\[\underbrace{y_t-\rho y_{t-1}}_{y_t'}=\underbrace{\beta_0(1-\rho)}_{\beta_0'}+\beta_1\underbrace{(x_t-\rho x_{t-1})}_{x_t'}+\underbrace{\varepsilon_t-\rho\varepsilon_{t-1}}_{a_t}. \tag{10.4}\]
The transformed model \(y_t'=\beta_0'+\beta_1x_t'+a_t\) has uncorrelated errors, so OLS on the transformed variables (generalized differencing) gives BLUE. The original intercept is recovered as \(\hat\beta_0=\hat\beta_0'/(1-\rho)\), and \(SE(\hat\beta_0)=SE(\hat\beta_0')/(1-\rho)\). One observation is lost; the Prais–Winsten transformation keeps it by using \(y_1'=\sqrt{1-\rho^2}\,y_1\), \(x_1'=\sqrt{1-\rho^2}\,x_1\). This is a special case of generalized least squares (Chapter 12).
If \(\rho\approx1\) (for example \(d\) close to 0), the first difference model \(y_t-y_{t-1}=\beta_1(x_t-x_{t-1})+a_t\) (through the origin) is used.
10.5.1 The Cochrane–Orcutt iterative procedure
Since \(\rho\) is unknown, it is estimated (Cochrane and Orcutt 1949):
- Fit the model by OLS and obtain the residuals \(e_t\).
- Estimate \(\rho\) by \(\hat\rho=\sum e_te_{t-1}/\sum e_{t-1}^2\) (or from \(d\): \(\hat\rho\approx1-d/2\)).
- Form \(y_t'=y_t-\hat\rho y_{t-1}\), \(x_t'=x_t-\hat\rho x_{t-1}\) and fit \(y_t'=\beta_0'+\beta_1x_t'+a_t\) by OLS.
- Compute new residuals from the original model \(e_t=y_t-\hat\beta_0-\hat\beta_1x_t\) with \(\hat\beta_0=\hat\beta_0'/(1-\hat\rho)\), re-estimate \(\rho\), and repeat steps 3–4 until \(\hat\rho\) converges.
- Apply the Durbin–Watson test to the residuals of the final transformed model.
Example 10.2 Apply the Cochrane–Orcutt procedure to the coconut data of Example 10.1.
Solution
Starting from \(\hat\rho=0.544\), the iterations are shown in Table 10.3.
| Iteration | \(\hat\rho\) | \(\hat\beta_0\) | \(\hat\beta_1\) |
|---|---|---|---|
| 1 | 0.5436 | 21.596 | 0.01119 |
| 2 | 0.5778 | 21.649 | 0.01117 |
| 3 | 0.5780 | 21.649 | 0.01117 |
At convergence \(\hat\rho=0.5780\) and the model is
\[\widehat{\text{nuts}}=21.649+0.01117\,\text{rainfall}.\]
The Durbin–Watson statistic of the transformed model is \(d=2.008\), which now exceeds \(d_U=1.49\) (\(n=29\)), so the autocorrelation has been removed. The standard error of the rainfall coefficient is 0.00117 in the transformed model against 0.00149 from OLS. The OLS value rests on the false assumption of independent errors and cannot be trusted; the Cochrane–Orcutt estimate is the efficient one. (Here rainfall itself shows no trend, so the OLS standard error happens to be conservative; with a trending regressor it would usually be too small.)
Before transforming, ask why the errors are autocorrelated. Very often autocorrelation is a symptom of an omitted variable (such as a time trend reflecting new varieties and management) or of a wrong functional form. Adding the missing regressor removes the autocorrelation and gives a more meaningful model than a mechanical transformation.
10.6 R practical
cc <- read.csv("csv/coconut.csv")
fit <- lm(nuts ~ rainfall, data = cc)
lmtest::dwtest(fit) # Durbin-Watson test with p-value#>
#> Durbin-Watson test
#>
#> data: fit
#> DW = 0.8604, p-value = 0.0001915
#> alternative hypothesis: true autocorrelation is greater than 0
lmtest::bgtest(fit, order = 2) # Breusch-Godfrey test up to lag 2#>
#> Breusch-Godfrey test for serial correlation of order up to 2
#>
#> data: fit
#> LM test = 9.4872, df = 2, p-value = 0.008707
acf(resid(fit), main = "ACF of OLS residuals")
# Cochrane-Orcutt by hand
n <- nrow(cc); e <- resid(fit)
rho <- sum(e[-1] * e[-n]) / sum(e[-n]^2)
for (i in 1:50) {
ys <- cc$nuts[-1] - rho * cc$nuts[-n]
xs <- cc$rainfall[-1] - rho * cc$rainfall[-n]
ft <- lm(ys ~ xs)
b0 <- coef(ft)[1] / (1 - rho); b1 <- coef(ft)[2]
u <- cc$nuts - b0 - b1 * cc$rainfall
rnew <- sum(u[-1] * u[-n]) / sum(u[-n]^2)
if (abs(rnew - rho) < 1e-6) break
rho <- rnew
}
c(rho = rho, b0 = unname(b0), b1 = unname(b1))#> rho b0 b1
#> 0.57799206 21.64934973 0.01117211
lmtest::dwtest(ft)#>
#> Durbin-Watson test
#>
#> data: ft
#> DW = 2.0078, p-value = 0.5522
#> alternative hypothesis: true autocorrelation is greater than 0
# Generalized least squares with AR(1) errors (maximum likelihood)
library(nlme)
summary(gls(nuts ~ rainfall, data = cc, correlation = corAR1(form = ~ year)))$tTable#> Value Std.Error t-value p-value
#> (Intercept) 21.64434316 3.371911833 6.419012 5.97193e-07
#> rainfall 0.01123087 0.001123895 9.992818 9.77868e-11
Durbin, Watson and the bounds test
James Durbin and Geoffrey Watson developed their test at the Department of Applied Economics in Cambridge in 1950–51 (Durbin and Watson 1950). The exact distribution of \(d\) depends on the regressors, which made tabulation impossible with the computing power of the time, so they derived upper and lower bounds that hold for every \(\mathbf X\), accepting an inconclusive zone as the price of a usable table. Donald Cochrane and Guy Orcutt, also at Cambridge, had shown in 1949 that autocorrelated errors were common in economic relationships and proposed the transformation that bears their names (Cochrane and Orcutt 1949).
“Prediction is very difficult, especially about the future.”
- Niels Bohr
10.7 Practical exercises
10.7.1 Practical 10.1: Durbin–Watson test from residuals
A regression of annual black pepper production on area for 15 years (\(k=1\)) gave the residuals below (in time order). Compute the Durbin–Watson statistic, estimate \(\rho\), and test for autocorrelation at 5%.
| \(t\) | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| \(e_t\) | 1.2 | 0.8 | 1.5 | 0.9 | -0.2 | -0.8 | -1.1 | -0.6 | 0.3 | 0.7 | 1.0 | 0.4 | -0.5 | -1.2 | -0.9 |
Solution
\(\sum_{t=2}^{15}(e_t-e_{t-1})^2=5.73\) and \(\sum e_t^2=11.63\). By Equation 10.2,
\[d=\frac{5.73}{11.63}=0.493,\qquad \hat\rho=\frac{\sum e_te_{t-1}}{\sum e_t^2}=0.657\approx1-\frac d2=0.754.\]
From Table 10.2, for \(n=15\), \(k=1\): \(d_L=1.08\), \(d_U=1.36\). Since \(d=0.493<1.08\), \(H_0:\rho=0\) is rejected: the errors are positively autocorrelated, as the long runs of same-signed residuals suggest.
Doing it in R
e <- c(1.2, 0.8, 1.5, 0.9, -0.2, -0.8, -1.1, -0.6, 0.3, 0.7, 1.0, 0.4, -0.5, -1.2, -0.9)
d <- sum(diff(e)^2) / sum(e^2)
rho <- sum(e[-1] * e[-length(e)]) / sum(e^2)
c(d = d, rho = rho, approx_rho = 1 - d / 2)#> d rho approx_rho
#> 0.4926913 0.6569218 0.7536543
sum(diff(sign(e)) != 0) + 1 # number of runs#> [1] 4
plot(e, type = "b", pch = 19, xlab = "Year", ylab = "Residual"); abline(h = 0, lty = 2)
# With the original data, lmtest::dwtest(model) gives the exact p-value10.7.2 Practical 10.2: Removing autocorrelation by generalized differencing
Using \(\hat\rho=0.6\), transform the following series of yield (\(y_t\)) and rainfall (\(x_t\)) and fit the transformed regression. Recover the original intercept.
| \(t\) | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| \(y_t\) | 20 | 23 | 25 | 24 | 27 | 30 | 31 | 33 |
| \(x_t\) | 10 | 12 | 13 | 12 | 14 | 16 | 16 | 18 |
Solution
By Equation 10.4, \(y_t'=y_t-0.6y_{t-1}\) and \(x_t'=x_t-0.6x_{t-1}\), giving \(y'=(11.0,\ 11.2,\ 9.0,\ 12.6,\ 13.8,\ 13.0,\ 14.4)\) and \(x'=(6.0,\ 5.8,\ 4.2,\ 6.8,\ 7.6,\ 6.4,\ 8.4)\) (\(n=7\)). OLS on the transformed data gives \(\hat y'=3.510+1.3370x'\). The slope estimates \(\beta_1\) directly; the original intercept is \(\hat\beta_0=3.510/(1-0.6)=8.774\).
Doing it in R
yt <- c(20, 23, 25, 24, 27, 30, 31, 33); xt <- c(10, 12, 13, 12, 14, 16, 16, 18)
rho <- 0.6; n <- length(yt)
ys <- yt[-1] - rho * yt[-n]; xs <- xt[-1] - rho * xt[-n]
ft <- lm(ys ~ xs)
c(beta0 = unname(coef(ft)[1] / (1 - rho)), beta1 = unname(coef(ft)[2]))#> beta0 beta1
#> 8.774295 1.336991
lmtest::dwtest(ft)#>
#> Durbin-Watson test
#>
#> data: ft
#> DW = 1.9323, p-value = 0.3963
#> alternative hypothesis: true autocorrelation is greater than 0
10.8 Chapter Summary
Fill in the blanks
Answers are given at the end of the chapter.
Correlation between successive errors is called __________.
In the AR(1) model, \(\varepsilon_t=\) __________.
With autocorrelated errors, OLS estimators remain __________ but are no longer __________.
With positive autocorrelation, the usual standard errors are usually __________.
The Durbin–Watson statistic is approximately \(d\approx\) __________.
A value of \(d\) close to 2 indicates __________.
If \(d<d_L\), we conclude that there is __________ autocorrelation.
The Durbin–Watson test is not valid when a __________ is included as a regressor.
In generalized differencing, \(y_t'=\) __________.
The intercept of the original model is recovered as \(\hat\beta_0=\) __________.
Short-answer questions
What is autocorrelation? List its sources in agricultural data.
State the AR(1) error model and its properties.
What are the consequences of autocorrelation for OLS?
Describe graphical methods of detecting autocorrelation.
Explain the Durbin–Watson test and its decision rule.
Show that \(d\approx2(1-\hat\rho)\).
State the limitations of the Durbin–Watson test.
Derive the generalized difference transformation.
Describe the Cochrane–Orcutt procedure.
When is first differencing appropriate?
Numerical and conceptual questions
Answers are given at the end of the chapter.
\(\sum(e_t-e_{t-1})^2=18.6\) and \(\sum e_t^2=24.0\) with \(n=25\), \(k=2\). Compute \(d\) and test at 5%.
Estimate \(\rho\) from \(d=0.8\).
If \(d=3.1\) with \(n=30\) and \(k=1\), what do you conclude?
If \(\hat\rho=0.6\), write the transformed variables for \(y_t\) and \(x_t\).
The transformed model gives \(\hat\beta_0'=8\) with \(\hat\rho=0.6\). Find \(\hat\beta_0\).
For an AR(1) process with \(\rho=0.5\) and \(\sigma_a^2=3\), find \(V(\varepsilon_t)\) and \(Corr(\varepsilon_t,\varepsilon_{t-2})\).
Why is the Durbin–Watson test not meaningful for cross-sectional data arranged in random order?
\(d=1.45\), \(n=40\), \(k=2\). What is the decision?
Important formulae
AR(1) error model:
\[ \varepsilon_t=\rho\varepsilon_{t-1}+a_t,\qquad V(\varepsilon_t)=\frac{\sigma_a^2}{1-\rho^2},\qquad Corr(\varepsilon_t,\varepsilon_{t-s})=\rho^s \]
Durbin–Watson statistic:
\[ d=\frac{\sum_{t=2}^n(e_t-e_{t-1})^2}{\sum_{t=1}^ne_t^2}\approx2(1-\hat\rho) \]
Generalized differencing:
\[ y_t-\rho y_{t-1}=\beta_0(1-\rho)+\beta_1(x_t-\rho x_{t-1})+a_t \]
Quick revision
- Autocorrelation → common in time series and adjacent plots.
- Consequences → OLS unbiased but not BLUE; SEs understated; spurious significance.
- Detect → residual time plot, runs test, Durbin–Watson \(d\).
- \(d\approx2\) none; \(d<d_L\) positive; \(d>4-d_L\) negative.
- Remedy → look for omitted variables first; then generalized differencing, Cochrane–Orcutt, GLS.
Answers to fill in the blanks
1. Autocorrelation (serial correlation) 2. \(\rho\varepsilon_{t-1}+a_t\) 3. Unbiased; BLUE (efficient) 4. Underestimated 5. \(2(1-\hat\rho)\) 6. No autocorrelation 7. Positive 8. Lagged dependent variable 9. \(y_t-\rho y_{t-1}\) 10. \(\hat\beta_0'/(1-\hat\rho)\)
Solutions to numerical and conceptual questions
\(d=18.6/24.0=0.775<d_L=1.21\) (Table 10.2); positive autocorrelation.
\(\hat\rho\approx1-0.8/2=0.6\) (Equation 10.3).
\(4-d_L=2.65\); \(d=3.1>2.65\), so there is negative autocorrelation.
\(y_t'=y_t-0.6y_{t-1}\), \(x_t'=x_t-0.6x_{t-1}\) (Equation 10.4).
\(\hat\beta_0=8/(1-0.6)=20\).
\(V(\varepsilon_t)=3/(1-0.25)=4\); \(Corr=0.5^2=0.25\).
The ordering is arbitrary, so “successive” observations have no natural relationship; \(d\) would change with any reordering of the data.
\(d_L=1.39\le1.45\le d_U=1.60\): the test is inconclusive; compute the exact \(p\)-value or use the Breusch–Godfrey test.