Skip to content

Time series and autocorrelation

A series remembers its past; plot it against a shifted copy of itself, and the correlation of that cloud, lag by lag, is its autocorrelation.

Helps to know firstCovariance and correlation

Helps to know first
This topic

First, the picture

Plot a series against itself one step later, then two, then ten. Watch the cloud loosen as the lag grows.

A series remembers its past

A series where each value is 0.8 times the last plus noise, 200 values (seed 10100).

Each value is 0.8 times the one before plus fresh noise. Plot every value against the value one step later.

lag
–
measured correlation
–
0.8 to the lag
–

Predict first. Plot each value against the next one. What shape will the cloud have?

0.00 / 12.20 s
Describe this picture

Three panels. The first shows a series of 200 values (seed 10100) in which each value is 0.8 times the one before plus fresh noise of variance 1. Beside it (below it on a phone) is its lag plot: the points (xk,xk+ℓ)(x_k,x_{k+\ell}), each value against the value ℓ\ell steps later, on a square from −5 to 5. The third panel dots the measured correlation of the lag plot for each lag, as a stem, over a dashed curve, 0.8ℓ0.8^\ell, and a shaded band from −0.139-0.139 to 0.1390.139. Before the clip a question asks what the lag plot looks like at lag 1: a round blob, a slanted band, or a thin line. A tap picks one and starts the clip. In the clip lag 1 appears and holds, a slanted band with correlation 0.8124; then, about one second per step, the lag steps to 10, each change a short morph of the cloud. The cloud loosens to a round blob, and a dot is added below at each lag. Readouts give the lag, the measured correlation and 0.8ℓ0.8^\ell. After the clip a slider sets the lag from 1 to 10.

Lag plots

Before the clip you guessed. At lag 1 the cloud is a slanted band: a high value tends to be followed by a high one. As the lag grows the band loosens, and by lag 10 it is nearly a round blob: the series has almost forgotten. The clip’s series measured 0.8124, 0.6236, 0.4729, 0.3520 and 0.2864 at lags 1 to 5, against 0.8, 0.64, 0.512, 0.410 and 0.328 in theory.

A time series is a sequence of values in time order: daily temperatures, monthly sales, a sensor read every second. I write the observed values xkx_k, k=1,…,nk=1,\dots,n, and the random series behind them XkX_k. Signal processing pages write the same thing x[n]x[n], with nn the time; here nn is the number of values.

The correlation of the lag plot at lag ℓ\ell measures how much the series remembers ℓ\ell steps back. Taken lag by lag, it is the series’ autocorrelation function.

Trend, season and noise

Many series are three things added together: a slow trend, a season that repeats with a fixed period, such as 12 months, and noise:

Xk=trendk+seasonk+noisek.X_k=\text{trend}_k+\text{season}_k+\text{noise}_k.

A series is stationary if its behaviour does not drift over time: the mean stays the same, and so does the covariance between values a fixed number of steps apart. Trends and seasons break stationarity. They are usually removed first, as Smoothing and seasonality shows, and what is left is studied for its memory.

The autocorrelation function

For a stationary series with mean μX\mu_X and variance σX2\sigma_X^2, the autocovariance at lag ℓ\ell is

CX[ℓ]=Cov{Xk,Xk+ℓ},C_X[\ell]=\mathrm{Cov}\{X_k,X_{k+\ell}\},

the same for every kk, and the autocorrelation is ρX[ℓ]=CX[ℓ]/CX[0]\rho_X[\ell]=C_X[\ell]/C_X[0]. It is 1 at lag 0. The lag goes in square brackets; the log-likelihood ℓ(θ)\ell(\theta) of Maximum likelihood is a different use of the letter.

From data, use the sample mean xˉ\bar x and divide every lag by the same total:

ρ^X[ℓ]=∑k=1n−ℓ(xk−xˉ)(xk+ℓ−xˉ)∑k=1n(xk−xˉ)2.\hat\rho_X[\ell]=\frac{\sum_{k=1}^{n-\ell}(x_k-\bar x)(x_{k+\ell}-\bar x)}{\sum_{k=1}^{n}(x_k-\bar x)^2}.

White noise. A series of independent values with mean 0 has ρX[ℓ]=0\rho_X[\ell]=0 at every lag except 0. Its sample autocorrelations are not exactly 0; for about 95 % of lags they fall within ±1.96/n\pm1.96/\sqrt n. For 200 values that band is ±0.139\pm0.139, the band in the picture.

Two extremes

A series with fading memory. The picture’s series is an AR(1) series, short for autoregressive of order 1:

Xk=ϕ Xk−1+Vk,X_k=\phi\,X_{k-1}+V_k,

where VkV_k is white noise with variance σV2\sigma_V^2 and ∣ϕ∣<1\lvert\phi\rvert<1. Its autocorrelation decays geometrically, ρX[ℓ]=ϕℓ\rho_X[\ell]=\phi^\ell, and its variance is σX2=σV2/(1−ϕ2)\sigma_X^2=\sigma_V^2/(1-\phi^2). Here ϕ\phi is a coefficient; signal processing pages use the letter for a phase.

A series with no forgetting. With ϕ=1\phi=1 each step adds fresh noise to the last value: a random walk. Its variance after kk steps is kσV2k\sigma_V^2, growing without limit, so it is not stationary, and its sample autocorrelation barely decays. Take its differences, xk−xk−1x_k-x_{k-1}, and you get the white noise back.

Two series that both wander can look related when they are not.

Describe this picture

Two panels. The first, “two independent walks”, draws two independent random walks of 200 steps (seed 10101), one above the other, each scaled to its own band; their correlation, 0.4736, is a readout. The second, “correlations of 1000 pairs”, is a histogram of the correlations of 1000 such independent pairs on an axis from −1 to 1: spread widely, with much of it far from 0. The stretches beyond ±0.5 are then shaded, and a readout gives their share: 37.7 %. There is no control.

In the clip, the first pair of walks has a correlation of 0.4736, and 377 of the 1000 independent pairs, 37.7 %, land beyond ±0.5.

Watch out

Two series that both trend will often show a large correlation even when they have nothing to do with each other: each one’s values are correlated with their own past, so the usual rules for a correlation do not apply. Remove the trends, or take differences, before comparing series.

Cross-correlation

The same idea compares two series. If yy is a delayed copy of xx plus noise, correlate yky_k with xk−ℓx_{k-\ell} for each lag ℓ\ell. The correlation peaks at the lag equal to the delay. This is the cross-correlation ρYX[ℓ]\rho_{YX}[\ell], written with the delayed series first, as in Correlation of the signal processing course.

Worked example

1. A short series. The series 1,2,4,5,4,3,2,31,2,4,5,4,3,2,3 has mean 3 and deviations −2,−1,1,2,1,0,−1,0-2,-1,1,2,1,0,-1,0, whose squares add to 12. The sums of lagged products are 5 at lag 1, −4-4 at lag 2 and −7-7 at lag 3, so

ρ^X[1]=512=0.4167,ρ^X[2]=−0.3333,ρ^X[3]=−0.5833.\hat\rho_X[1]=\tfrac{5}{12}=0.4167,\qquad \hat\rho_X[2]=-0.3333,\qquad \hat\rho_X[3]=-0.5833.

With only 8 values the white-noise band is ±1.96/8=±0.693\pm1.96/\sqrt8=\pm0.693, so none of these stands out: eight points cannot tell a pattern from noise. The plain correlation of the seven lag-1 pairs is 0.52960.5296, not 0.41670.4167, because it uses each set’s own mean and a different divisor; for long series the two agree closely.

2. The AR(1) series. With ϕ=0.8\phi=0.8 and σV=1\sigma_V=1, σX2=1/0.36=2.7778\sigma_X^2=1/0.36=2.7778 and σX=1.667\sigma_X=1.667. The autocorrelations are 0.8, 0.64, 0.512, 0.4096, 0.327680.8,\ 0.64,\ 0.512,\ 0.4096,\ 0.32768 at lags 1 to 5. For 100 values the band is ±0.196\pm0.196, and the theory drops below it at lag 8, where 0.88=0.1680.8^8=0.168.

3. Many lags of white noise. Check 20 lags against a 95 % band: on average one falls outside, and the chance that at least one does is 1−0.9520=0.64151-0.95^{20}=0.6415, the many-tests problem of p-values.

4. A delay. If yy is xx delayed by 3 samples plus noise, ρYX[ℓ]\rho_{YX}[\ell] peaks at ℓ=3\ell=3.

5. Trend and season. Monthly data with a rising trend and a yearly cycle have an autocorrelation that stays high at every lag and swings with period 12, peaking at lags 12, 24 and so on.

Try it yourself. For ϕ=0.8\phi=0.8, ρX[2]=0.64\rho_X[2]=0.64. For 400 values the band is ±0.098\pm0.098. A random walk of unit steps has variance 100 after 100 steps.

Where you’ll meet this

Is it noise? Checking that a signal, or the residuals of a fitted model, has no autocorrelation beyond the band is a standard check that nothing systematic is left. Linear regression assumes exactly that.

Delays and echoes. The delay between two microphones, two sensors or a sound and its echo is the lag of a cross-correlation peak.

Hidden periods. A peak in the autocorrelation at lag PP reveals a cycle of period PP: a machine’s vibration, a heartbeat, a weekly pattern in web traffic.

In signal processing · random processes

Signal processing treats noise as a random process with an autocorrelation in the same sense, writing it Rx[ℓ]R_x[\ell] for a signal x[n]x[n]. Random processes and Correlation in the signal processing course use it to describe noise and find delays.

Where this leads · a positive definite matrix

Arrange the autocovariances CX[ℓ]C_X[\ell] in a matrix with CX[∣p−q∣]C_X[\lvert p-q\rvert] in row pp and column qq. It is symmetric, constant along each diagonal, and positive definite, as a covariance matrix is unless some mix of the values has no spread: for AR(1) with ϕ=0.8\phi=0.8 the 3×33\times3 autocorrelation matrix has determinant (1−0.64)2=0.1296>0(1-0.64)^2=0.1296>0. Positive definite matrices in the linear algebra course explain why.

Reference card

QuantityFormulaNotes
Decompositiontrend + season + noiseremove trend and season first
Stationarymean and lagged covariances do not drift
AutocovarianceCX[ℓ]=Cov{Xk,Xk+ℓ}C_X[\ell]=\mathrm{Cov}\{X_k,X_{k+\ell}\}
AutocorrelationρX[ℓ]=CX[ℓ]/CX[0]\rho_X[\ell]=C_X[\ell]/C_X[0]1 at lag 0
Sample versionρ^X[ℓ]\hat\rho_X[\ell], divide every lag by ∑(xk−xˉ)2\sum(x_k-\bar x)^2
White noise band±1.96/n\pm1.96/\sqrt nabout 95 % of lags inside
AR(1)ρX[ℓ]=ϕℓ\rho_X[\ell]=\phi^\ell, σX2=σV2/(1−ϕ2)\sigma_X^2=\sigma_V^2/(1-\phi^2)fading memory
Random walkvariance kσV2k\sigma_V^2not stationary; difference it
Cross-correlationpeaks at the delaydelayed series first

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look