ts_data_mv: Multivariate Time Series Data

View source: R/ts_data_mv.R

ts_data_mvR Documentation

Multivariate Time Series Data

Description

Construct a multivariate time-series object used throughout the target-centered multivariate workflow.

Usage

ts_data_mv(
  data,
  y = NULL,
  x = NULL,
  sw = 1,
  variables = NULL,
  lags = NULL,
  transforms = NULL
)

Arguments

data

data.frame or matrix with one column per variable and one row per time index. It can also be an existing ts_data_mv, in which case the stored metadata is reused by default.

y

Optional character scalar. Name of the target variable. When data already inherits from ts_data_mv, this defaults to the stored target name.

x

Optional character vector. Names of the auxiliary variables. By default, all columns except y are used.

sw

Integer. Temporal width of the representation. Use sw = 1 for aligned multivariate observations and sw > 1 for lagged windows.

variables

Optional character vector. Variables to include when sw > 1. By default, all variables stored in data are used.

lags

Optional named list with one integer vector per variable. When omitted, every variable uses all lags from 0:(sw-1).

transforms

Optional named list of raw-series transformations applied per variable before the lagged blocks are built. Each entry can be a single transform object or a list of transforms.

Details

ts_data_mv() follows the same design principle as ts_data() in the univariate path:

  • with sw = 1, it stores aligned multivariate observations

  • with sw > 1, it materializes multivariate lagged windows

This keeps a single data abstraction for both the aligned and the lagged representations.

In aligned mode (sw = 1):

  • each row is a time instant

  • each column is one variable

In lagged mode (sw > 1):

  • each row is a forecasting origin

  • each variable contributes one lag block

  • column names follow the pattern var_tk

Optional variables, lags, and transforms let the caller inspect a specific multivariate feature space while staying inside the ts_data_mv abstraction.

Value

A ts_data_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 = as.numeric(x2)),
 y = "y"
)
ts_head(mv, 3)

mv_sw <- ts_data_mv(mv, sw = 5)
ts_head(mv_sw, 3)

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