fit_var_each: Fit an ordinary least-squares VAR for every subject

View source: R/var.R

fit_var_eachR Documentation

Fit an ordinary least-squares VAR for every subject

Description

Applies fit_var() to each subject separately, returning one transparent person-specific OLS VAR result per individual. This is the unregularized companion to fit_graphical_var_each() and is useful as an equivalence baseline for checking lag construction, scaling, and temporal coefficient direction.

Usage

fit_var_each(data, vars, id, day = NULL, beep = NULL, min_obs = NULL, ...)

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; required.

day

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

beep

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

min_obs

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

...

Further arguments passed to fit_var().

Value

A named list of var_result objects (class var_list), one element per subject, named by subject id. Subjects that cannot be fit are dropped with a warning.

Examples

set.seed(1)
d <- data.frame(
  id = rep(1:3, each = 40),
  day = rep(1, 120),
  beep = rep(seq_len(40), 3),
  A = rnorm(120), B = rnorm(120), C = rnorm(120)
)
fits <- fit_var_each(d, vars = c("A", "B", "C"), id = "id",
                       day = "day", beep = "beep")
fits[["1"]]

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