liveBook · Manning

Lag

As explained in Statistics Every Programmer Needs

A lagged observation is a time-series observation from an earlier time point used in relation to a later observation.

A lag is the distance between a time-series observation and an earlier observation. At lag k, the comparison is between the value at time t and the value at time t − k. Lags let a forecasting model use past values to help predict a current value; in an AR(1) model, that past value is the immediately preceding observation. section 7.3.7 section 7.3.1

Inspect lag relationships before choosing how many past values to model:

  • The autocorrelation function (ACF) measures correlation between a series and its past values across lags. Plotting those correlations reveals temporal dependence. section 7.3.7
  • The partial autocorrelation function (PACF) measures the relationship at a particular lag after accounting for intervening lags. A sharp drop after the first few lags can suggest that only those lags have a substantial direct relationship. section 7.3.7
  • Stationarity matters when interpreting these patterns: a stationary series has autocovariance that depends on the lag, not on the particular dates compared. Differencing subtracts the previous observation to help address nonstationarity. section 7.3.5 section 7.3.7

Inspect lags before fitting ARIMA

For a training series of closing prices, `plot_acf(train)` and `plot_pacf(train)` expose lag relationships. After `train_diff = train.diff().dropna()`, compare the original and differenced plots rather than assuming their patterns are unchanged. In this example, the augmented Dickey–Fuller p-value falls from about 0.576 for the original training series to 1.25 × 10⁻¹⁶ after differencing. The resulting specification, `ARIMA(train, order=(1, 1, 0))`, uses one autoregressive lag, one differencing step, and no lagged forecast errors. These settings follow the inspected training data; they are not a universal choice. section 7.3.7 section 7.3.9

A lag can describe either a past observation or, in a moving-average model component, a past forecast error. ARIMA can use both; exponential smoothing instead forecasts with weighted past observations whose weights decrease exponentially. Distinguish these roles before interpreting a model’s order. section 7.3.9 section 7.4.3

How Statistics Every Programmer Needs covers it

How deep it goes
Defines lags through ACF and PACF, then applies their plots to differencing and ARIMA order selection.
Examples
Compares ACF and PACF plots before and after differencing closing prices, then fits an ARIMA(1, 1, 0) model.
What it assumes
Introduces covariance, variance, ACF, and PACF while working with a training time series.
What you can do after
Apply it via statsmodels ACF and PACF plots to assess lag relationships before specifying an ARIMA model.
How it connects
Connects lags to autocorrelation, partial autocorrelation, stationarity, differencing, autoregression, and lagged forecast errors.

Also explained in

Compare how 5 books explain lag →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.