-2
$\begingroup$

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?

$\endgroup$

closed as too localized by gung, whuber Apr 26 '13 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.

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

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.

$\endgroup$
  • $\begingroup$ Here is what I tried to do:data_ts<-ts(data[,1],start=1959.1,freq=12) $\endgroup$ – Nicola Rosaia Mar 3 '12 at 5:01
  • 1
    $\begingroup$ 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),period=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 $\endgroup$ – Nicola Rosaia Mar 3 '12 at 5:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.