fit_var_bayes: Build a Bayesian VAR(1) network (unregularized,...

View source: R/var_bayes.R

fit_var_bayesR Documentation

Build a Bayesian VAR(1) network (unregularized, Mplus-targeted)

Description

Native, pure-R Bayesian VAR(1) that reproduces Mplus's Bayesian (DSEM/time-series) estimates without needing Mplus. It is the unregularized Bayesian counterpart of fit_graphical_var(): instead of a graphical-lasso / EBIC sparse fit, it estimates a full VAR(1) with a flat prior on the temporal coefficients and an inverse-Wishart prior on the residual precision, then reports the temporal network B and the contemporaneous partial-correlation network derived from the residual covariance. With more than one subject the data are within-person centred and pooled (as in fit_graphical_var()).

Usage

fit_var_bayes(
  data,
  vars,
  id = NULL,
  day = NULL,
  beep = NULL,
  lags = 1L,
  scale = TRUE,
  center_within = TRUE,
  n_iter = 4000L,
  n_burnin = NULL,
  n_chains = 2L,
  thin = 1L,
  seed = NULL,
  min_obs = NULL,
  subject = NULL,
  verbose = FALSE
)

Arguments

data

A data.frame or matrix.

vars

Character vector of variable names (length >= 2).

id

Character. Person-ID column, or NULL for a single series.

day

Character. Day/session column, or NULL.

beep

Character. Beep/measurement column, or NULL.

lags

Integer lag order; only 1 is supported.

scale

Logical. Global standardization of each variable. Default TRUE.

center_within

Logical. Within-person centre when >1 id (removes between-person variance, as in fit_graphical_var()). Default TRUE.

n_iter, n_burnin, n_chains, thin

MCMC controls. Defaults 4000, n_iter/2, 2, 1.

seed

Integer or NULL. Base seed (chain c uses seed + c).

min_obs

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

subject

Optional vector naming the exact subject(s) to analyse.

verbose

Logical. Progress messages. Default FALSE.

Value

A var_bayes_result object (a cograph group with temporal and contemporaneous netobjects) carrying beta, temporal, kappa, PCC, PDC, posterior draws, and a tidy coefs() table (posterior median, SD, 95% CI, one-tailed p, significance by CI excluding 0).

See Also

fit_graphical_var() (regularized GLASSO/EBIC), fit_var() (OLS), fit_mlvar_bayes() (multilevel Bayesian VAR).

Examples


set.seed(1)
y <- matrix(0, 200, 2)
for (t in 2:200) y[t, ] <- c(0.4, 0.3) * y[t - 1, ] + rnorm(2)
d <- data.frame(A = y[, 1], B = y[, 2])
fit <- fit_var_bayes(d, vars = c("A", "B"), n_iter = 500, seed = 1)
print(fit)
coefs(fit)


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