# Forecast time series data with external variables

Currently I'm working on a project to do forecasting of a time series data (monthly data). I am using R to do the forecasting. I have 1 dependent variable (y) and 3 independent variables (x1, x2, x3). The y variable has 73 observations, and so does the other 3 variables (alos 73). From January 2009 to January 2015. I have checked correlations and p-value, and it's all significant to put it in a model. My question is: How can I make a good prediction using all the independent variables? I don't have future values for these variables. Let's say that I would want to predict what my y variable in over 2 years (in 2017). How can I do this?

I tried the following code:

    model = arima(y, order(0,2,0), xreg = externaldata)


Can I do a prediction of the y value over 2 years with this code?

I also tried a regression code:

    reg = lm(y ~ x1 + x2 + x3)


But how do I take the time in this code? How can I forecast what my y value will be over lets say 2 years? I am new to statistics and forecasting. I have done some reading and cam across the lag value, but how can I use a lag value in the model to do forecasting?

Actually my overall question is how can I forecast a time series data with external variables with no future value?

• Never use regression with time series data. Use a Transfer Function model approach. – Tom Reilly May 17 '16 at 15:16
• Hi sir, can you tell me more about a transfer function model? And why should I never use regression with time series data? Most studies suggest using regressing with time series. – S.B May 18 '16 at 12:36
• A Transfer Function model is explained in the Box-Jenkins textbook in Chapter 10. The goal is to build a model for each causal(pre-whitening) and then use the residuals to find correlations against Y(cross correlation). This will help you identify which variables are important and if there is any lead or lag relationships. There might be a need for ARIMA in this equation or denominator on the X variables. You might also have outliers, changes in trend, level, seasonality, parameters and variance. – Tom Reilly May 18 '16 at 14:03
• There also might be a Regression assumes that time isn't important. Regression was used by Galton to study Sweat Peas...not a time series problem. The Transfer Function uses parts of the process to estimate the problem. – Tom Reilly May 18 '16 at 14:03

If you fit a model using external variables and want to forecast from this model, you will need (forecasted) future values of the external variables, plain and simple. There is no way around this.

There are of course different ways of forecasting your explanatory variables. You can use the last observed value (the "naive random walk" forecast) or the overall mean. You can simply set them to zero if this is a useful value for them (e.g., special events that happened in the past like an earthquake, which you don't anticipate to recur). Or you could fit and forecast a time series model to these explanatory variables themselves, e.g., using auto.arima.

The alternative is to fit a model to your $y$ values without explanatory variables, by removing the xreg parameter, then to forecast $y$ using this model. One advantage is that this may even capture regularities in your explanatory variables. For instance, your ice cream sales may be driven by temperature, and you don't have good forecasts for temperature a few months ahead... but temperature is seasonal, so simply fitting a model without temperature yields a seasonal model, and your seasonal forecasts may actually be pretty good even if you don't include the actual driver of sales.

I recommend this free online forecasting textbook, especially this section on multiple regression (unfortunately, there is nothing about ARIMAX there), as well as Rob Hyndman's blog post "The ARIMAX model muddle".

As Yogi Berra said, "It's tough to make predictions, especially about the future."

Many stat software modules will generate forecasts based on the univariate stream of time series in the absence of any future information, e.g., Proc Forecast in SAS or any number of ARIMA modules available. These forecasts are projections based on the historic behavior of your data.

You tell us that your data is monthly but don't tell us how many periods you have available. Another approach is to set your three IVs back 24 months relative to the DV so that the period they are predicting is t+24. This assumes that you have a sufficient amount of date both to initialize the model and calibrate any relevant seasonality, as appropriate.

• I have edited my text. Can you answer my questions now? – S.B May 16 '16 at 20:52
• Given that you have a sufficient amount of information, there are many ways to integrate time into your model. You can create dummy variables for the years (e.g., 2009, 2010, etc.), for the quarters, for each month in the time series or, as an approach to accounting for seasonality, each month of the year. Another approach would be to treat time as a numeric trend function, e.g., linear (as in a count of the periods beginning with Jan 2009=1, Feb=2, etc.) or any number of polynomial trends based on the linear trend, e.g., quadratic (linear trend squared) and up. What else do you want to know? – DJohnson May 16 '16 at 21:36
• But time can't be a indepedent variable right? So how can I predict my y variable using the 3 external variables? I am having a hard time actually selecting a model that will do the prediction? – S.B May 16 '16 at 21:49
• As outlined in the prior comment, time would be an independent variable. I think you need to read up on regression, econometrics and the time series literature. There are many threads on this site that address these questions and suggest articles, books, etc. Browse the right hand side of this web page for more threads related to your concerns. – DJohnson May 16 '16 at 22:15
• I have done a lot of reading and I haven't been able to come with a solution. That's the reason that I've asked this question here. Can you name some threads of some literature that I can use? Or right web page? – S.B May 16 '16 at 22:45

As I see it, you have three options:

1) Use a published forecast for your independent variables or find a model to forecast them. For example, the Census will have forecasted population data. 2) Using the dataset that you have, regress each of your independent variables against time & then use these results your forecast model for the independent variables 3) Drop the independent variables and just model your dependent variable as a function of time and lagged values of y.

Each approach has its own strengths and weaknesses, so the best depends on the specific context.