# Model/explain a time series as a function of other time series - R

I have six time series, all made of daily historical data. All of them cover the same period and the same days, they are all about 2700 days long. I want to explain one of the time series as a function of the other five, every day; i.e. for each day "i" I'd like to obtain a functional relationship of this sort:

ts1_i = f(ts2_i, ts3_i, ts4_i, ts5_i, ts6_i)


I am not sure what method or approach is more adequate for doing so, and if I should use machine learning techniques (I am new on it). As a starting point, I have performed PCA analysis on the entire data set of six time series, and rank correlation tests for each pairs. (PS: I use R, it would be great to have suggestions about R functions and packages)

• What is your goal? Inference, prediction, or forecast? R package nlme offers regression models that include a model for residual autocorrelation. Jun 27, 2016 at 14:40
• @Roland my aim is to understand how each time series influences ts1, and use those that have most of the influence on ts1 for predictions. I'd say my goal is dimensionality reduction and prediction
– stem
Jun 27, 2016 at 14:51
• @stem Do you just want contemporaneous relationship, or intertemporal dependence, ie. $x^1_t = f( x^2_t, x^2_{t-1}, ...., x^3_t, x^3_{t-1},...., x^6_t, x^6_{t-1}....)$ Jun 28, 2016 at 18:48
• @horaceT no intertemporal dependence is required, only contemporaneous relations
– stem
Jun 29, 2016 at 20:46

Box-Jenkins laid out an approach to do this in their text book published in 1970 called "Transfer Function modeling". In short, you build a model for each causal and then use the residuals to find correlation with the Y variable. Don't forget to look for outliers too as they exist.

• Thanks @Tom-Reilly, I have never used this technique and I am going to search for more information about it. I was also looking for predictability of the ts1 using the other time series, or better for how much of the ts1 the other time series can account for. Does the Transfer Function modeling help with that?
– stem
Jun 27, 2016 at 14:37
• Yes, it will help. Jun 27, 2016 at 15:31

Before you toss your time series into arimax, make sure you check if they are stationary. This is a crucial assumption for time series regression. If some of the time series on the RHS are $I(1)$, you'd get meaningless result, the so-called spurious regression in the econometrics literature.

You can see it with a few lines of 'R' codes. Try use the S&P 500 for $y_t$ and Nasdaq for $x_t$.

$y_t = \alpha + \beta x_t + \epsilon$

As you toss in more and more data, the regression R squared gets better and better. In fact, as $N \rightarrow \infty$, the p-value of your coefficient approaches zero and your $R^2$ approaches 1.

This is a famous paper :

Phillips, P. C. (1986). Understanding spurious regressions in econometrics. Journal of econometrics, 33(3), 311-340.

The simplest model I can think of for this problem is ARMAX, which is a bit like an ARMA model with exogenous parameters stuck on the end. However, there doesn't actually seem to be a direct implementation of these models in R.

Rob Hyndman (who occasionally posts here) has a nice blog post describing these models. As Rob points out, ARMAX is a special case of the transfer function model mentioned by Tom Reilly. In fact, the TSA package has a function called arimax, which actually fits transfer functions under the guise of ARIMAX.

• thanks I'll check the function and the blog. As I wrote above, my aim is to understand how each time series influences ts1, and use those that have most of the influence on ts1 for predictions. I have a dual goal, that is dimensionality reduction and prediction
– stem
Jun 27, 2016 at 15:22
• @RichardHardy perhaps not. I will update Jun 28, 2016 at 18:19
• @RichardHardy nope you're just keeping me honest! Jun 28, 2016 at 19:50