Method · Statistics Library

Autocorrelation (ACF and PACF)

The autocorrelation function (ACF) shows how strongly a series correlates with itself 1, 2, 3, ... periods earlier, and the partial autocorrelation function (PACF) shows what remains at each lag once the shorter lags are accounted for; bars past the dashed bounds are larger than pure noise would usually give.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

Take a series of monthly sales and line it up against itself shifted by one month: the correlation of the two is the lag-1 autocorrelation. Shift by two months for lag 2, and so on. The ACF draws all of them as bars. A bar below zero means a high value tends to be followed, that many steps later, by a low one: the series swings back and forth.

The PACF asks a sharper question: after allowing for the months in between, is there still a link between this month and the one k months back? It helps tell an effect that reaches straight back k periods from one that is just passed along one month at a time.

The dashed lines mark how far a bar usually reaches by chance if the values were unrelated: about 19 bars in 20 stay inside them. A slowly fading ACF means the series drifts or trends; spikes at lag 12 in monthly data mean a yearly pattern. One bar just past the line at a long lag is weak evidence, because about one bar in twenty crosses it by chance.

A blank cell is a missing period. Leaving it out would join the values on either side of the gap as if they were neighbors and shift every later lag, so KernelStats keeps the gap in its place and the card says how many values were missing.

Practitioner explanation

KernelStats computes the sample ACF as R's acf() (the biased estimator with divisor n, statsmodels acf with fft off) and the PACF as R's pacf() (Durbin-Levinson on the sample ACF, statsmodels method 'ldb'), with R's default lag.max = floor(10 log10 n) unless a largest lag is given, and the approximate white-noise bound qnorm(0.975)/sqrt(n). An optional differencing (1 or 2) is applied first. A blank cell is a missing period. KernelStats keeps the gaps, as R's acf(x, na.action = na.pass) does: each lag uses only the pairs of values that are both present, n and the bound count the gaps, and the card notes how many values were missing. Dropping blank cells instead joins the values on either side of a gap as if they were neighbors and shifts every lag that spans it: on airquality Ozone (37 blanks of 153), lag 1 is 0.562 with the gaps kept and 0.464 with them dropped. R's acf() with its default na.action refuses a series with blanks. The rows must still be in time order with one row per period.

Identification heuristics: an ACF that cuts off after lag q with a tailing PACF suggests MA(q); a PACF cutting off after lag p with a tailing ACF suggests AR(p); both tailing suggests ARMA. The bound is pointwise and approximate (Bartlett's formula would widen it at higher lags for a non-white series), so read shapes, not single bars. The ARIMA card draws the residual ACF and PACF, which should show no bar well past the bounds.

When to use it

Consider it when

You want to see whether a series is autocorrelated, how far back the dependence reaches, whether it is seasonal, or which ARIMA order to try (ACF, PACF, correlogram).

Use caution when

The rows are not in time order, or a missing period has no row at all (the lags would be wrong; a blank cell in its row keeps the gap), or you want a forecast (use ARIMA or exponential smoothing).

Formulas and symbols

Sample autocorrelation at lag k

rk=∑t=1n−k(yt−yˉ)(yt+k−yˉ)∑t=1n(yt−yˉ)2r_k = \dfrac{\sum_{t=1}^{n-k} (y_t - \bar{y})(y_{t+k} - \bar{y})}{\sum_{t=1}^{n} (y_t - \bar{y})^2}

y the series, n its length; the divisor n (not n − k) as in R's acf(). When the series has gaps, each sum runs over the pairs (or values) that are both present, and the lag-k sum is divided by the number of such pairs plus k, as R's acf(na.action = na.pass) does.

Alternatives

  • ARIMA forecast (ARIMA Forecast). You have chosen an order and want the model, its Ljung-Box residual check and a forecast.

Common misconceptions

Misconception

A bar inside the dashed lines means there is no autocorrelation at that lag.

Correction

The bound is approximate and is applied separately at each lag, with no allowance for looking at many lags: a bar inside it is not proof of no dependence, and about one bar in twenty crosses it by chance even when there is none. Read the pattern across lags and confirm with a model's Ljung-Box residual test.

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.3.1 Autocorrelation Plot, NIST/SEMATECH (2012).