Re: [R] predict and arima

2006-11-25 Thread Prof Brian Ripley
Part of the fit is the Kalman filter state after running the model 
forwards.  Try reversing your series, fitting and then forecasting.

You might have more success in understanding arima0.

On Sat, 25 Nov 2006, Franck Arnaud wrote:

 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]]

 __
 R-help@stat.math.ethz.ch 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.


-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch 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.


[R] predict and arima

2006-11-24 Thread Franck Arnaud
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]]

__
R-help@stat.math.ethz.ch 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.