# Can I apply ARIMA(p, d, q) model to testing dataset and make forecast with the testing dataset? Just like the scenario of regression model?

After I fit a sarima model with some historical sales data (for example A dataset), I get coefficients of sma1 and ar1. And I'd like to apply this model to current sales data (for example B dataset) and forecast future sales. That's where my concerns comes up, it seem like neither sarima.for() nor predict() or any other forecasting functions has the 'new.data' argument (I don't mean xreg, so ignore xreg here, I only mean the univariate series itself). Since for general regression models, we can store the coefficient and apply the model to future testing dataset. Does that mean we cannot store the coefficient from the ARIMA model and apply the model to other period of data? If time series works differently, what should I do if I want use the model I get? More specifically, when we say a time series model, do we only mean the p, d, q that we have get, how about the coefficient? Correct me if I'm wrong. Looking forward to any enlightenment!

For univariate time series forecasting, once you have fit a model and you want to predict new values, the only input to the model is the number of future time steps you want to perform predictions for.

Keep in mind that in a real world business scenario (as opposed to testing the accuracy of the model) the future hasn't happened yet, so there are no inputs available to be fed to the model.

For testing purposes, as I mentioned, the prediction function only takes the number of future steps as an argument. The test data set is used then for evaluation purposes, to be compared to the forecasts, not as an input to the model.

For ARIMA and SARIMA models, the output of the model is fed back to the model recursively to generate future forecasts in the following matter:

Suppose that our ARIMA model is a simple AR(1) model. Generate a forecast for one step ahead $\hat{y}_{t+1} = a*y_t$, then use that to generate a forecast for two steps ahead $\hat{y}_{t+2} = a*\hat{y}_{t+1}$, etc...until you have $\hat{y}_{T}$ for your desired $T$ steps ahead.

If your model is an AR(2) model. Generate a forecast for one step ahead $\hat{y}_{t+1} = a*y_t + b*y_{t-1}$, then use that to generate a forecast for two steps ahead $\hat{y}_{t+2} = a*\hat{y}_{t+1} + b*y_t$, $\hat{y}_{t+3} = a*\hat{y}_{t+2} + b*\hat{y}_{t+1}$, etc...until you have $\hat{y}_{T}$ for your desired $T$ steps ahead.

• Hi, Alex, I understand your point. Let's make up some scenario. For example, one scenario is in general regression analysis, let's make it simple, in linear regression, height and weight has some linear relationship and I want to know the relationship and make use of the model. I fit lm(height ~ weight, data = A) and get coefficient of the weight, namely, height = a + bweight. Then, I have a B dataset that contains weight data, then I can use a + b weight (from B dataset) to get estimated height for B dataset. The other scenario, in TS analysis..(to be continued) – EmLp Aug 25 '18 at 6:42
• The other scenario, in TS analysis, I use sales weekly data from 2010-2014 to get a SARIMA model, and I have coefficient for ar(1) and sma(1), while I cannot directly use these coefficient to the another dataset B with data 4 months before today to get forecasting for the sales of next month from today ~~ – EmLp Aug 25 '18 at 6:46
• Is that the difference between TS model and general regression model? In general regression, we can train the model and use the model (coefficients) with other dataset to do forecasting, however, in TS, we can train the model, while must stick to the training dataset to use the model (coefficient) when forecasting, and then forecast is from the latest time point in the training dataset and then afterwards~~ correct? – EmLp Aug 25 '18 at 6:55
• To be continued with the second scenario, if in a dynamic situation, each time I want to use the sales data 4 month ago from today to predict sales 1 month in the future, I need to re-fit the arima model, re-gain new coefficients and re-specify n.ahead, since I cannot put the 4-month-ago data to the model I gained from 2010-2014. While in linear regression, I can use the already fitted a+b*weight once for all~~, correct? Correct me if my understanding is wrong~~ Many thanks! – EmLp Aug 25 '18 at 7:06
• @EmLp your second scenario is correct. You should refit a new model every time with your most recent data and use that a basis for prediction. If you use model parameters fitted to older data, there's a chance that they are no longer a good fit because in the interim your time series structure has changed (for example from an upward trend to a downward trend). – Skander H. Aug 25 '18 at 14:52