6
$\begingroup$

Hi all I'm trying to do one step ahead forecast. Lets say I have 1000 data and fit an ARIMA model with it and then I do a forecast for one period ahead. When I get more data I would like to forecast another step using the new data without having to reestimate all coefficients and so on...

This is my code but for some reason it's very slow for a bigger dataset and am not too sure that is doing what I want:

set.seed(1234)
y=ts(log(35+10*rnorm(1000)))
set.seed(4567)
new.data=ts(log(35+10*rnorm(10)))

library(forecast)
model = auto.arima(y)

onestep.for=forecast(model,h=1)
for (i in 1:10) {
  data=c()
  data=c(y,new.data[1:i])
  newfit=Arima(data, model=model)
  forec=forecast(newfit,h=1)
  onestep.for=c(onestep.for,forec)
}
$\endgroup$

1 Answer 1

5
$\begingroup$

You don't need the loop here. The one-step forecasts are the same as fitted values in a time series model. So the following should do what you want:

library(forecast)
model <- auto.arima(y)
newfit <- Arima(c(y,new.data), model=model)
onestep.for <- fitted(newfit)[1001:1010]
$\endgroup$
3
  • $\begingroup$ I get some NaN values in the s.e. of some of the coefficients using the auto.arima with higher number of parameters than the default, does this means there is something wrong with the fitted model? $\endgroup$
    – nopeva
    Commented Apr 5, 2013 at 6:30
  • $\begingroup$ Yes. That suggests the model fit has problems. $\endgroup$ Commented Apr 5, 2013 at 6:38
  • $\begingroup$ Sorry, but how do you fit a data you don't have yet? @RobHyndman I'm talking about {new.data} $\endgroup$ Commented Oct 27, 2016 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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