Closed robjhyndman closed 8 years ago
From my understanding of the model and the code it looks like this requires updating y
, x
, fitted.values
and errors
in the "bats" object
.
The time series, y
, can be directly assigned, but the rest require re-estimating the states. It looks to me like this happens in forecast:::fitSpecificBATS
:
w <- .Call("makeBATSWMatrix", smallPhi_s = small.phi,
sPeriods_s = seasonal.periods, arCoefs_s = ar.coefs,
maCoefs_s = ma.coefs, PACKAGE = "forecast")
g <- .Call("makeBATSGMatrix", as.numeric(alpha), beta.v,
gamma.v, seasonal.periods, as.integer(p), as.integer(q),
PACKAGE = "forecast")
F <- makeFMatrix(alpha = alpha, beta = beta.v, small.phi <- small.phi,
seasonal.periods = seasonal.periods, gamma.bold.matrix = g$gamma.bold.matrix,
ar.coefs = ar.coefs, ma.coefs = ma.coefs)
fitted.values.and.errors <- calcModel(y, x.nought, F,
g$g, w)
fitted.values.and.errors$x #these are the states and errors
Although things are somewhat more complicated than that if lambda
is not NULL, but that seems to be the only temporal information returned in the model. I'd be happy to put together a patch if my understanding is accurate.
I neglected to note that the actual likelihood needs to be updated, too, but that looks easy.
Thanks for the offer. I'm always happy to receive patches if it saves me some work!
This patch needs to apply to tbats
as well as bats
but the logic is essentially identical.
There are two options here.
I don't mind if we implement only 1 as a first pass at this, and leave 2 until later.
It might be simplest to produce a new function that is similar to fitSpecificBATS
but without the optimization. Similarly for fitSpecificTBATS
.
As a check, the new functions should give identical models and forecasts if the model is applied to the same data on which it was estimated, and identical models but different residuals, fitted values and forecasts if the model is applied to different data.
To compute forecasts and fitted values without re-estimating the model.