cross-correlation function and lagged regression
cross-correlation function and lagged regression
In the relationship between two time series (yt and xt), the series yt may be related to past lags of the x-series. The sample cross
correlation function (CCF) is helpful for identifying lags of the x-variable that might be useful predictors of yt.
In R, the sample CCF is defined as the set of sample correlations between xt+h and yt for h = 0, ±1, ±2, ±3, and so on. A negative
value for h is a correlation between the x-variable at a time before t and the y-variable at time t. For instance, consider h = −2.
The CCF value would give the correlation between xt-2 and yt.
When one or more xt+h , with h negative, are predictors of yt, it is sometimes said that x leads y.
When one or more xt+h, with h positive, are predictors of yt, it is sometimes said that x lags y.
In some problems, the goal may be to identify which variable is leading and which is lagging. In many problems we consider,
though, we’ll examine the x-variable(s) to be a leading variable of the y-variable because we will want to use values of the x-
Thus, we’ll usually be looking at what’s happening at the negative values of h on the CCF plot.
Note to Minitab Users: Minitab calculates its sample CCF as the set of sample correlations between xt and yt+h. Hence, the “x
leading y” side of the plot is for h positive. That’s where x comes before y in time.
In a full transfer function model, we model yt as potentially a function of past lags of yt and current and past lags of the x-
variables. We also usually model the time series structure of the x-variables as well. We’ll take all of that on next week. This
week we’ll just look at the use of the CCF to identify some relatively simple regression structures for modeling yt.
Sample CCF in R
If you wish to specify how many lags to show, add that number as an argument of the command. For instance, ccf(x,y,
Example: Southern Oscillation Index and Fish Populations in the southern hemisphere.
The text describes the relationship between a measure of weather called the Southern Oscillation Index (SOI) and “recruitment,”
a measure of the fish population in the southern hemisphere. The data are monthly estimates for n = 453 months. We see SOI as
The data are in two different files. The CCF below was created with these commands:
soi= scan("soi.dat")
rec = scan("recruit.dat")
soi=ts (soi)
rec = ts(rec)
ccf (soi, rec)
The most dominant cross correlations occur somewhere between h =−10 and about h = −4. It’s difficult to read the lags exactly
from the plot, so we might want to give an object name to the ccf and then list the object contents. The following two commands
ccfvalues = ccf(soi,rec)
ccfvalues
-1 0 1 2 3 4 5
6 7 8 9
0.011 0.025 -0.013 -0.086 -0.154 -0.228 -0.259 -0.232 -
0.144 -0.017 0.094
10 11 12 13 14 15 16
17 18 19 20
0.154 0.174 0.162 0.118 0.043 -0.057 -0.129 -0.156 -
0.131 -0.049 0.060
There are nearly equal maximum values at h = −5, −6, −7, and −8 with tapering occurring in both directions from that peak.
Note that the correlations in this region are negative, indicating that an above average value of SOI is likely to lead to a below
average value of “recruit” about 6 months later. And, a below average of SOI is associated with a likely above average recruit
Scatterplots
In the "astsa" library that we’ve been using, Stoffer included a script that produces scatterplots of yt versus xt+h for negative h
from 0 back to a lag that you specify. The command is lag2.plot.
The result of the command lag2.plot (soi, rec, 10) is shown below. In each plot, (recruit variable) is on
the vertical and a past lag of SOI is on the horizontal. Correlation values are given on each plot.
Regression Models
There are a lot of models that we could try based on the CCF and lagged scatterplots for these data. For demonstration purposes,
we’ll first try a multiple regression in which yt, the recruit variable, is a linear function of (past) lags 5, 6, 7, 8, 9, and 10 of the
SOI variable. That model works fairly well. Following is some R output. All coefficients are statistically significant and the R-
The residuals, however, have an AR(2) structure, as seen in the graph following the regression output. We might try the method
described in Lesson 8.1 to adjust for that, but we’ll take a different approach that we’ll describe after the output display.
Coefficients:
Next week we’ll discuss more about ways to interpret the CCF. One feature that will be described in more detail (with the “why”)
is that a peak in a CCF followed by a tapering pattern is an indicator that lag 1 and possibly lag 2 values of the y-variable may be
helpful predictors.
So, our try number 2 for a regression model will be to use lag 1 and lag 2 values of the y-variable as well as lags 5 through 10 of
The R-squared value has gone to about 94%. Not all sample coefficients are statistically significant. Although it’s dangerous to
drop too much from a model at once, we might think about dropping lags 7, 8 , 9, and maybe 10 of SOI from the model. You
might disagree with dropping lag 10 of SOI, but we’ll try it because it seems odd to have a “stray” term like that.
So our third attempt is to predict yt using lags 1 and 2 of itself and lags 5 and 6 of the x-variable (SOI). Here’s what happens:
Coefficients:
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 7.069 on 442 degrees of freedom
All sample coefficients are significant and the R-squared is about 94%. The ACF and PACF of the residuals look pretty good.
There’s a barely significant residual autocorrelation at lag 4 which we may or may not want to worry about.
Complications
The CCF pattern is affected by the underlying time series structures of the two variables and the trend each series has. It often
(perhaps most often) is helpful to de-trend and/or take into account the univariate ARIMA structure of the x-variable before
graphing the CCF. We’ll play with this a bit in the homework this week and will take it on more fully next week.
R code
Here’s the full R code for this handout. The alldata=ts.intersect() command preserves proper alignment between
all of the lagged variables (and defines lagged variables). The tryit=lm() commands are specifying the various regression
library(astsa)
soi= scan("soi.dat")
rec = scan("recruit.dat")
soi=ts (soi)
rec = ts(rec)
ccfvalues =ccf (soi, rec)
ccfvalues
lag2.plot (soi, rec, 10)
alldata=ts.intersect(rec,reclag1=lag(rec,-1), reclag2=lag(rec,-
2), soilag5 = lag(soi,-5),
soilag6=lag(soi,-6), soilag7=lag(soi,-7), soilag8=lag(soi,-8),
soilag9=lag(soi,-9),
soilag10=lag(soi,-10))
tryit = lm(rec~soilag5+soilag6+soilag7+soilag8+soilag9+soilag10,
data = alldata)
summary (tryit)
acf2(residuals(tryit))
tryit2 =
lm(rec~reclag1+reclag2+soilag5+soilag6+soilag7+soilag8+soilag9+so
ilag10,
data = alldata)
summary (tryit2)
acf2(residuals(tryit2))
tryit3 = lm(rec~reclag1+reclag2+ soilag5+soilag6, data = alldata)
summary (tryit3)
acf2(residuals(tryit3))