# How do I investigate how long it takes one variable to affect another in a time series

I am a total newbie when it comes to time series, so it is quite possible this question is duplicated somewhere else, only that I cannot find it because I don't know what this feature is called.

### My data:

I have weekly measurements of a variable "change in rank". I also have weekly measurements of another variable loosely described as "change in goodness". I believe that "change in rank" is dependent on "change in goodness", but I also believe that whenever "goodness" improves, it takes some time before rank improves. A simplistic representation of the data would look like this:

change_in_rank = c(0,0,0,0,-10,0,0,0)
change_in_goodness = c(0,2,0,0,0,0,0,0)


where this constructed example shows that a improvement of 2 in goodness took 3 time steps to lead to an improvement in rank.

### My question:

What analysis method do I use to detect whether such a relationship actually exists between "change in goodness" and "change in rank", and if such a relationship exists, how do I find out how long it takes for a change in "goodness" to flow on to a change in rank.

### The motivation behind this question:

Some additional, non necessary background: it is claimed that search engine optimisation takes time to affect your site's ranking in Google. E.g.:

"Why does SEO take so long?"

I am trying to find a statistical way of calculating how long it takes for a change in a site to actually reflect in the site's Google ranking.

### More motivation:

Slightly different type of data but similar question...

"How long does it take before a change in diet starts to take effect?"

• some potentially relevant topics to search and see if they're useful to you: cross-correlation function (or CCF), transfer function models, intervention models (you'll need to add something like "time series" for that or you'll get a bunch of psych stuff), and distributed lag models. – Glen_b Jul 24 '14 at 1:40
• search "cross wavelet transform" , wavelet coherence ;-) – Ivan Kshnyasev Jul 30 '14 at 15:52
• Alex, what about the answers you have, are they still lacking or could one be accepted to finish the thread? – Richard Hardy Jul 26 '17 at 8:42

Try looking at cross-correlations between the two series:
correlate series 1 with series 2;
correlate series 1 with series 2 lagged by 1 period;
correlate series 1 with series 2 lagged by 2 periods;
etc.
Explore as many lags as can reasonably be expected to be plausible in the context you are in. Also, depending on the context of the application, you may need to look at lagged series 1 against (non-lagged) series 2.
Note which lag gives the highest absolute correlation - this will be a rough estimate of the "true" lag.

It is comfortable to inspect the cross-correlations visually. In R, you may use function ccf(.) to obtain and plot the correlogram.

• (+1) Same approach is proposed here for a similar (seemingly duplicated) question. A more detailed description of the overall idea can be found here. Related post also here, which gives an example of the interpretation of the cross-correlation function. Some technical details for the implementation of this approach are discussed in this post. – javlacalle Sep 30 '14 at 18:06

As often in regression, there are several ways to proceed, but the most straightforward one is probably given by the moving-average approach. That is, you assume a linear (linear-in-the-parameters) relationship between your target $y_t$ (change_in_rank) and your regressand $x_t$ (change_in_goodness) given by

$$y_t = \sum_{i=1}^p \beta_{t-k} \, x_{t-k}$$

Here, the input-parameter $p$ determines the maximum lag-time. Next, you fit your model using some seleted data of the form $(x_{j-1}, \ldots, x_{j-p}; y_j)$ where $j\in \{1,\ldots, N_\text{data}\}$, e.g. by using standard least-squares regression.

Finally, you can use the result either to forecast (in this case more flexible models like neural networks might be doing better), or to interprete the result using the fitted parameters $\boldsymbol \beta$ (--in interpretability, almost nothing beats linear models).

If that model is not flexible enough, you can extend it to higher dimensions and more general functions $f(x_{t-1}, \ldots, f_{t-p})$, and also to autoregressive-moving-average models where you further include some previous regression results $y_j$ for $j<t$.