Hi all,

Forecasting from an arima model is easy with predict.

But I can't manage to backcast : invent data from the model before the
begining of the sample.
The theory is easy : take your parameters, reverse your data, forecast, and
then reverse the forecast
I've tried to adapt the predict function to do that (i'm not sure that the
statistical procedure is fine (with the residuals), but that's not my point
right now) :

mav.backcast.arima<-function(model,n.backcast,...)
{
    if (class(model)[1]!="Arima") stop("argument <model> must be an object
of class 'Arima' (see ?arima)")

    model2<-model
    model$residuals<-rev(model$residuals)
    if (is.ts(model2$residuals))
model$residuals<-ts(model$residuals,start=start(model2$residuals),
        frequency=frequency(model2$residuals))
    pred.before<-predict(model,n.ahead=n.backcast,...)

    freq<-frequency(model$residuals)
    startingdate<-per.sub(start(model2$residuals),n.backcast,freq=freq)

    pred<-ts(rev(pred.before$pred),start=startingdate,freq=freq)
    se<-ts(rev(pred.before$se),start=startingdate,freq=freq)

    return((list(pred = pred, se =se)))
}

This function does not work : it gives always the same result, it does not
depend on the residuals (i've tried to insert
a model$residuals<-rep(1,100) after the definition, to check that).

Then i look at the code, with getS3method("predict","Arima"). And i get even
more confused (!) :
where does data play a role in the function ? residuals are loaded into rsd,
but this variable is not used after...
I looked at KalmanForecast and at the C code of KalmanFore, but it did not
help me understand what was going on.

thanks

Franck A.

btw, it has nothing to do with it, but i've done some stuff on time series
(filtering with Hodrick prescott or Baxter King, for instance) that you can
find on http://arnaud.ensae.net

	[[alternative HTML version deleted]]

