a a
2010-May-04 16:18 UTC
[R] How to make predictions with the predict() method on an arimax object using arimax() from TSA library
Hi R Users, I'm fairly new to R (about 3 months use thus far.) I wanting to use the arimax function from the TSA library to incorporate some exogenous inputs into the basic underllying arima model.Then with that newly model of type arimax, I would like to make a prediction. To avoid being bogged down with issues specific to my own work, I would like to refer to readers to the example given in the TSA documentation which would also then clarify my own issues:>library(TSA)>>data(airmiles)>air.ml=arimax(log(airmiles),order=c(0,1,1),seasonal=list(order=c(0,1,1),>period=12),xtransf=data.frame(I911=1*(seq(airmiles)==69),>I911=1*(seq(airmiles)==69)),>transfer=list(c(0,0),c(1,0)),xreg=data.frame(Dec96=1*(seq(airmiles)==12),>Jan97=1*(seq(airmiles)==13),Dec02=1*(seq(airmiles)==84)),method='ML')Ok,so I've run the above code and an object called air.ml has now been created of class type arimax.According to the documentation this is the same type as arima.So now I make a prediction,say 15 time steps ahead:>forecast=predict(air.m1, n.ahead=15)The following error is produced: Error in predict.Arima(air.m1, n.ahead = 15) : 'xreg' and 'newxreg' have different numbers of columns -------------------------------------------------------------------------------------------------------------------- Question is how to to get a prediction correctly using predict.(I've seen DSE package but that seems overkill to make just a simple prediction)?? Thank you in advance for any repsonses. A.A Part time student at BBK college,UofL. _________________________________________________________________ Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. N:WL:en-US:WM_HMP:042010_2 [[alternative HTML version deleted]]
Dennis Murphy
2010-May-04 19:50 UTC
[R] How to make predictions with the predict() method on an arimax object using arimax() from TSA library
Hi: If you look at the help page of the predict.Arima() function, you'll discover the problem:>forecast=predict(air.m1, n.ahead=15)Error in predict.Arima(air.m1, n.ahead = 15) : 'xreg' and 'newxreg' have different numbers of columns ^^^^^^^^^^ ## what's this newxreg??> class(air.m1)[1] "Arimax" "Arima">From the help page for predict.Arima:Usage ## S3 method for class 'Arima': predict(object, n.ahead = 1, newxreg = NULL, se.fit = TRUE, ...) Arguments object The result of an arima fit. n.ahead The number of steps ahead for which prediction is required. newxreg New values of xreg to be used for prediction. Must have at least n.ahead rows. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Evidently, you need to supply a data frame as the argument to newxreg = with at least 15 rows, which needs to contain the same covariates as in your model with the same names, whose values are those you want at the forecast times. Basically, you've asked to forecast the next 15 steps ahead without providing the covariate values at those future times. HTH, Dennis On Tue, May 4, 2010 at 9:18 AM, a a <aahmad31@hotmail.com> wrote:> > Hi R Users, > > > > I'm fairly new to R (about 3 months use thus far.) > > I wanting to use the arimax function from the TSA library to incorporate > some exogenous inputs into the basic underllying arima model.Then with that > newly model of type arimax, I would like to make a prediction. > > > > To avoid being bogged down with issues specific to my own work, I would > like to refer to readers to the example given in the TSA documentation which > would also then clarify my own issues: > > > > >library(TSA) > > > > > >data(airmiles) > > >air.ml=arimax(log(airmiles),order=c(0,1,1),seasonal=list(order=c(0,1,1), > > >period=12),xtransf=data.frame(I911=1*(seq(airmiles)==69), > > >I911=1*(seq(airmiles)==69)), > > >transfer=list(c(0,0),c(1,0)),xreg=data.frame(Dec96=1*(seq(airmiles)==12), > > >Jan97=1*(seq(airmiles)==13),Dec02=1*(seq(airmiles)==84)),method='ML') > > > > Ok,so I've run the above code and an object called air.ml has now been > created of class type arimax.According to the documentation this is the same > type as arima.So now I make a prediction,say 15 time steps ahead: > > > > >forecast=predict(air.m1, n.ahead=15) > > > > The following error is produced: > > > > Error in predict.Arima(air.m1, n.ahead = 15) : > 'xreg' and 'newxreg' have different numbers of columns > > -------------------------------------------------------------------------------------------------------------------- > > Question is how to to get a prediction correctly using predict.(I've seen > DSE package but that seems overkill to make just a simple prediction)?? > > > > Thank you in advance for any repsonses. > > > > A.A > > Part time student at BBK college,UofL. > > > > > > > > _________________________________________________________________ > Hotmail is redefining busy with tools for the New Busy. Get more from your > inbox. > > N:WL:en-US:WM_HMP:042010_2 > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]