% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sim_bvarnet.R
\name{sim_var}
\alias{sim_var}
\title{Simulate data from a multilevel VAR model}
\usage{
sim_var(
  N,
  T_obs,
  p,
  K = 1L,
  family = c("bernoulli", "ordinal", "gaussian"),
  alpha = NULL,
  gamma = NULL,
  Phi = NULL,
  sigma = NULL,
  kappa = NULL,
  q = 0L,
  x_gen = NULL,
  sd_alpha = 0.5,
  sd_phi = 0.2,
  sd_gamma = NULL,
  re_temporal = FALSE,
  C = 5L,
  burnin = 500L,
  seed = NULL
)
}
\arguments{
\item{N}{Integer. Number of subjects (groups).}

\item{T_obs}{Integer. Number of time points per subject.}

\item{p}{Integer. Number of outcome nodes.}

\item{K}{Integer. AR order (default 1).}

\item{family}{Character. One of \code{"bernoulli"}, \code{"ordinal"},
\code{"gaussian"}.}

\item{alpha}{Numeric vector of length \code{p}. Population intercepts
(on logit scale for bernoulli, identity for gaussian). For ordinal,
this is absorbed into kappa and should be left NULL. Generated if NULL.}

\item{gamma}{Matrix \code{q x p}. Population covariate effects. Generated
if NULL and \code{q > 0}.}

\item{Phi}{Matrix \code{(p*K) x p}. Population lag coefficients. Generated
if NULL.}

\item{sigma}{Numeric vector of length \code{p}. Residual SD per node
(gaussian only). Generated if NULL.}

\item{kappa}{List of \code{p} ordered vectors, each of length \code{C-1}.
Cutpoints per node (ordinal only). Generated if NULL.}

\item{q}{Integer. Number of covariates (default 0).}

\item{x_gen}{Function \code{f(N, T_obs)} returning an \code{N x T_obs x q}
array of covariates. If NULL, default generation is used.}

\item{sd_alpha}{Numeric. SD of random intercepts (scalar or p-vector).
Default 0.5. Set to 0 to simulate a fixed-effects-only model with no
between-person variation in intercepts.}

\item{sd_phi}{Numeric. SD of random lag coefficients (scalar or matrix).
Default 0.2.}

\item{sd_gamma}{Numeric or NULL. SD of random covariate slopes. NULL means
no random slopes on covariates.}

\item{re_temporal}{Logical. Include random slopes on lag predictors?
Default FALSE.}

\item{C}{Integer. Number of ordinal categories (ordinal only, default 5).}

\item{burnin}{Integer. Number of time points to discard as warmup before
recording data (default 500). The VAR process is simulated for
\code{burnin + T_obs} time points per subject, and the first
\code{burnin} are discarded. This allows the process to reach its
stationary distribution before data collection begins.}

\item{seed}{Integer or NULL. RNG seed.}
}
\value{
A list with two components:
\describe{
\item{data}{A long-format data frame with columns \code{id}, \code{t},
\code{y_1}, ..., \code{y_p}, and optionally \code{x_1}, ..., \code{x_q}.}
\item{truth}{A list of true generating parameters.}
}
}
\description{
Generates data from the generative model implied by each Stan model family.
Useful for testing parameter recovery and model validation.
}
\details{
To simulate a VAR without any random effects (i.e. all subjects share
identical parameters), set \code{sd_alpha = 0}, \code{re_temporal = FALSE}
(the default), and \code{sd_gamma = NULL} (the default).
}
