fit_var: Build an ordinary least-squares VAR network

View source: R/var.R

fit_varR Documentation

Build an ordinary least-squares VAR network

Description

Fits a transparent VAR(1) baseline from intensive longitudinal data using ordinary least squares: current variables are regressed on an intercept and lag-1 predictors. The lag construction, scaling, within-person centring, and day-boundary behaviour match fit_graphical_var(), but no regularization or EBIC model selection is applied.

Usage

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

lags

Integer. Only 1 is supported.

scale

Logical. Whether to standardize variables before lagging. Default TRUE.

center_within

Logical. Whether to centre within person 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.

subject

Optional vector naming the subject(s) to analyse.

Value

A var_result object with temporal OLS coefficients, residual covariance, residual precision, contemporaneous partial correlations, and tidy access through edges(), coefs(), nodes(), and summary().

Examples

set.seed(1)
d <- data.frame(id = 1, A = rnorm(80), B = rnorm(80), C = rnorm(80))
fit <- fit_var(d, vars = c("A", "B", "C"), id = "id")
edges(fit)

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