% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bvar.R
\name{bvar}
\alias{bvar}
\title{Fit a Bayesian multilevel VAR network model}
\usage{
bvar(
  id_col,
  time_col,
  y_cols,
  x_cols = NULL,
  center_x = FALSE,
  fe_interactions = NULL,
  re_interactions = NULL,
  re_cols = NULL,
  re_temporal = FALSE,
  K = 1,
  na_action = c("listwise"),
  skip_lag = TRUE,
  data,
  family = c("bernoulli", "ordinal", "gaussian"),
  priors = set_priors(),
  iter = 4000,
  warmup = 1000,
  chains = 4,
  cores = 1,
  seed = NULL,
  adapt_delta = NULL,
  max_treedepth = NULL,
  save_data = FALSE
)
}
\arguments{
\item{id_col}{Character. Name of the subject/group identifier column.}

\item{time_col}{Character. Name of the time column.}

\item{y_cols}{Character vector. Names of the outcome columns.}

\item{x_cols}{Character vector or NULL. Names of the covariate columns.}

\item{center_x}{Logical. Grand-mean centre covariates before fitting?
Default \code{FALSE}.}

\item{fe_interactions}{List or NULL. Fixed-effect interaction terms to add
to the design matrix. Each element is a character vector of column names
to interact, or \code{c("lag", "x")} to interact all lag columns with
a covariate.}

\item{re_interactions}{List or NULL. Random-effect interaction terms.}

\item{re_cols}{Character vector. Columns from X and/or "Intercept" to include as random slopes.}

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

\item{K}{Integer. AR order. Default 1.}

\item{na_action}{Character. Missing-data strategy; currently only
\code{"listwise"}.}

\item{skip_lag}{Logical. If \code{TRUE} (default), rows with irregular time
gaps have their lag set to zero rather than being dropped.}

\item{data}{Data frame in long format.}

\item{family}{Character scalar or vector. Observation model per node.
A scalar is recycled to all \code{y_cols}. A vector of length
\code{length(y_cols)} (named or positional) specifies per-node families.
Valid values: \code{"bernoulli"}, \code{"ordinal"}, \code{"gaussian"}.}

\item{priors}{A \code{bvarnet_priors} object from \code{set_priors()}.
Defaults to \code{set_priors()} (package defaults).}

\item{iter}{Integer. Number of post-warmup iterations per chain. Default 4000.}

\item{warmup}{Integer. Number of warmup iterations per chain. Default 1000.}

\item{chains}{Integer. Number of MCMC chains. Default 4.}

\item{cores}{Integer. Number of chains to run in parallel. Default 1.}

\item{seed}{Integer or NULL. RNG seed.}

\item{adapt_delta}{Numeric in (0, 1). Target average proposal acceptance
probability during warmup adaptation. Higher values (e.g., 0.95–0.99)
reduce divergences at the cost of slower sampling. Default \code{NULL}
(CmdStan default of 0.8).}

\item{max_treedepth}{Integer. Maximum depth of the NUTS binary tree.
Increasing this allows the sampler to take more leapfrog steps per
iteration, which can help with difficult posteriors (e.g., funnels in
hierarchical logistic models) but increases computation. Default
\code{NULL} (CmdStan default of 10).}

\item{save_data}{Logical. If \code{TRUE}, store the preprocessed (sorted,
listwise-deleted) estimation data in the \code{data_used} slot of the
returned object for reproducibility and downstream analyses.
Default \code{FALSE}.}
}
\value{
A \code{bvarnet} object (a named list) with slots:
\code{draws}, \code{convergence}, \code{diagnostics}, \code{timing},
\code{metadata}, \code{return_codes}, \code{family}, \code{standata},
\code{priors}. If \code{save_data = TRUE}, also includes
\code{data_used} (the cleaned estimation data frame).
}
\description{
The \code{bvar} function estimates the posterior distribution of the specified Bayesian (Multilevel) Vector Autoregression.
}
\examples{
\dontrun{
# Run bvar on studentlife data
data(studentlife, package = "bvarnet")
fit <- bvar(
  id_col = "id",
  time_col = "time",
  y_cols = c("anxious", "calm", "conventional", "critical", "dependable"),
  re_temporal = TRUE,
  K = 1,
  data = studentlife,
  family = "ordinal",
  priors = set_priors(),
  seed = 1337)

summary(fit)
}
}
