Cross-Correlation
The Cross-Correlation of two time series x_t and y_t at lag h, \rho_{xy}(h), is the correlation between x_{t+h} and y_t, one series set against the other shifted by h periods. Read across the lags as the cross-correlation function (ccf), it shows whether one series leads the other.
The cross-covariance function (ccvf) is the covariance of the pairs (x_{t+h}, y_t):
\gamma_{xy}(h) = \mathrm{Cov}(x_{t+h},\, y_t) = E\big[(x_{t+h} - \mu_x)(y_t - \mu_y)\big]
\mu_xand\mu_yare the means of the two series.
It depends on the lag h alone when the two series are jointly stationary: each is stationary, and the cross-covariance does not change with t. The cross-correlation is
\rho_{xy}(h) = \frac{\gamma_{xy}(h)}{\sqrt{\gamma_x(0)\,\gamma_y(0)}}
\gamma_x(0)and\gamma_y(0)are the variances of the two series.-1 \le \rho_{xy}(h) \le 1.
With y = x the ccf is the ACF. Unlike the ACF, the ccf is not symmetric: \rho_{xy}(h) \ne \rho_{xy}(-h) in general. Instead \rho_{xy}(h) = \rho_{yx}(-h), so the plot runs over negative and positive lags, and swapping the two series mirrors it.
Sample cross-correlation
From n observations of each series, the sample cross-covariance at lag h \ge 0 is
\hat{\gamma}_{xy}(h) = \frac{1}{n}\sum_{t=1}^{n-h}(x_{t+h} - \bar{x})(y_t - \bar{y})
\bar{x}and\bar{y}are the sample means.
As in the sample ACF, the sum has n - h terms but is divided by n. Negative lags come from \hat{\gamma}_{xy}(-h) = \hat{\gamma}_{yx}(h). The sample cross-correlation is
\hat{\rho}_{xy}(h) = \frac{\hat{\gamma}_{xy}(h)}{\sqrt{\hat{\gamma}_x(0)\,\hat{\gamma}_y(0)}}
\hat{\gamma}_x(0)and\hat{\gamma}_y(0)are the lag-0 sample autocovariances, each series' sum of squared deviations divided byn.
The autocovariances at lag h do not enter the denominator.
What are the sample cross-correlations at lags
-1,0and1, and which series leads? Over six quarters an insurer wrotex_t = 3, 6, 4, 7, 5, 5(hundreds of new policies) and receivedy_t = 5, 3, 6, 4, 6, 6(tens of claims).Answer
- Both means are
5, so the deviations are(-2, 1, -1, 2, 0, 0)forxand(0, -2, 1, -1, 1, 1)fory.- Their sums of squares are
10and8. The1/nfactors cancel, so each\hat{\rho}_{xy}(h)is a sum of deviation products divided by\sqrt{10 \times 8} = 8.944.- Lag
-1pairsx_{t-1}withy_t:(-2)(-2) + (1)(1) + (-1)(-1) + (2)(1) + (0)(1) = 8, so\hat{\rho}_{xy}(-1) = 8/8.944 = 0.894.- Lag
0pairsx_twithy_t:0 - 2 - 1 - 2 + 0 + 0 = -5, so\hat{\rho}_{xy}(0) = -5/8.944 = -0.559.- Lag
1pairsx_{t+1}withy_t:0 + 2 + 2 + 0 + 0 = 4, so\hat{\rho}_{xy}(1) = 4/8.944 = 0.447.- Lag
-1is the peak, so new policies lead claims by one quarter.- The lag-0 correlation is negative, so correlating the two columns side by side would have missed the relationship.
Reading lead and lag
In R, ccf(x, y) at lag k estimates the correlation between x_{t+k} and y_t, and type = "covariance" gives the ccvf. A peak at a negative lag h = -\ell means x_{t-\ell} moves with y_t, so x leads y by \ell periods. A peak at a positive lag means x lags y. A negative peak means the two move in opposite directions. R returns and plots the lag in units of time, not observations, so on a quarterly ts object a one-quarter lead peaks at -0.25.
The peak marks the lead because, if y_t = A x_{t-\ell} + w_t with noise w_t uncorrelated with x_t, then \gamma_{yx}(h) = A\,\gamma_x(h - \ell). The cross-covariance is the input's own autocovariance moved to lag \ell, and it is largest in absolute value there.
Significance bounds
If x_t and y_t are independent and at least one of them is iid white noise (independent, not merely uncorrelated), \hat{\rho}_{xy}(h) is approximately normal with mean 0 and standard deviation 1/\sqrt{n}. Values outside \pm 2/\sqrt{n} then point to a real relationship.
When both series carry their own structure (a trend or a seasonal cycle), independent series can show sizeable cross-correlations. Remove the trend, or prewhiten one series (strip its own structure so that what is left is white noise), before reading the plot.
Which of these cross-correlations are significant, and what do they say? Over
n = 100months,x_tis the monthly change in a construction-cost index, already prewhitened to iid white noise, andy_tis the monthly change in average property claim severity. The sample variances are\hat{\gamma}_x(0) = 0.36and\hat{\gamma}_y(0) = 2.25, and the sample cross-covariances are:
h-3-2-1012\hat{\gamma}_{xy}(h)0.0630.4050.1080.045-0.0810.027Answer
- The denominator is
\sqrt{0.36 \times 2.25} = 0.9.- Dividing each cross-covariance by
0.9gives\hat{\rho}_{xy}(h) = 0.07,\ 0.45,\ 0.12,\ 0.05,\ -0.09,\ 0.03forh = -3, \ldots, 2.x_tis iid white noise, so the bounds\pm 2/\sqrt{100} = \pm 0.2apply.- Only lag
-2is outside them, so cost changes lead severity changes by two months.- The positive sign says they move in the same direction, which makes
x_{t-2}a candidate predictor ofy_t.
Use in forecasting
A related variable that leads the one to be forecast by one or more periods is an efficient basis for a forecast. The closer the relationship and the longer the lead, the better. Cowpertwait's example is Australian building activity, which tends to lag building approvals by about a quarter. The lags the ccf picks out are candidate predictors in a lagged regression of y_t on past values of x_t.
Reading the sign of the lag backwards In R's
ccf(x, y), a peak at a negative lag meansxleadsy. Minitab shiftsyinstead, so its plot reads the other way round.