Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

In 1949 an international airline started keeping a simple monthly tally: how many passengers flew that month, counted in thousands. Twelve years of those counts, from January 1949 through December 1960, became one of the most studied datasets in statistics. The airline’s problem was concrete. To decide how many aircraft to buy, how many crews to hire, and how to schedule maintenance, the planners needed to forecast demand a year or two ahead. A good forecast saved money; a bad one grounded planes or stranded passengers.

Figure 1 plots the 144 monthly counts in order. Three features jump out. The series climbs steadily: air travel roughly tripled over the twelve years. It also cycles every year, with a tall summer peak (people fly on vacation) and a winter dip. And the swings get wider as the series rises: the gap between the summer peak and the winter trough was small in 1949 and large in 1960. A single straight line will not describe this, but a regression with a trend term and a set of monthly indicators just might.

A line plot of monthly international airline passengers in thousands from 1949 to 1960. The series rises from about 100 to over 600, repeats a yearly cycle with a summer peak and winter trough, and the size of the yearly swing grows from roughly 30 in 1949 to over 150 by 1960.

Figure 1:The monthly airline series: a rising trend, a repeating yearly cycle with summer peaks, and seasonal swings that grow wider as the overall level climbs.

Time-ordered data like this break a promise the earlier chapters relied on. Every inference you have done so far assumed the errors were uncorrelated: one observation’s luck told you nothing about the next. When observations come in time order, that assumption usually fails. A month that runs above the trend tends to be followed by another above the trend, because whatever pushed demand up (a booming economy, a new route) does not vanish overnight. This chapter shows what that correlation does to your standard errors, how to detect it, one classic way to remove it, and how to judge a forecast honestly by testing it on the future instead of the past.

15.1 A model for trend and seasonality

Intuition

We start where the workflow always starts: with the picture and the question. Figure 1 shows three ingredients, and a regression can carry one term for each. The steady climb is a trend, which we model with a straight line in the time index t=1,2,,144t = 1, 2, \dots, 144. The yearly cycle is seasonality, which we model with eleven indicator (dummy) variables for the months February through December, each measuring how that month sits relative to a January baseline. The growing swings are the reason we do not model the raw counts directly.

Look again at the raw series: in 1949 the summer peak stands maybe 30 above the winter trough, but by 1960 that same seasonal gap is over 150. The seasonal effect is not a fixed number of passengers; it is a fixed percentage of the current level. When an effect is multiplicative like that, taking logarithms turns it additive and, as a bonus, evens out the variance. Figure 2 shows the payoff: on the log scale the seasonal swings are about the same width every year. Working on the log scale is the transformation idea from 10.2 The log transformation and reading its coefficients, and it is what lets a single set of month effects fit the whole twelve years.

Two side-by-side line plots of the airline series. The left panel, on the raw scale, shows seasonal swings that grow wider over time. The right panel, on the log scale, shows seasonal swings of roughly constant width across all years.

Figure 2:On the raw scale (left) the yearly swings widen as the level rises; on the log scale (right) they hold a nearly constant width. Logs turn a multiplicative seasonal pattern into an additive one and stabilize the variance.

Formula

Let YtY_t be the passenger count in month tt and work with logYt\log Y_t. The model carries one term for each feature of Figure 1: a linear trend, a fixed offset for each month, and an error.

The pieces, term by term:

In words: the log passenger count is a straight-line trend plus a fixed offset for each month of the year plus a disturbance. For now we fit this by ordinary least squares, treating the εt\varepsilon_t as if they satisfied the usual assumptions. Section 15.2 checks whether they do.

R

We read the tidy monthly file, build a time index and a log response, and make month a factor so lm expands it into indicator variables automatically.

air <- read.csv("data/airpassengers.csv")
air$t <- seq_len(nrow(air))
air$logpass <- log(air$passengers)
air$month <- factor(air$month)
dim(air)
head(air, 3)
[1] 144   5
  year month passengers t  logpass
1 1949     1        112 1 4.718499
2 1949     2        118 2 4.770685
3 1949     3        132 3 4.882802

Eleven coefficients are hard to picture from a table, so Figure 3 draws them as bars. Each bar is one month’s offset from January, and the shape tells the whole seasonal story at a glance: a summer hump peaking in July and August, a soft dip in late fall.

A bar chart of the eleven monthly seasonal offsets from the fitted model, with January fixed at zero as the baseline. Bars rise through spring to a summer peak at July (about 0.30) and August (about 0.29), then fall to a low at November (about minus 0.14). Bars above January are blue, bars below are orange.

Figure 3:The seasonal coefficients as bars, each measured against a January baseline. The summer peak and the November low that the numbers rank are far easier to see as a shape than as a column of decimals.

The trend slope deserves its own reading, because logs make it a growth rate.

Figure 4 lays the fitted values over the observed log series. The straight trend plus twelve monthly offsets reproduces the sawtooth shape closely, which is why R2R^2 is so high.

A line plot on the log scale showing observed log passengers and the fitted values from the trend-plus-month model, from 1949 to 1960. The fitted line tracks the observed sawtooth pattern closely, capturing both the upward trend and the repeating seasonal shape.

Figure 4:The trend-plus-month model on the log scale. A single straight trend and eleven seasonal offsets follow the observed sawtooth closely, which is why the model explains 98 percent of the variation.

15.2 Why time breaks ordinary least squares

Intuition

We can now fit the line; the obvious next question is whether we should trust its standard errors. Recall the residual plot habit from Chapter 2: after any fit, look at the residuals. For time data, plot them in time order. Figure 5 does exactly that for the trend-plus-season model, and the picture is not the random band you want. The residuals move in long runs: a stretch of months above zero, then a stretch below, then above again. A month that overshoots the model is usually followed by another that overshoots. That is autocorrelation (Definition 15.2): the errors are correlated with their own recent past.

A plot of the trend-plus-month model residuals against time from 1949 to 1960, drawn as stems from a zero line and colored by sign. The residuals form long runs of the same color, several years of mostly positive residuals followed by stretches of mostly negative ones, rather than alternating randomly.

Figure 5:The model residuals in time order form long runs of the same sign instead of scattering randomly around zero. That clustering is the visual signature of positive autocorrelation.

Autocorrelation matters because it breaks the “uncorrelated errors” assumption that every standard error formula in this book was built on. Under the Gauss-Markov conditions of 2.5 Sampling behavior and the Gauss-Markov theorem, distinct errors were uncorrelated. When they are not, least squares still lands on an unbiased estimate of the slope, but its reported standard error is wrong. For the positive autocorrelation you almost always see in time series, it is wrong in the dangerous direction: too small. The software prints a tight confidence interval and a tiny p-value, and you believe the trend is pinned down far more precisely than the data support.

Formula

The simplest and most common model for correlated errors is the first-order autoregressive model, written AR(1).

Reading the pieces:

In words: this month’s error is a fraction ρ\rho of last month’s error plus a fresh independent shock. Figure 6 contrasts independent errors with AR(1) errors of the same variance. The independent series has no memory; the AR(1) series wanders in runs, exactly like the residuals in Figure 5.

Two side-by-side time plots of simulated error series with the same variance. The left panel, independent errors, jitters rapidly around zero with no memory. The right panel, AR(1) errors with rho equal to 0.8, wanders in long smooth runs above and below zero.

Figure 6:Independent errors (left) and positively autocorrelated AR(1) errors (right) with the same variance. The AR(1) series drifts in long runs, which is why autocorrelated residuals cluster by sign.

Derivation

Why does positive autocorrelation make the reported standard error too small? The cleanest place to see the mechanism is the simplest estimator, the sample mean, where the algebra is short and the lesson transfers directly to the regression slope.

Proof. Suppose Yt=μ+εtY_t = \mu + \varepsilon_t for t=1,,nt = 1, \dots, n, where each error has mean zero and variance σ2\sigma^2, and neighboring errors have correlation Corr{εt,εt+k}=ρk\operatorname{Corr}\{\varepsilon_t, \varepsilon_{t+k}\} = \rho^{\,k}, the AR(1) pattern. The estimator of μ\mu is Yˉ\bar Y. Its true variance is

Var{Yˉ}=1n2Var ⁣{t=1nεt}=1n2(t=1nVar{εt}+2s<tCov{εs,εt}).\operatorname{Var}\{\bar Y\} = \frac{1}{n^2}\operatorname{Var}\!\Big\{\sum_{t=1}^n \varepsilon_t\Big\} = \frac{1}{n^2}\Big(\sum_{t=1}^n \operatorname{Var}\{\varepsilon_t\} + 2\sum_{s<t}\operatorname{Cov}\{\varepsilon_s, \varepsilon_t\}\Big).

The first sum is nσ2n\sigma^2. Every covariance is Cov{εs,εt}=σ2ρts\operatorname{Cov}\{\varepsilon_s,\varepsilon_t\} = \sigma^2 \rho^{\,|t-s|}, so collecting terms by their lag k=tsk = t - s gives

Var{Yˉ}=σ2n(1+2k=1n1(1kn)ρk).\operatorname{Var}\{\bar Y\} = \frac{\sigma^2}{n}\left(1 + 2\sum_{k=1}^{n-1}\Big(1 - \frac{k}{n}\Big)\rho^{\,k}\right).

In words: the true variance of the mean is the familiar σ2/n\sigma^2/n multiplied by a bracket that depends on the autocorrelation. When the errors are uncorrelated (ρ=0\rho = 0) the bracket is 1 and we recover σ2/n\sigma^2/n. When ρ>0\rho > 0 every term in the sum is positive, so the bracket exceeds 1 and the true variance is larger than σ2/n\sigma^2/n. But σ2/n\sigma^2/n is exactly what the ordinary formula estimates, because it ignores the covariances. So ordinary least squares divides by too little and reports a variance, and a standard error, that are too small. The same cancellation of covariances inflates the true variance of the regression slope b1b_1; only the bookkeeping is longer. \blacksquare

How badly does this bite in practice? A simulation makes it concrete, and it is worth running yourself, in the spirit of the “check a formula by simulating it” habit.

A histogram of 2000 simulated slope estimates centered on the true slope of 0.5, with a wide double-headed arrow marking the true spread of about plus or minus 0.016 and a much shorter arrow marking the mean OLS-reported standard error of about plus or minus 0.005.

Figure 7:Two thousand slope estimates under AR(1) errors. Their actual spread (wide arrow) is about three times the standard error ordinary least squares reports (short arrow), so the usual confidence interval is far too narrow.

The simulation below puts that whole argument under your finger: it holds the data and the shocks fixed and lets you turn the autocorrelation up, so you can watch the reported standard error stay put while the true one runs away from it.

Slide the autocorrelation rho and watch the residuals fall into long runs, the Durbin-Watson statistic drop from 2 toward 0, and the standard error that least squares reports drift further and further below the true spread of the slope.

15.3 Detecting autocorrelation: the Durbin-Watson test

Intuition

The residual plot warns you; a test quantifies the warning. Two pictures point the same way. A lag plot (Definition 15.5) graphs each residual ete_t against the previous residual et1e_{t-1}; positive autocorrelation shows up as an upward tilt, because a positive residual tends to sit next to another positive one. Figure 9 is that plot for the airline model, and the tilt is unmistakable.

The Durbin-Watson test turns that tilt into a single number and a p-value. You met this test as one item in the diagnostic toolkit of 9. Model diagnostics, where it flagged ordering in savings residuals; here is the time-ordered data it was built for, and this is where we finally derive why its scale runs the way it does.

A scatterplot of each model residual against the previous residual, with a fitted line of positive slope about 0.79 through the origin. The points cluster along the upward line, showing that a residual and its predecessor tend to have the same sign.

Figure 9:Each residual against the one before it. The clear upward tilt (slope near 0.79) means a residual is usually followed by another of the same sign, the definition of positive autocorrelation.

Formula

The Durbin-Watson statistic measures how much consecutive residuals differ.

The statistic runs from 0 to 4. When neighboring residuals are nearly equal (strong positive autocorrelation) the numerator is small and DD is near 0. When residuals alternate sign (negative autocorrelation) the changes are large and DD is near 4. When residuals are uncorrelated, DD sits near 2. Figure 10 is the number line to keep in mind.

A horizontal number line from 0 to 4 shaded into three zones: near 0 labeled positive autocorrelation, near 2 labeled none or ideal, near 4 labeled negative autocorrelation. A red marker sits at 0.43, deep in the positive-autocorrelation zone, labeled airpassengers model DW equals 0.43.

Figure 10:The Durbin-Watson statistic runs from 0 to 4: near 0 is strong positive autocorrelation, near 2 is none, near 4 is negative. The airline model lands at 0.43, deep in the positive zone.

Derivation

The scale is not arbitrary. Chapter 9 stated the shortcut D2(1ρ^)D \approx 2(1 - \hat\rho) in its summary and used it to read the savings statistic; now that autocorrelation is the whole story, it is worth seeing where that identity comes from. The Durbin-Watson statistic is, up to a small-sample correction, just a rescaling of the lag-one residual autocorrelation, which explains why 2 is the neutral value.

Proof. Expand the square in the numerator:

t=2n(etet1)2=t=2net2+t=2net122t=2netet1.\sum_{t=2}^{n} (e_t - e_{t-1})^2 = \sum_{t=2}^{n} e_t^2 + \sum_{t=2}^{n} e_{t-1}^2 - 2\sum_{t=2}^{n} e_t e_{t-1} .

For a reasonably long series the first two sums are each very close to the full residual sum of squares t=1net2\sum_{t=1}^n e_t^2, because they each drop only one term (the last or the first). Write r1=(t=2netet1)/(t=1net2)r_1 = \big(\sum_{t=2}^n e_t e_{t-1}\big)\big/\big(\sum_{t=1}^n e_t^2\big) for the lag-one residual autocorrelation. Dividing the expansion by et2\sum e_t^2,

D=t=2net2+t=2net122t=2netet1t=1net2    1+12r1=2(1r1).D = \frac{\sum_{t=2}^{n} e_t^2 + \sum_{t=2}^{n} e_{t-1}^2 - 2\sum_{t=2}^{n} e_t e_{t-1}} {\sum_{t=1}^{n} e_t^2} \;\approx\; 1 + 1 - 2 r_1 = 2(1 - r_1) .

In words: the Durbin-Watson statistic is about 2 minus twice the lag-one autocorrelation. If r1=0r_1 = 0 then D2D \approx 2; if r11r_1 \to 1 then D0D \to 0; if r11r_1 \to -1 then D4D \to 4. This is why a value near 2 signals no autocorrelation. \blacksquare

Deciding whether an observed DD is far enough from 2 to be surprising is slightly awkward. The null distribution of DD depends on the predictor values, so Durbin and Watson published a pair of bounds, dLd_L and dUd_U, that bracket the true critical value. Software sidesteps the tables by computing the p-value directly. Both appear below.

R and Python

A p-value below 2×10162\times 10^{-16} is easy to read past. The simulation below makes it concrete by building the comparison the test is making: hundreds of series whose errors really are uncorrelated, so you can see for yourself how far 0.43 sits from anything chance produces.

Simulate the Durbin-Watson statistic under honestly uncorrelated errors and watch the pile gather around 2. The airline model’s 0.43, marked in amber, never gets company.

15.4 A remedy: the Cochrane-Orcutt procedure

Intuition

If the errors follow an AR(1) pattern, we can transform them away. The trick is quasi-differencing: instead of the raw series, regress each observation minus ρ\rho times the previous observation. That combination cancels the correlated part of the error and leaves the fresh, independent innovations behind. Because the transformed model has uncorrelated errors, ordinary least squares on it is valid again. The one snag is that ρ\rho is unknown, so we estimate it from the residuals and iterate. That loop is the Cochrane-Orcutt procedure.

Formula

Start from the regression with AR(1) errors, written compactly with xt\mathbf{x}_t for the row of predictors (the 1, the trend tt, and the month indicators) in month tt:

Yt=xtβ+εt,εt=ρεt1+ut.Y_t = \mathbf{x}_t' \boldsymbol\beta + \varepsilon_t, \qquad \varepsilon_t = \rho\,\varepsilon_{t-1} + u_t .

Lag the whole regression one step, multiply by ρ\rho, and subtract:

YtρYt1Yt=(xtρxt1)xtβ+(εtρεt1)ut.\underbrace{Y_t - \rho\, Y_{t-1}}_{Y_t^{\ast}} = \underbrace{(\mathbf{x}_t - \rho\,\mathbf{x}_{t-1})'}_{\mathbf{x}_t^{\ast\prime}} \boldsymbol\beta + \underbrace{(\varepsilon_t - \rho\,\varepsilon_{t-1})}_{u_t} .

The transformed model Yt=xtβ+utY_t^{\ast} = \mathbf{x}_t^{\ast\prime}\boldsymbol\beta + u_t has exactly the same coefficients β\boldsymbol\beta as the original, but now satisfies the ordinary least-squares assumptions, so fitting it gives trustworthy standard errors.

Derivation

Proof. The AR(1) definition says the error is its own lag scaled by ρ\rho plus an independent shock, εt=ρεt1+ut\varepsilon_t = \rho\varepsilon_{t-1} + u_t, which rearranges to ut=εtρεt1u_t = \varepsilon_t - \rho\varepsilon_{t-1}. Take the original regression Yt=xtβ+εtY_t = \mathbf{x}_t'\boldsymbol\beta + \varepsilon_t and the same relation one step back, Yt1=xt1β+εt1Y_{t-1} = \mathbf{x}_{t-1}'\boldsymbol\beta + \varepsilon_{t-1}. Multiply the lagged equation by ρ\rho and subtract it from the current one. On the left, YtρYt1Y_t - \rho Y_{t-1}; on the right, (xtρxt1)β(\mathbf{x}_t - \rho\mathbf{x}_{t-1})'\boldsymbol\beta plus εtρεt1\varepsilon_t - \rho \varepsilon_{t-1}, and that last piece is exactly utu_t. So the quasi-differenced series obeys a regression with the same β\boldsymbol\beta and with the independent, constant-variance errors utu_t. Ordinary least squares is back on solid ground, which is the whole point of the transform.

The obstacle is that ρ\rho is unknown. The Cochrane-Orcutt procedure estimates it and the coefficients together, by iterating:

  1. Fit the original model by ordinary least squares and keep the residuals ete_t.

  2. Estimate ρ\rho by regressing ete_t on et1e_{t-1} through the origin: ρ^=t=2netet1/t=2net12\hat\rho = \sum_{t=2}^n e_t e_{t-1} / \sum_{t=2}^n e_{t-1}^2.

  3. Quasi-difference YY and every predictor using ρ^\hat\rho, and refit by least squares to get new β\boldsymbol\beta.

  4. Recompute residuals from the original-scale fit, re-estimate ρ\rho, and repeat until ρ^\hat\rho stops changing.

Each pass reduces the leftover autocorrelation; in practice a couple of iterations suffice. \blacksquare

Figure 12 lays the four steps out as a loop. Read it top to bottom, then follow the orange arrow back up whenever the estimated ρ\rho is still moving: fit, estimate, transform, refit, check, and stop once ρ^\hat\rho settles.

A flowchart of the Cochrane-Orcutt procedure. Four boxes run down the left in order: fit by ordinary least squares and keep residuals, estimate rho by regressing each residual on its lag, quasi-difference the response and every predictor with the estimated rho, and refit by least squares and recompute residuals. An arrow leads to a decision diamond asking whether rho-hat is stable. A no branch loops back up to the estimate-rho step; a yes branch leads to a final box, report the corrected fit.

Figure 12:The Cochrane-Orcutt procedure as a loop. Each pass estimates the autocorrelation, quasi-differences with it, and refits; the loop repeats until the estimated rho stops changing, then reports the corrected standard errors.

R and Python

Two side-by-side lag plots of residuals. The left panel, before Cochrane-Orcutt, shows an upward tilt with lag-one slope about 0.79. The right panel, after one quasi-differencing step, shows a round cloud with lag-one slope near zero.

Figure 13:Residual lag plots before (left) and after (right) one Cochrane-Orcutt step. Quasi-differencing flattens the upward tilt to a round cloud, so the transformed errors look uncorrelated.

Try it 15.4 asks you to argue that ρ=1\rho = 1 is too much. The simulation below lets you check the argument on the real airline model by choosing the ρ\rho yourself and reading off the autocorrelation that survives.

Quasi-difference the airline model with a rho of your choosing. Near 0.71 the residual runs break up and the Durbin-Watson statistic settles beside 2; push toward 1 and the residuals begin to zigzag instead.

15.5 Forecasting honestly: test on the future

Intuition

A model that fits the past beautifully can still forecast the future badly. The only honest way to judge a forecast is to hide part of the future from the model, forecast it, and compare. For time data that means an out-of-time split (Definition 15.11): train on the earlier years, test on the later ones. This is the validation mindset of Chapter 12 with one strict rule added by the clock. You may never train on data that came after your test period, because at forecast time that data did not exist. Splitting at random, the way you would for cross-sectional data, would let the model peek at the future and flatter itself.

We train the trend-plus-season model on 1949 through 1957 and forecast 1958 through 1960, three years it has never seen. Figure 15 shows the result, and it is a useful humbling.

A plot of the airline series with a dashed line separating the 1949 to 1957 training period from the 1958 to 1960 test period. Fitted values hug the data in the training period. In the test period the forecast line runs visibly above the actual counts, and a shaded 95 percent prediction band covers only a few of the actual points.

Figure 15:The model trained on 1949 to 1957 and forecasting 1958 to 1960. In the test years the forecast drifts above what actually happened, and the shaded naive prediction band misses most of the real months.

Formula

Two honest scorecards summarize test-set performance. The root mean squared error and the mean absolute percentage error on the held-out months are

RMSE=1ntestttest(YtY^t)2,MAPE=100%ntestttestYtY^tYt.\mathrm{RMSE} = \sqrt{\frac{1}{n_{\text{test}}}\sum_{t \in \text{test}} (Y_t - \hat Y_t)^2}, \qquad \mathrm{MAPE} = \frac{100\%}{n_{\text{test}}}\sum_{t \in \text{test}}\frac{|Y_t - \hat Y_t|}{Y_t} .

In words: RMSE is the typical size of a forecast miss in passengers, and MAPE is the average miss as a percent of the actual count.

Because the model is fitted on the log scale, we exponentiate the log forecast to get a count forecast before scoring. We also carry the ordinary regression prediction interval from 3.5 Prediction interval for a new observation, back-transformed the same way, and check how often it actually covers the truth.

R and Python

Why does the prediction interval fail so badly? The interval from 3.5 Prediction interval for a new observation was derived under independent, constant-variance, normal errors, and it accounts for only two sources of uncertainty: the spread of a single new error and the uncertainty in the fitted mean. For a forecast several years out, neither piece is the real story. The errors are strongly autocorrelated, so a run of bad months compounds instead of averaging out. The trend is extrapolated far beyond the data, so any error in the estimated slope grows with the horizon. And genuine forecast uncertainty should widen the further ahead you look, while the ordinary regression interval barely widens at all. An interval that ignores all of this is bound to be too narrow, which is exactly what the 19%19\% coverage shows.

The 1957 split is one choice among many, and the simulation below lets you move it. Watching the same model score well on the months it saw and badly on the months it did not, over and over at different splits, is the fastest way to make the lesson stick.

Move the training cutoff and compare the two error tiles: the model scores about 9 on the months it trained on and about 63 on the months it forecast. The 95 percent prediction band covers 19 percent of them.

15.6 Chapter summary

You can now handle regression on time-ordered data from end to end. You fit a trend-plus-season model on the log scale (Definition 15.1), reading the trend as a growth rate and each month coefficient as a seasonal offset, reusing the log transform of 10.2 The log transformation and reading its coefficients and the dummy coding of 11.1 From categories to numbers: indicator coding. You can explain why time order usually correlates the errors, and you proved, for the sample mean, that positive autocorrelation makes the ordinary variance formula too small (Theorem 15.4), so least squares reports standard errors you cannot trust. You diagnose autocorrelation three ways, the residual-versus-time plot, the lag plot, and the Durbin-Watson test, and you derived why D2(1r1)D \approx 2(1 - r_1) makes 2 the neutral value (Theorem 15.7). You apply the Cochrane-Orcutt procedure and know why quasi-differencing restores independent errors (Theorem 15.10). And you evaluate a forecast honestly with an out-of-time split, computing test error and prediction-interval coverage, and you can say plainly why calibrated forecast intervals need time-series methods this course does not cover.

Key results at a glance.

ResultStatement or formulaValid when
Trend-plus-season model (Def 15.1)logYt=β0+β1t+m=212γmDmt+εt\log Y_t = \beta_0 + \beta_1 t + \sum_{m=2}^{12}\gamma_m D_{mt} + \varepsilon_ttrend and seasonality are multiplicative; logs make them additive and stabilize variance
Growth from the log slopemonthly (eβ11)×100%(e^{\beta_1}-1)\times 100\%; annual (e12β11)×100%(e^{12\beta_1}-1)\times 100\%response modeled on the log scale
AR(1) error model (Def 15.3)εt=ρεt1+ut\varepsilon_t = \rho\varepsilon_{t-1} + u_t, $\rho
Variance of the mean under AR(1) (Thm 15.4)Var{Yˉ}=σ2n(1+2k(1kn)ρk)\operatorname{Var}\{\bar Y\}=\frac{\sigma^2}{n}\big(1 + 2\sum_{k}(1-\tfrac{k}{n})\rho^k\big)AR(1) errors; exceeds σ2/n\sigma^2/n when ρ>0\rho>0, so OLS SEs are too small
Durbin-Watson statistic (Def 15.6)D=t2(etet1)2/tet2D = \sum_{t\ge 2}(e_t - e_{t-1})^2 / \sum_t e_t^2any fitted regression; 0 positive, 2 none, 4 negative
Durbin-Watson identity (Thm 15.7)D2(1r1)D \approx 2(1 - r_1)reasonably long series of residuals
Quasi-differencing removes AR(1) (Thm 15.10)YtρYt1=(xtρxt1)β+utY_t - \rho Y_{t-1} = (\mathbf{x}_t - \rho\mathbf{x}_{t-1})'\boldsymbol\beta + u_tAR(1) errors, with ρ\rho known or estimated
Out-of-time forecast scoreRMSE and MAPE on held-out later monthstrain/test split respects time order
Prediction-interval coveragefraction of test months inside the 95%95\% intervalinterval is honest only if coverage 0.95\approx 0.95

Airline figures: R2=0.983R^2 = 0.983, ρ^=0.79\hat\rho = 0.79, DD moves from 0.43 to 2.19 after one Cochrane-Orcutt step, test RMSE 63 / MAPE 14%14\%, and prediction-interval coverage 0.19 (7 of 36).

Key terms. time-ordered data, trend, seasonality, trend-plus-season model, autocorrelation, first-order autoregressive (AR(1)) error model, autocorrelation parameter, innovation, Durbin-Watson statistic, Durbin-Watson test, lag plot, Cochrane-Orcutt procedure, quasi-differencing, out-of-time split, mean absolute percentage error (MAPE), prediction-interval coverage.

You should now be able to.

Where this fits. This chapter serves the CHECK and USE stages of the modeling workflow introduced in The modeling workflow. We ASK a forecasting question and EXPLORE the series, FIT a trend and seasonal model, then spend most of the chapter on CHECK: the uncorrelated-errors assumption that every earlier inference relied on fails on time data, so we diagnose the failure with the Durbin-Watson test and repair the inference with Cochrane-Orcutt. The USE stage, forecasting, comes with a warning the earlier chapters could make cleanly but this one cannot: the prediction interval of 3.5 Prediction interval for a new observation, honest under independent errors, is badly miscalibrated here. That is the seam where an applied regression course hands off to a time-series course: the out-of-time split and the honest-forecast discipline you built here are the entry habits any such course assumes. Chapter 16 (16. Path analysis and a look ahead) closes the book by stepping back from any single model to ask what a chain of regressions can and cannot say about cause, and by walking the whole workflow one last time.

15.7 Frequently asked questions

Q1. Why log the passengers instead of modeling the counts directly? Because the seasonal swings and the error spread both grow with the level of the series, which is a multiplicative pattern. Taking logs turns the multiplicative seasonal effect into an additive one, so a single set of month coefficients fits all twelve years, and it stabilizes the variance so the constant-variance assumption is closer to true. This is the same reasoning as 10.2 The log transformation and reading its coefficients, applied to a series that grows over time.

Q2. If least squares is still unbiased under autocorrelation, why care? Unbiased means the estimate is right on average, but a single analysis gives you one estimate, and you need to know how far it might be off. That is the standard error’s job, and autocorrelation makes the reported standard error wrong, usually far too small. You end up with a point estimate that is fine and a confidence interval that lies about its own reliability.

Q3. My Durbin-Watson statistic is 2.6. Is that a problem? It is on the negative- autocorrelation side, since D>2D > 2 means r1<0r_1 < 0. From D2(1r1)D \approx 2(1 - r_1), a DD of 2.6 implies r10.3r_1 \approx -0.3. Mild negative autocorrelation is less common than positive but does occur, often from over-differencing or from a variable measured as a change. Whether it is “a problem” depends on the p-value and on how much you rely on the standard errors.

Q4. Does Cochrane-Orcutt change the trend estimate or just the standard errors? Both, a little. The quasi-differenced fit is a generalized least-squares estimate, which weights the data differently from ordinary least squares, so the coefficients shift somewhat. The larger and more important change is to the standard errors, which now account for the correlation and are the ones you should report.

Q5. Why not just use the ordinary prediction interval and admit it is approximate? Because it is not approximately right, it is badly wrong: on the airline test set it covered 19%19\% of months instead of 95%95\%. An interval that far off does not communicate uncertainty, it misstates it. If you cannot produce a calibrated interval, report the out-of-time test error instead, which is honest about how the forecast actually performs.

Q6. Could I add more predictors instead of modeling the error correlation? Sometimes. Autocorrelated residuals can be a symptom of a missing predictor, an omitted trend curvature or a skipped seasonal term, and adding the right predictor can remove the pattern at its source. That is usually the better fix when you can find the missing structure. Cochrane-Orcutt is for the residual correlation that remains after you have modeled the structure you can.

Q7. Is a high R2R^2 like 0.983 evidence the forecast will be good? No. That R2R^2 measures fit to the past, and this chapter’s whole point is that in-sample fit and out-of-time forecast accuracy are different things. The same model with R2=0.983R^2 = 0.983 missed the future by 14%14\% and its interval covered one test month in five. Judge a forecast on held-out data, never on R2R^2.

15.8 Practice problems

  1. (A) In one sentence each, name the three features of the airline series in Figure 1 and say which term in the trend-plus-season model captures each.

  2. (A) Explain why the errors in a regression on monthly data are likely to be correlated, and give a concrete reason two neighboring months would share the sign of their error.

  3. (A) The trend slope estimate is b1=0.0101b_1 = 0.0101 on the log scale. Interpret it as a monthly percentage growth rate, and explain why exponentiating is needed.

  4. (A) A Durbin-Watson statistic equals 0.43. Without a table, state what it implies about the lag-one autocorrelation and about the reliability of the ordinary standard errors.

  5. (A) Explain, to someone who has not taken this course, why splitting time-series data at random for a train/test evaluation is cheating, and what the correct split is.

  6. (A) The naive 95%95\% prediction interval covered 19%19\% of the test months. State plainly what “95% coverage” is supposed to mean and why 19%19\% is a failure, not just a small miss.

  7. (A) Give a wrong reading of the July coefficient γ^7=0.3006\hat\gamma_7 = 0.3006 that a careless student might state, then correct it. (Hint: the coefficient is on the log scale, relative to January.)

  8. (A) Why does positive autocorrelation, rather than negative, make ordinary least squares overconfident? Point to the sign of the covariance terms in the variance of the mean.

  9. (B) Starting from D=t=2n(etet1)2/t=1net2D = \sum_{t=2}^n (e_t - e_{t-1})^2 / \sum_{t=1}^n e_t^2, derive the approximation D2(1r1)D \approx 2(1 - r_1) (Theorem 15.7), stating the step where the two truncated sums are replaced by the full residual sum of squares and why it is reasonable for large nn.

  10. (B) For Yt=μ+εtY_t = \mu + \varepsilon_t with Var{εt}=σ2\operatorname{Var}\{\varepsilon_t\} = \sigma^2 and Cov{εs,εt}=σ2ρts\operatorname{Cov}\{\varepsilon_s, \varepsilon_t\} = \sigma^2 \rho^{|t-s|}, derive Var{Yˉ}=σ2n(1+2k=1n1(1k/n)ρk)\operatorname{Var}\{\bar Y\} = \frac{\sigma^2}{n}\big(1 + 2\sum_{k=1}^{n-1}(1 - k/n)\rho^k\big) (Theorem 15.4), and conclude it exceeds σ2/n\sigma^2/n when ρ>0\rho > 0.

  11. (B) Using the AR(1) error model εt=ρεt1+ut\varepsilon_t = \rho\varepsilon_{t-1} + u_t, derive the quasi-differencing transform (Theorem 15.10) and show that the transformed error εtρεt1\varepsilon_t - \rho\varepsilon_{t-1} equals the independent innovation utu_t.

  12. (B) Show that Var{εt}=σu2/(1ρ2)\operatorname{Var}\{\varepsilon_t\} = \sigma_u^2/(1 - \rho^2) for a stationary AR(1) process, starting from εt=ρεt1+ut\varepsilon_t = \rho\varepsilon_{t-1} + u_t and using Var{εt}=Var{εt1}\operatorname{Var}\{\varepsilon_t\} = \operatorname{Var}\{\varepsilon_{t-1}\}.

  13. (B) In the AR(1) model, show that the correlation between errors kk steps apart is ρk\rho^k, so the autocorrelation decays geometrically with the lag. (Use Cov{εt,εtk}=ρCov{εt1,εtk}\operatorname{Cov}\{\varepsilon_t, \varepsilon_{t-k}\} = \rho\,\operatorname{Cov}\{\varepsilon_{t-1}, \varepsilon_{t-k}\}.)

  14. (B) The Cochrane-Orcutt transform loses the first observation, since Y1Y_1^{\ast} has no predecessor. Explain why, and describe how the Prais-Winsten variant recovers it by rescaling the first row by 1ρ2\sqrt{1 - \rho^2} (a one-paragraph argument, no full derivation needed).

  15. (B) A student claims that because b1b_1 is unbiased under autocorrelation, the confidence interval b1±ts{b1}b_1 \pm t^{\ast} s\{b_1\} is still valid. Identify the error in the claim and state precisely which quantity in the interval is wrong.

  16. (B) Show that if the true errors are uncorrelated (ρ=0\rho = 0), the Cochrane-Orcutt first step estimates ρ^0\hat\rho \approx 0 and the quasi-differenced fit reduces to ordinary least squares, so the procedure does no harm when there is no autocorrelation.

  17. (C) Read airpassengers.csv, build t and logpass, fit the trend-plus-season model, and reproduce the trend slope, R2R^2, and residual standard error reported in Example 15.1.

  18. (C) Compute the Durbin-Watson statistic from the residuals by hand (via (etet1)2/et2\sum (e_t - e_{t-1})^2 / \sum e_t^2) and confirm it against lmtest::dwtest in R or durbin_watson in Python. Report both.

  19. (C) Make the residual-versus-time plot and the lag plot for the fitted model. Describe what each shows and how they agree about the sign of the autocorrelation.

  20. (C) Estimate ρ\rho from the residuals, quasi-difference the response and design matrix, refit, and report the Durbin-Watson statistic before and after. Confirm it moves from about 0.43 toward 2.

  21. (C) Fit the model without logs (passengers ~ t + month) and compare its residual-versus-time plot and Durbin-Watson statistic to the log model’s. Does dropping the log make the autocorrelation better or worse, and does the residual spread look constant?

  22. (C) Split the data by time (train on 1949 to 1957, test on 1958 to 1960), fit on the training years, forecast the test years, back-transform, and reproduce the test RMSE and MAPE from Example 15.6.

  23. (C) For the same split, compute the naive 95%95\% prediction-interval coverage on the test set and confirm it is far below 0.95. Then compute the in-sample coverage on the training set and comment on the difference.

  24. (C) Refit the trend-plus-season model dropping the seasonal dummies (trend only, logpass ~ t). Report the drop in R2R^2 and the new Durbin-Watson statistic, and explain how the unmodeled seasonal pattern shows up in the residuals of the trend-only fit.

  25. (C) Add a squared trend term (logpass ~ t + I(t^2) + month) and report whether the curvature term is needed and whether it reduces the residual autocorrelation. Interpret what a negative coefficient on t2t^2 would mean for the growth rate.

  26. (C) Using the training fit, forecast December 1958, 1959, and 1960 (months 120, 132, 144), back-transform, and compare each to the actual value. Describe how the forecast error grows with the horizon.

  27. (C) Repeat the out-of-time evaluation with an earlier split (train 1949 to 1955, test 1956 to 1960). Report the test MAPE and compare it to the 1958 split’s 14%14\%. Explain why a shorter training window can change the forecast error.

  28. (C) Run the simulation of Example 15.3 for ρ=0\rho = 0, ρ=0.4\rho = 0.4, and ρ=0.8\rho = 0.8, and report the ratio of the mean reported SE to the true standard deviation of b1b_1 for each. Describe how the ratio changes as ρ\rho grows and what that means for confidence intervals.

  29. (A) The ordinary regression prediction interval from 3.5 Prediction interval for a new observation covered only 19%19\% of the airline test months. Give the three reasons this interval is structurally too narrow for a forecast several years ahead, and name one family of methods that builds the error correlation into the model so its forecast interval widens with the horizon.

15.9 Exam practice

These five questions are written in the style of the course exams: each one hands you output or a claim and asks you to explain, in full sentences with units, what it means. A correct number with no reasoning earns little credit here. Work each one before opening the model answer.

EP 15.1 (interpret this output in context). The trend-plus-season model was fitted to all 144 months of airpassengers.csv, and the software reported the following.

Coefficients (partial):
            Estimate  Std. Error  t value  Pr(>|t|)
t          0.0100688   0.0001193   84.40    < 2e-16 ***

Durbin-Watson test:  DW = 0.4252,  p-value < 2.2e-16
alternative hypothesis: true autocorrelation is greater than 0

Interpret the trend coefficient as a yearly growth rate (use e12×0.01011.128e^{12 \times 0.0101} \approx 1.128), and then explain, given the Durbin-Watson result, whether you would report the printed standard error of 0.00012 and the tiny p-value on the trend at face value. State the direction in which those numbers are wrong and why.

EP 15.2 (a student claims X, evaluate). A student writes: “This model has R2=0.983R^2 = 0.983, so it explains almost all the variation in the series. That means it will forecast next year’s monthly passenger counts to within about 2%2\%.” Using the out-of-time evaluation from this chapter, evaluate the student’s reasoning and state what the correct expectation is.

EP 15.3 (interpret this output in context). One Cochrane-Orcutt step was run on the airline model, producing the output below.

rho_hat (lag-one autocorrelation of residuals):  0.7918
Durbin-Watson before quasi-differencing:  0.4252
Durbin-Watson after  quasi-differencing:  2.1891

Explain what this procedure did to the model, what problem the “after” statistic shows it fixed, and name one thing this step does not fix. Write in full sentences.

EP 15.4 (what would change if). Suppose you had fitted the model to the raw passenger counts instead of their logs, passengers ~ t + month. The two fits compare as follows.

                    R^2     residual SE        DW      corr(|residual|, fitted)
raw counts        0.9559     26.33 pass       0.4502            +0.137
log counts        0.9835      0.0593 (log)    0.4252            -0.041

Explain what would change, and what would not, if you used the raw-count fit. Address both the behavior of the residual spread and whether the autocorrelation problem is cured, and say why the log scale is preferred here.

EP 15.5 (explain why). On the 1958 to 1960 test set, the model’s nominal 95%95\% prediction interval covered only 7 of the 36 test months, an actual coverage of 19%19\%.

nominal coverage:  0.95
actual coverage:   0.194   (7 of 36 test months inside the 95% interval)

State what “95%95\% coverage” is supposed to mean, explain why 19%19\% is a structural failure rather than a small miss, give the three reasons the ordinary regression interval is too narrow for a forecast several years ahead, and name one family of methods built to fix it.

Chapter game