fit_rolling_graphical_var: Estimate rolling-window graphical VAR networks

View source: R/rolling_graphical_var.R

fit_rolling_graphical_varR Documentation

Estimate rolling-window graphical VAR networks

Description

Fits fit_graphical_var() over ordered, overlapping windows within each subject. This is the time-varying graphical VAR companion to fit_rolling_var(): every window uses graphical VAR's lag construction, EBIC/penalty settings, and tidy coefficient access, then returns one coefficient table per window.

Usage

fit_rolling_graphical_var(
  data,
  vars,
  id = NULL,
  day = NULL,
  beep = NULL,
  window_size,
  step = 1L,
  scale = TRUE,
  center_within = TRUE,
  delete_missings = TRUE,
  min_obs = NULL,
  subject = NULL,
  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.

id

Character. Name of the person-ID column, or NULL for a single series.

day

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

beep

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

window_size

Integer number of ordered rows per rolling window.

step

Integer number of rows to advance between windows. Default 1.

scale

Logical. Whether to standardize variables inside each window. Default TRUE.

center_within

Logical. Whether to centre within person inside each window when more than one id is present. Default TRUE.

delete_missings

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

min_obs

Integer or NULL. Keep only subjects with at least this many observations before rolling.

subject

Optional vector naming the subject(s) to analyse.

keep_fits

Logical. Store successful gvar_result fits? Default FALSE.

...

Further arguments passed to fit_graphical_var(), such as n_lambda, gamma, lambda_beta, or lambda_kappa.

Value

A rolling_gvar_result with ⁠$estimates⁠, ⁠$windows⁠, ⁠$failures⁠, and optionally ⁠$fits⁠. ⁠$estimates⁠ is a tidy coefficient table with subject/window metadata plus network, from, to, and weight.

Examples

set.seed(1)
d <- data.frame(id = 1, day = rep(1:5, each = 20),
                beep = rep(1:20, 5),
                A = rnorm(100), B = rnorm(100), C = rnorm(100))
tv <- fit_rolling_graphical_var(d, vars = c("A", "B", "C"), id = "id",
                            day = "day", beep = "beep",
                            window_size = 50, step = 25,
                            scale = FALSE, n_lambda = 5)
head(tv$estimates)

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