ts_regsw_mv: Multivariate Sliding-Window Regressor

View source: R/ts_regsw_mv.R

ts_regsw_mvR Documentation

Multivariate Sliding-Window Regressor

Description

Orchestrate one target model and one auxiliary model per covariate, while reusing the existing univariate learners from tspredit.

Usage

ts_regsw_mv(model_y, models_x, window_size = 30)

Arguments

model_y

A ts_mv_spec or a fitted-model constructor for the target variable.

models_x

Named list with one ts_mv_spec (or plain model object) per auxiliary variable.

window_size

Integer. Base window size available to each variable.

Details

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:

  1. store aligned multivariate observations in ts_data_mv()

  2. define one ts_mv_spec() for y

  3. define one ts_mv_spec() for each x

  4. fit the composed system with fit()

  5. 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.

Value

A ts_regsw_mv object.

Examples

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")

tspredit documentation built on Sept. 9, 2026, 9:08 a.m.