validate_forecast: Validate one-step forecasts from idiographic VAR models...

View source: R/forecast.R

validate_forecastR Documentation

Validate one-step forecasts from idiographic VAR models (experimental)

Description

Experimental. The rolling-origin design follows standard time-series cross-validation practice, but unlike the estimators in this package it has no external reference implementation to validate against, and its interface, defaults, and reported metrics may change in a future release.

Performs rolling-origin one-step prediction from fit_var() or fit_graphical_var(). Each split fits the estimator on earlier blocks and predicts current variables in the next block from their lag-1 values. Scaling and within-person centring parameters are learned from the training split only, then applied to the assessment split before prediction.

Usage

validate_forecast(
  data,
  vars,
  estimator = c("var", "graphical_var"),
  id = NULL,
  day = NULL,
  beep = NULL,
  initial = NULL,
  assess = 1L,
  step = 1L,
  n_splits = NULL,
  block_size = NULL,
  scale = TRUE,
  center_within = TRUE,
  delete_missings = TRUE,
  keep_fits = FALSE,
  ...
)

Arguments

data

A data.frame or matrix with columns for variables and optional id/day/beep columns.

vars

Character vector of variable names.

estimator

"var" (default) for fit_var() or "graphical_var" for fit_graphical_var().

id

Character. Name of the person-ID column, or NULL.

day

Character. Name of the day/session column, or NULL.

beep

Character. Name of the measurement-occasion column, or NULL.

initial

Integer number of ordered blocks in the first training split. Default uses 60 percent of blocks, leaving at least one assessment block.

assess

Integer number of blocks to assess per split. Default 1.

step

Integer number of blocks to advance between splits. Default 1.

n_splits

Optional maximum number of rolling splits.

block_size

Integer or NULL. Consecutive block length used only when neither id nor day is supplied. Defaults to floor(sqrt(nrow(data))).

scale

Logical. Whether to standardize using training-split means and SDs. Default TRUE.

center_within

Logical. Whether to centre within person using training-split person means when more than one id is present. Default TRUE.

delete_missings

Logical. Drop incomplete current/lagged assessment rows. Default TRUE.

keep_fits

Logical. Store fitted split models? Default FALSE.

...

Further arguments passed to the estimator.

Value

A forecast_result with ⁠$predictions⁠, ⁠$metrics⁠, ⁠$splits⁠, ⁠$failures⁠, and optionally ⁠$fits⁠.

Examples

set.seed(1)
d <- data.frame(id = 1, day = rep(1:5, each = 12),
                beep = rep(1:12, 5),
                A = rnorm(60), B = rnorm(60), C = rnorm(60))
fc <- validate_forecast(d, vars = c("A", "B", "C"), id = "id",
                        day = "day", beep = "beep",
                        initial = 3, n_splits = 2, scale = FALSE)
fc$metrics

idiographic documentation built on Aug. 4, 2026, 1:07 a.m.