| ts_regsw_mv | R Documentation |
Orchestrate one target model and one auxiliary model per
covariate, while reusing the existing univariate learners from tspredit.
ts_regsw_mv(model_y, models_x, window_size = 30)
model_y |
A |
models_x |
Named list with one |
window_size |
Integer. Base window size available to each variable. |
ts_regsw_mv() is the first multivariate forecasting orchestrator in
tspredit. It keeps the package centered on a target variable y, while
allowing every auxiliary variable x1, ..., xn to be forecast by its own
pipeline.
The workflow is:
store aligned multivariate observations in ts_data_mv()
define one ts_mv_spec() for y
define one ts_mv_spec() for each x
fit the composed system with fit()
forecast recursively with predict(..., steps_ahead = h)
The current implementation keeps a single window_size as the base temporal
memory available to every variable. After that, each specification decides
which variables and which lag positions are actually used by its learner.
This means the multivariate extension does not replace the existing univariate models. It reuses them as polymorphic building blocks.
Supported configurations in this first version:
the target model must inherit from ts_regsw
auxiliary models may inherit from ts_regsw or from ts_reg
raw-series auxiliary models such as ts_arima() currently use only their
own variable as input
The method returns the forecast of y as a numeric vector. The recursive
path of y and all auxiliary predictions is attached to that vector as
attributes, so the interface stays target-centered without discarding the
system forecast.
A ts_regsw_mv object.
data(tsd)
x1 <- c(tsd$y[-1], tail(tsd$y, 1))
x2 <- stats::filter(tsd$y, rep(1/3, 3), sides = 1)
x2[is.na(x2)] <- tsd$y[is.na(x2)]
mv <- ts_data_mv(data.frame(y = tsd$y, x1 = x1, x2 = x2), y = "y")
samp <- ts_sample(mv, test_size = 5)
model <- ts_regsw_mv(
model_y = ts_mv_spec(
ts_mlp(ts_norm_an(), input_size = 4, size = 4, decay = 0),
variables = c("y", "x1", "x2"),
transforms = list(y = ts_fil_ma(3))
),
models_x = list(
x1 = ts_mv_spec(ts_deterministic("periodic", period = 7)),
x2 = ts_mv_spec(ts_deterministic("periodic", period = 7))
),
window_size = 10
)
model <- daltoolbox::fit(model, samp$train)
predict(model, steps_ahead = 1)
predict(model, steps_ahead = 5)
pred <- predict(model, steps_ahead = 5)
attr(pred, "system")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.