Autocorrelation and the ACF
Today let's understand autocorrelation and the ACF, using simple and practical examples.
Here is the running example for the whole lesson: quarterly beer production in Australia, from 1992 Q1 to 2010 Q2, in megalitres (a megalitre is a million litres). That's 74 quarters, published by the Australian Bureau of Statistics.
Look at the line. It rises and falls again and again, and it never quite settles at one level for long. That raises the question this whole lesson answers: does each quarter's value actually depend on the quarters that came before it, or is that rise and fall just noise with no memory at all?
What autocorrelation asks: does a value depend on its own past?
Build that same series properly, as a tsibble, and you can start asking sharper questions of it than a single line chart can answer.
A lag is just "how many periods back". Lag 1 means one quarter earlier, lag 2 means two quarters earlier, and so on.
Autocorrelation asks a very specific question using that idea: does the value at time \(t\) depend on the value some lag \(k\) periods earlier, at time \(t-k\)? And the way you check that is not new at all. You already know how to check whether two things move together: correlation. Autocorrelation is nothing more than the ordinary Pearson correlation you already know, computed between a series and its own lagged copy.
Written with subscripts, autocorrelation at lag \(k\), called \(r_k\), is the correlation between \(y_t\) (the value now) and \(y_{t-k}\) (the value \(k\) periods earlier).
Here's the beer series built as a tsibble, with a new column holding each row's own lag-1 value next to it.
Look at the Beer_lag1 column. Row 2's value there, 443, is exactly row 1's Beer value. Every row's lag-1 column is just the row above its own Beer value, shifted down by one. The first row has nothing before it, so its lag is NA (not available).
That's all a lag is: the same series, copied and shifted down by \(k\) rows. Autocorrelation at lag \(k\) is just the correlation between the Beer column and this shifted copy.