ts_var: Vector Autoregression

View source: R/ts_var.R

ts_varR Documentation

Vector Autoregression

Description

Create a target-centered vector autoregression over aligned multivariate observations.

Usage

ts_var(target = NULL, p = NULL, p_max = 5, intercept = TRUE)

Arguments

target

Optional target variable name. When omitted, use the y attribute stored in ts_data_mv.

p

Optional lag order. When NULL, choose the order automatically.

p_max

Maximum lag order considered in the automatic search.

intercept

Logical. Whether to include an intercept in each equation.

Details

ts_var() models the multivariate system directly, but keeps the tspredit interface centered on a distinguished target variable y.

This means:

  • the full system is learned jointly

  • predict() returns the target forecast by default

  • predict(..., return_all = TRUE) exposes the forecast path of all system variables

The current implementation uses ordinary least squares over lagged aligned observations and can choose the lag order automatically by minimizing AICc over 1:p_max.

This makes ts_var() conceptually different from ts_arimax():

  • ts_arimax() treats the auxiliaries as regressors for one main target

  • ts_var() treats all variables as part of the dynamic system

Even so, tspredit still lets the user mark one variable as the main target for evaluation and default return behavior.

Value

A ts_var object inheriting from ts_reg_mv.

References

  • Lütkepohl H (2005). New Introduction to Multiple Time Series Analysis. Springer.

  • Tsay RS (2014). Multivariate Time Series Analysis with R and Financial Applications. Wiley.

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")
samp <- ts_sample(mv, test_size = 5)

model <- ts_var(p_max = 3)
model <- daltoolbox::fit(model, samp$train)
predict(model, steps_ahead = 5)

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