# Optimizing a time-series with multiple predictors

I have a few questions about turing a univariate time series into a multivariate time series and optimizing the predictors. Here is the univariate data:

index
22
26
34
33
40
39
39
45
50
58
64
78
51
60
80
80
93
100
96
108
111
119
140
164
103
112
154
135
156
170
146
156
166
176
193
204


My first step here was to of course create a ts object in R and visualize the data:

tsData <- ts(data = dummyData, start = c(2012,1), end = c(2014,12), frequency = 12)

Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2012  22  26  34  33  40  39  39  45  50  58  64  78
2013  51  60  80  80  93 100  96 108 111 119 140 164
2014 103 112 154 135 156 170 146 156 166 176 193 204

plot(tsData)


I interpreted this plot as a deterministic time series with a trend and perhaps a bit of seasonality

Examining the acf and pacf plot confirms the trend component of the time series

My first question has to do with creating trend & seasonal variables for the time series using the decompose() function in R which yields the following plots:

I understand that the decompose() function in R has created a list of vectors for the trend, seasonal and random components of the original time series but what am I suppose to do with them? Should I cbind() them to my univariate data and model:

lm(index ~ trend + seasonal + random)

index     trend    seasonal       random
Jan 2012    22        NA -23.8940972           NA
Feb 2012    26        NA -19.4357639           NA
Mar 2012    34        NA   6.8350694           NA
Apr 2012    33        NA  -7.5399306           NA
May 2012    40        NA   4.3142361           NA
Jun 2012    39        NA   9.5017361           NA
Jul 2012    39  45.20833  -6.3524306   0.14409722
Aug 2012    45  47.83333  -0.8315972  -2.00173611
Sep 2012    50  51.16667  -1.1232639  -0.04340278
Oct 2012    58  55.04167   2.2517361   0.70659722
Nov 2012    64  59.20833  11.2100694  -6.41840278
Dec 2012    78  63.95833  25.0642361 -11.02256944
Jan 2013    51  68.87500 -23.8940972   6.01909722
Feb 2013    60  73.87500 -19.4357639   5.56076389
Mar 2013    80  79.04167   6.8350694  -5.87673611
Apr 2013    80  84.12500  -7.5399306   3.41493056
May 2013    93  89.83333   4.3142361  -1.14756944
Jun 2013   100  96.58333   9.5017361  -6.08506944
Jul 2013    96 102.33333  -6.3524306   0.01909722
Aug 2013   108 106.66667  -0.8315972   2.16493056
Sep 2013   111 111.91667  -1.1232639   0.20659722
Oct 2013   119 117.29167   2.2517361  -0.54340278
Nov 2013   140 122.20833  11.2100694   6.58159722
Dec 2013   164 127.75000  25.0642361  11.18576389
Jan 2014   103 132.75000 -23.8940972  -5.85590278
Feb 2014   112 136.83333 -19.4357639  -5.39756944
Mar 2014   154 141.12500   6.8350694   6.03993056
Apr 2014   135 145.79167  -7.5399306  -3.25173611
May 2014   156 150.37500   4.3142361   1.31076389
Jun 2014   170 154.25000   9.5017361   6.24826389
Jul 2014   146        NA  -6.3524306           NA
Aug 2014   156        NA  -0.8315972           NA
Sep 2014   166        NA  -1.1232639           NA
Oct 2014   176        NA   2.2517361           NA
Nov 2014   193        NA  11.2100694           NA
Dec 2014   204        NA  25.0642361           NA


When I use the auto.arima function in the forecast package is this all happening under the hood? It seems to me that the auto.arima() selected a MA(1) term and a differencing term to deal with the trend? Is my interpretation correct? What is drift?

plot(forecast(auto.arima(tsData, stepwise=FALSE)))

Forecast method: ARIMA(0,0,1)(0,1,0)[12] with drift

Model Information:
Series: tsData
ARIMA(0,0,1)(0,1,0)[12] with drift

Coefficients:
ma1   drift
0.9622  4.5780
s.e.  0.4698  0.4352

sigma^2 estimated as 176.6:  log likelihood=-44.52
AIC=95.05   AICc=96.25   BIC=98.58

Error measures:
ME     RMSE      MAE        MPE     MAPE       MASE
Training set 0.2459764 7.673429 4.967187 -0.7272714 4.661455 0.08876581
ACF1
Training set -0.0791942


What happens if I'm interested in expanding the model to include other time series variables such as spend_1 and spend_2? do I need to create trend and seasonal and random variables for each of these spend variables or do I just plug them into the auto.arima as external variables:

auto.ariam(tsData, xreg=spendData, stepwise= FALSE)

spend_1 spend_2
0   0
0   0
0   0
0   0
0   0
0   209
0   0
0   0
0   239
0   0
0   553
0   216
0   0
0   161
0   449
107 0
53  0
120 81
242 0
100 80
482 0
708 81
54  240
688 0
80  0
254 108
183 84
104 191
183 84
243 167
0   108
0   0
0   191
0   191
0   167
0   0


Once I build this multivariate time series model how do I interpret the coefficients for spend_1 and spend_2? How do to optimize them in order to maximize the index variable where the model was something like:

lm(index ~ spend_1 + spend_2 + trend + seasonal + random)


Thanks all for the advice please let me know if I can clarify anything further.

• That's a lot of questions. You might be better breaking it up a little. – Glen_b Jan 29 '15 at 21:55
• Yeah you are probably right. I wanted to explain the thought process and how I got to my questions. – moku Jan 29 '15 at 22:48