# Forecast with arima model [closed]

Starting with arima models in R, I cannot make a forecast with my favourite model. For example, the commands

predict(arima(data_ts,order=c(1,1,2),xreg=cbind(t),seasonal=list(order=c(0,1,1),period=12)))


and

forecast(arima(data_ts,order=c(1,1,2),xreg=cbind(t),seasonal=list(order=c(0,1,1),period=12)))


don't work. Can you explain me why?

-
Please post a reproducible example. –  Zach Mar 1 '12 at 21:09
Exactly how do these commands "not work"? –  whuber Mar 1 '12 at 21:17
What is cbind(t) supposed to do? Why not just xreg=t? (Or better yet, not use t as a variable name in R?) –  jbowman Mar 1 '12 at 21:55

## closed as too localized by gung, whuber♦Apr 26 at 4:51

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Well the error message you get is pretty explicit. Let us fit the model first with some data (the model comes from arima help page):

> data(lh)
> t<-1:length(lh)

arima(lh, order = c(1,0,0),xreg=t)
Series: lh
ARIMA(1,0,0) with non-zero mean

Coefficients:
ar1  intercept       t
0.5221     2.0965  0.0128
s.e.  0.1208     0.2534  0.0089

sigma^2 estimated as 0.1904:  log likelihood=-28.46
AIC=64.92   AICc=65.85   BIC=72.41


As you can see fitting works. This happens when we try to predict:

> predict(arima(lh, order = c(1,0,0),xreg=t))
Erreur dans predict.Arima(arima(lh, order = c(1, 0, 0), xreg = t)) :
'xreg' and 'newxreg' have different numbers of columns: 1 != 0


For forecasting you need to supply new values of your regressor, which apparently you do not. Also since you did not produce the reproducible example there might be another million reasons why the code did not work, I just picked the most likely one.

-
Here is what I tried to do:data_ts<-ts(data[,1],start=1959.1,freq=12) –  Nicola Rosaia Mar 3 '12 at 5:01
Here is what I tried to do: >data_ts<-ts(data[,1],start=1959.1,freq=12) >t<-seq(1959.1,2012.1,length=length(data_ts)) >model=arima(data_ts,order=c(1,1,1),xreg=cbind(t),seasonal=list(order=c(0,1,1),p‌​eriod=12)) > predict(model) Error in predict.Arima(model) : 'xreg' and 'newxreg' have different numbers of columns: 1 != 0 How can I do to to supply new values of my regressor (the time variable)? Because if I create a time variable longer than my dataset I have problems in fitting, so I need to provide them expressly for the forecast. Thank you –  Nicola Rosaia Mar 3 '12 at 5:17