# Interpreting output from cross correlation function in R

I am working with two time series and I am interested in understanding the relationship between them. As a first step, I checked the cross correlation function (using ccf() in R).

The output of my code is shown below, where I'm running ccf(x,y). As I understand it, the conclusion here is that x at time t+k is negatively correlated with y at time t, where the lag, k = 2,3,4,5,6. I'm really surprised by this because my hypothesis was that x would lead to negative changes in y, and therefore I expected to see the negative correlation at negative values of the lag, k. In fact, I can't think of how changes in y might induce a change in x at some point in the future, despite what I see here.

Is my interpretation of the output correct? I assume so after running some tests of the form:

x <- rnorm(10)
ccf(x, y, na.action=na.omit)


But given how surprised by the result I feel, I want to double check.

Assuming that my interpretation is correct, could there any other explanation for this almost sinusoidal shape I see in the results? (I'm thinking that perhaps there is some feature to my data that could artificially cause these shapes - I've no intuition around this!).

I've got multiple independent experiments featuring these time series and I see a sinusoidal pattern in a majority of them (although the 'sine wave' has a different amplitude and frequency from plot to plot).

I'd also love to hear of alternative approaches to quantifying the relationship between two time-series.

• What's lead? Not sure what -lead(x) is doing...
– Jon
Jan 2, 2017 at 20:26
• Lead is a function that just shifts the series by one unit - I could do this to create a series with perfect anti-correlation in a known direction to the original x series Jan 2, 2017 at 21:16
• It was not clear as to what purpose lead was serving as it is not a base R function, nor which package it is coming from.
– Jon
Jan 3, 2017 at 0:08
• I'm curious, was there something lacking in my answer as this question has yet to be "answered"?
– Jon
Jan 4, 2017 at 22:47

set.seed(123)
x = arima.sim(model=list(0.2, 0, 0.5), n = 100)
y = arima.sim(model=list(0.4, 0, 0.4), n = 100)
ccf(x, y, type="correlation")


There are two time series, x and y. The correlation between the two occurs at $y_t$ and $x_{t \pm k}$ where $\pm k$ is a lag. In this example, at $k$ = -2, -7, -10, $x_{t + k}$ is significantly $negatively$ correlated with $y_t$.

The interpretation can be that x leads y at lags 2, 7 and 10. This is random data so the leads are meaningless.

Here are a few useful references for interpretation (my TS knowledge is a bit rusty): http://homepage.univie.ac.at/robert.kunst/prognos4.pdf

https://onlinecourses.science.psu.edu/stat510/node/74 To add more detail regarding your situation, it appears that your y_t lags x_{t+k}. The sinusoidal pattern you see in the CCF/ACF is typical for certain time series structures. How familiar are you with AR and MA models?

Regarding your hypothesis, it's unclear what data you have, and what the nature of that data may be, but if your time series have a nonstationary pattern, that will result odd ACF/PACF/CCF plots.

• Thanks very much - I think the part of your answer I was most interested in was the final part, concerning how typical the sinusoidal pattern is for certain time-series structures. I don't suppose you could point me in the direction of where I might be able to read and learn about this, could you? Similarly any resources around the comment about the time-series having a non-stationary pattern. These are the kinds of things I was hoping to uncover from the question (I was 95% sure my interpretation of the plot was correct after I generated the simulated lead and lagged data). Jan 8, 2017 at 6:23

I checked the ccf function with a small example from Box and Jenkins (1976, p 374-375).

x <- as.ts(c(11,7,8,12,14))
y <-as.ts(c(7,10,6,7,10))
zz <- ccf(x,y, lag.max=3)
zz


which gives:

Autocorrelations of series ‘X’, by lag

-3     -2     -1      0      1      2      3

-0.343 -0.121  0.631  0.139 -0.380 -0.074  0.260


So, we can see that ccf gives as positive lags the calculations of the Box-Jenkins book for negative lags and vice-versa.

From the book, we have -0.38 at lag -1 and 0.63 at lag 1.

However, the ccf function is correct from what it is said:

The lag k value returned by ccf(x, y) estimates the correlation between x[t+k] and y[t].

It is only a matter of definition, but it can be... misleading.