Reusing the model from R's forecast package

I have been told that, while using R's forecast package, one can reuse a model. That is, after the code x <- c(1,2,3,4); mod <- ets(x); f <- forecast(mod,h=1) one could have append(x, 5) and predict the next value without recalculating the model. How does one do that? (As I understand, using simple exponential smoothing one would only need to know alpha, right?)

Is it like forecast(x, model=mod)? If that is the case I have to say that I am using Java and calling the forecast code programmatically (for many time series), so I dont think I could keep the model object in the R environment all the time. Would there be an easy way to keep the model object in Java and load it in R environment when needed?

Upvotes: 1

Views: 942

Answers (2)

Rob Hyndman
Rob Hyndman

Reputation: 31800

Regarding your first question:

x <- 1:4
mod <- ets(x)
f1 <- forecast(mod, h=1)
x <- append(x, 5)
mod <- ets(x, model=mod) # Reuses old mod without re-estimating parameters.
f2 <- forecast(mod, h=1)

Upvotes: 0

Dirk is no longer here
Dirk is no longer here

Reputation: 368191

You have two questions here:

A) Can the forecast package "grow" its datasets? I can't speak in great detail to this package and you will have to look at its document. However, R models in general obey a structure of

fit <- someModel(formula, data)
estfit <- predict(fit, newdata=someDataFrame)

eg you supply updated data given a fit object.

B) Can I serialize a model back and forth to Java? Yes, you can. Rserve is one object, you can also try basic serialize() to (raw) character. Or even just `save(fit, file="someFile.RData").

Upvotes: 2

Related Questions