[R] Time Series with External Regressors in R Problems with XReg

PaulJr paulbernal07 at gmail.com
Wed Nov 14 16:30:36 CET 2012


Hello everyone,

Hope you all are doing great! I have been fitting arima models and
performing forecasts pretty straightforwardly in R.

However, I wanted to add a couple of regressors to the arima model to see if
it could improve the accuracy of the forecasts but have had a hard time
trying to do so.

I used the following R function:

arima(x, order = c(0, 0, 0),
seasonal = list(order = c(0, 0, 0), period = NA),
xreg = NULL, include.mean = TRUE,
transform.pars = TRUE,
fixed = NULL, init = NULL,
method = c("CSS-ML", "ML", "CSS"),
n.cond, optim.method = "BFGS",
optim.control = list(), kappa = 1e6)

Now, I know that you don´t need all the parameters in the function so I
basically fit the model using this sentence:

> var1.fit<-arima(response$cargotonnage, order=c(3,0,0), xreg=explanatory,
> include.mean=FALSE)
> var1.fit

Now the weird thing here is that R was actually able to fit the model,
however, when I wanted to make predictions (see below):

> var1.pred<-predict(var1.fit, n.ahead=12)

R popped the following error:

[b]Error in predict.Arima(var1.fit, n.ahead = 12) : 
'xreg' and 'newxreg' have different numbers of columns
> 

Which is weird beaucse 1. I made sure that my regressor matrix had the same
amount of rows as my univariate time series and 
2. R was able to fit the model I was suggesting.

Has anyone done arima models including external regressors in R? Does anyone
has any idea of what could be happening?

Best regards,

Paul




--
View this message in context: http://r.789695.n4.nabble.com/Time-Series-with-External-Regressors-in-R-Problems-with-XReg-tp4649500.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list