Search

Search papers and lessons

Autocorrelation Function

Level 3 · 10 min read

The autocorrelation function measures how strongly a stationary process is correlated with a copy of itself shifted by h steps, showing how long its memory lasts.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Linear algebra
  • Calculus
  • Stochastic processes
  • Sign in to see your progress

TL;DR

The autocorrelation function of a stationary process says how strongly its value now is tied to its value a fixed number of steps later. At lag hh it is the correlation between XtX_t and Xt+hX_{t+h}: a number from −1-1 to 11 that starts at 11 for lag 00 and fades as the gap grows. A slow fade means long memory; a fast fade means the process forgets quickly.

Where you'll see it: in checking whether the leftover errors of a forecasting model are really random, in estimating how many independent samples a Markov chain Monte Carlo run has produced, and in the Fluctuation-Dissipation Theorem of physics.

This lesson explains a statistical quantity. It is not advice about any particular data set or decision.

Intuition

Correlation with your own past

Take the daily high temperature in a city. Today's value tells you something about tomorrow, because weather persists. Yesterday tells you more about today than last week does, and last month tells you almost nothing. The autocorrelation function puts a number on that fading relevance.

You already know how correlation works for two different quantities. Pair up the values, measure how they move together with Covariance, and scale the result to lie between −1-1 and 11. Autocorrelation does the same thing to one series against a shifted copy of itself. Pair each value with the value hh steps later. The shift hh is called the lag.

If a series is 3,5,4,6,…3, 5, 4, 6, \dots, the lag-1 pairs are (3,5)(3, 5), (5,4)(5, 4), (4,6)(4, 6) and so on. The lag-2 pairs skip one step: (3,4)(3, 4), (5,6)(5, 6). Lag 0 pairs every value with itself, so the correlation there is always 1.

A picture of the memory

The result is usually drawn as a bar or dot chart against the lag, called a correlogram. Its shape is a fingerprint of the process. The plot below compares two autoregressive processes, each one a fraction φ\varphi of its previous value plus fresh noise. The dots show the correlogram of the first at whole-number lags.

−6−4−2024600.51lag hautocorrelation
  • φ = 0.5
  • φ = 0.9
Correlograms of two AR(1) processes. Dots mark lags 0 to 3 for φ = 0.5. The φ = 0.9 curve fades far more slowly, so its memory is longer.

Both curves start at 1 and fall off, because a value is most like its immediate neighbours. The curve with the larger φ\varphi holds on longer. That single curve is what this lesson is about.

The math

Definition

Definition: Autocovariance and autocorrelation

For a weakly stationary process {Xt}\{X_t\} with mean μ\mu and variance γ(0)\gamma(0), the autocovariance at lag hh is

γ(h)=Cov(Xt,Xt+h)=E[(Xt−μ)(Xt+h−μ)],\gamma(h) = \mathrm{Cov}(X_t, X_{t+h}) = \mathbb{E}\big[(X_t - \mu)(X_{t+h} - \mu)\big],

and the autocorrelation function (ACF) is

ρ(h)=γ(h)γ(0).\rho(h) = \frac{\gamma(h)}{\gamma(0)}.

Here tt is a time index, and h=0,1,2,…h = 0, 1, 2, \dots is a whole number of steps. The notation E\mathbb{E} is the expected value. Because the process is stationary, the right-hand side depends only on the lag hh and not on tt. That is why one curve ρ(h)\rho(h) can describe the whole series.

Three facts follow from the definition:

  • ρ(0)=1\rho(0) = 1, because a value is perfectly correlated with itself.
  • ρ(−h)=ρ(h)\rho(-h) = \rho(h). Looking backwards by hh gives the same pair of values, so the curve is symmetric.
  • −1≤ρ(h)≤1-1 \le \rho(h) \le 1, since ρ(h)\rho(h) is the correlation between two random variables.

Estimating it from data

We never know μ\mu or γ\gamma exactly. Given observations x1,…,xnx_1, \dots, x_n with sample mean xˉ\bar{x}, the standard estimate is

r(h)=∑t=1n−h(xt−xˉ)(xt+h−xˉ)∑t=1n(xt−xˉ)2.r(h) = \frac{\displaystyle\sum_{t=1}^{n-h} (x_t - \bar{x})(x_{t+h} - \bar{x})}{\displaystyle\sum_{t=1}^{n} (x_t - \bar{x})^2}.

The numerator has n−hn-h products, because only n−hn-h pairs exist at lag hh. The denominator uses all nn squared deviations. Some texts divide the numerator by n−hn-h (and the denominator by nn) instead; the numbers then differ slightly, and the convention above is the one most software uses.

Autoregressive example

Take the AR(1) model Xt=φXt−1+εtX_t = \varphi X_{t-1} + \varepsilon_t with ∣φ∣<1|\varphi| \lt 1 and white noise εt\varepsilon_t of variance σ2\sigma^2 (see ARMA Model and White Noise). Its stationary variance is γ(0)=σ2/(1−φ2)\gamma(0) = \sigma^2/(1-\varphi^2), from the Stationary Process lesson. Its autocorrelation has a clean form, and it is worth deriving once.

Repeat the recursion hh times:

Xt+h=φhXt+∑j=0h−1φjεt+h−j.X_{t+h} = \varphi^h X_t + \sum_{j=0}^{h-1} \varphi^j \varepsilon_{t+h-j}.

Every noise term in the sum happens after time tt, so each one is uncorrelated with XtX_t. Only the first term carries a link back to XtX_t. Therefore

γ(h)=Cov(Xt,Xt+h)=φhγ(0),ρ(h)=φ∣h∣.\gamma(h) = \mathrm{Cov}(X_t, X_{t+h}) = \varphi^h \gamma(0), \qquad \rho(h) = \varphi^{|h|}.

The memory decays geometrically, the same pattern as the Geometric Series of powers of φ\varphi. A negative φ\varphi makes the correlogram alternate in sign, but φ2\varphi^2 is positive, so the sign of ρ(2)\rho(2) is always positive.

Integrated autocorrelation time

Summing the correlogram gives one number for how much memory a series has:

τ=1+2∑h=1∞ρ(h).\tau = 1 + 2\sum_{h=1}^{\infty} \rho(h).

This is the integrated autocorrelation time. Roughly, nn correlated observations are worth about n/τn/\tau independent ones. For the AR(1) model the sum is geometric, ∑h≥1φh=φ/(1−φ)\sum_{h \ge 1} \varphi^h = \varphi/(1-\varphi), so

τ=1+2φ1−φ=1+φ1−φ.\tau = 1 + \frac{2\varphi}{1-\varphi} = \frac{1+\varphi}{1-\varphi}.

This is the quantity behind the effective sample size in Markov Chain Monte Carlo and Metropolis Algorithm samplers.

Worked examples

Example
Tiny: an alternating series

Take the eight values 1,−1,1,−1,1,−1,1,−11, -1, 1, -1, 1, -1, 1, -1, so n=8n = 8.

  1. The sample mean is xˉ=0\bar{x} = 0, because four values are +1+1 and four are −1-1.
  2. The denominator is ∑xt2=8\sum x_t^2 = 8.
  3. At lag 1 there are n−1=7n - 1 = 7 pairs. Each pair is (1)(−1)(1)(-1) or (−1)(1)(-1)(1), so each product is −1-1. The numerator is −7-7, and r(1)=−7/8=−0.875r(1) = -7/8 = -0.875.
  4. At lag 2 there are 66 pairs. Each pair matches in sign, so each product is +1+1. The numerator is 66, and r(2)=6/8=0.75r(2) = 6/8 = 0.75.
  5. At lag 3 there are 55 pairs, each with product −1-1, so r(3)=−5/8=−0.625r(3) = -5/8 = -0.625.

Interpretation. The series is strongly anti-correlated at odd lags and strongly correlated at even lags. Its memory lives in the alternation, so the correlogram flips sign with each step while its size fades slowly.

Example
Standard: AR(1) with φ = 0.8 and σ² = 1

For this model γ(0)=1/(1−0.64)=2.778\gamma(0) = 1/(1 - 0.64) = 2.778, and ρ(h)=0.8∣h∣\rho(h) = 0.8^{|h|}.

  1. Lag 1: ρ(1)=0.8\rho(1) = 0.8.
  2. Lag 2: ρ(2)=0.64\rho(2) = 0.64.
  3. Lag 5: ρ(5)=0.85=0.328\rho(5) = 0.8^5 = 0.328.
  4. Lag 10: ρ(10)=0.810≈0.107\rho(10) = 0.8^{10} \approx 0.107.
  5. Half-life: solve 0.8h=0.50.8^h = 0.5, which gives h=ln⁡0.5/ln⁡0.8≈3.1h = \ln 0.5 / \ln 0.8 \approx 3.1. The correlation halves after about three steps.
  6. Integrated time: τ=(1+0.8)/(1−0.8)=1.8/0.2=9\tau = (1 + 0.8)/(1 - 0.8) = 1.8/0.2 = 9.

Interpretation. A value still has about 64 percent of its link to the present after two steps, and only about 11 percent after ten. Nine correlated observations are worth about one independent one.

Example
Realistic: a sampler's effective sample size (illustrative)

Suppose a Markov chain Monte Carlo run produces N=10,000N = 10{,}000 draws. Assume, for illustration, that the draws behave like an AR(1) process with φ=0.9\varphi = 0.9. In practice τ\tau is estimated from the sample itself, but the arithmetic is the same.

  1. Integrated time: τ=(1+0.9)/(1−0.9)=1.9/0.1=19\tau = (1 + 0.9)/(1 - 0.9) = 1.9/0.1 = 19.
  2. Effective sample size: N/τ=10000/19≈526N/\tau = 10000/19 \approx 526.
  3. To get the accuracy of 10,000 independent draws, you would need about 10000×19=190,00010000 \times 19 = 190{,}000 steps.

Interpretation. The average of these draws has the precision of about 526 independent ones. Checking the autocorrelation before trusting an average is therefore part of the job, not a formality.

Tradeoffs and failure modes

The ACF is a diagnostic. It answers well when its assumptions hold and misleads when they do not.

SituationWhat goes wrongBetter choice
Series with a trend or seasonal cycleThe ACF stays large across many lags, even between unrelated series, because the shared trend does the workRemove the trend or seasonality, or difference the series, then read the ACF
Random walkThe process is not stationary, and its sample ACF stays near 1 for many lagsDifference the series (Random Walk) and examine the differences
Short recordSample values at large lags are noisy and unreliableUse fewer lags, or collect more data
Nonlinear dependenceZero autocorrelation does not mean independence. Values can be uncorrelated while their squares are strongly linkedExamine the ACF of absolute or squared values as well
Many lags checked at onceWith 20 lags, about one spike outside the band is expected by chanceJudge the overall pattern, not a single spike

For white noise the sample ACF at each lag has a standard error of about 1/n1/\sqrt{n}. A common rule of thumb draws bands at ±2/n\pm 2/\sqrt{n}. Spikes outside those bands suggest real memory. Spikes inside them are compatible with no memory at all.

The main trap is reading the first lag alone. Two series can have the same ρ(1)\rho(1) and very different memories beyond that. Look at the full curve, and remember that the partial autocorrelation, which removes the effect of the intermediate lags, is a separate tool used for choosing model orders.

History

Autoregressive models were first used for time series by George Udny Yule in the 1920s, to describe cycles such as sunspot counts. Work in the early 1930s by Norbert Wiener and, in 1934, by Aleksandr Khinchin tied the autocorrelation function to the spectrum of a stationary process; this is the spectral view in the Wiener–Khinchin theorem.

The correlogram became a working tool later. In the 1960s and 1970s George Box and Gwilym Jenkins showed how to choose a model by reading the ACF and partial ACF, then fit and check it. Their 1970 book made the method standard in forecasting and economics. The ACF caught on because it turns a single record into a picture of memory that anyone can read.

Recap

The autocorrelation function ρ(h)\rho(h) is the correlation between a stationary process and itself shifted by hh steps. It starts at 1, is symmetric, and stays between −1-1 and 11. For an AR(1) process it decays as φ∣h∣\varphi^{|h|}, and summing it gives the integrated autocorrelation time τ\tau, which sets how many independent samples a correlated series is worth. The correlogram is the first diagnostic for memory, and it is the tool behind effective sample size in Markov Chain Monte Carlo and the response functions in Linear Response Theory.

Check yourself

QuestionWhat is ρ(0)\rho(0), and why must ρ(−h)\rho(-h) equal ρ(h)\rho(h)?Show answer

ρ(0)=γ(0)/γ(0)=1\rho(0) = \gamma(0)/\gamma(0) = 1, because a value is perfectly correlated with itself. The symmetry comes from the definition: Cov(Xt,Xt+h)\mathrm{Cov}(X_t, X_{t+h}) and Cov(Xt,Xt−h)\mathrm{Cov}(X_t, X_{t-h}) describe the same pair of values, one shifted forwards and one backwards. Stationarity makes both depend only on the gap ∣h∣|h|.

QuestionAn AR(1) process has φ=−0.6\varphi = -0.6. What is ρ(2)\rho(2), and why is its sign positive?Show answer

ρ(2)=φ2=(−0.6)2=0.36\rho(2) = \varphi^2 = (-0.6)^2 = 0.36. Two steps is an even number, so the minus sign from φ\varphi is squared away. The correlogram of this process alternates sign at each lag, but at even lags the sign is positive.

QuestionA series has a strong upward trend. Its sample ACF is about 0.9 at lags 1 through 20. Why does this not show that the series has long memory in its dynamics?Show answer

A trend makes every value resemble every other value, because they all lie on the same rising line. That pushes the sample ACF high at many lags even when the fluctuations around the trend are unrelated. Removing the trend, for example by differencing, and then reading the ACF of the remainder shows the real memory.

QuestionA Markov chain run gives 20,000 draws, and its integrated autocorrelation time is estimated at τ=40\tau = 40. What is the effective sample size, and what does it mean for the estimate of a mean?Show answer

The effective sample size is N/τ=20000/40=500N/\tau = 20000/40 = 500. The average of the draws is about as precise as the average of 500 independent draws, not 20,000. The standard error is therefore larger than a naive calculation that ignored autocorrelation would suggest.

Sources