ts_lm_mv: Multivariate Linear Regression

View source: R/ts_lm_mv.R

ts_lm_mvR Documentation

Multivariate Linear Regression

Description

Create a target-centered singular multivariate regressor based on stats::lm.

Usage

ts_lm_mv(models_x = NULL, formula = NULL, features = NULL)

Arguments

models_x

Optional named list with one univariate model per auxiliary variable.

formula

Optional regression formula. When omitted, the target variable from ts_data_mv is regressed on all auxiliary variables.

features

Optional character vector of feature names used when formula is NULL.

Details

ts_lm_mv() is a linear-regression member of the ts_reg_mv family.

It is inspired by the formula-based design already used in daltoolbox, but adapted to the aligned multivariate time-series abstraction of tspredit.

This makes it a very transparent baseline for the singular multivariate branch:

  • the target variable remains explicit

  • the auxiliary variables are declared in the formula

  • the analyst can read the structural assumption directly from the model

The most common usage patterns are:

  • provide a full formula such as y ~ x1 + x2

  • omit the formula and let the model regress y on all auxiliary variables

The target variable is forecast from the synchronized auxiliary variables. When future auxiliary values are not known, they can be generated by the univariate models supplied in models_x.

Value

A ts_lm_mv object inheriting from ts_reg_mv.

References

  • Montgomery DC, Peck EA, Vining GG (2021). Introduction to Linear Regression Analysis. 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_lm_mv(
 models_x = list(x1 = ts_arima(), x2 = ts_arima()),
 formula = y ~ x1 + x2
)
model <- daltoolbox::fit(model, samp$train)
predict(model, steps_ahead = 5)

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