% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/complex-models.R
\name{var1}
\alias{var1}
\title{ngme VAR(1) bivariate model specification (Cayley re-parameterization)}
\usage{
var1(mesh = NULL, p1 = 0, p2 = 1, p3 = 0, p4 = 1)
}
\arguments{
\item{mesh}{Integer vector or \code{inla.mesh.1d} object for the time mesh
(length \eqn{T}).  Pass \code{NULL} for deferred construction.}

\item{p1}{Unconstrained skew-symmetric parameter (\eqn{\in \mathbb{R}});
controls the rotation part of the Cayley mapping.  Default \code{0}.}

\item{p2, p3, p4}{Unconstrained lower-triangular Cholesky parameters
(\eqn{\in \mathbb{R}}); control the contraction (positive-definite) part.
Defaults \code{p2 = 1}, \code{p3 = 0}, \code{p4 = 1}.}
}
\value{
An \code{ngme_operator} (or \code{ngme_operator_def} when
  \code{mesh = NULL}) suitable for use inside \code{f()}.
}
\description{
Builds a Vector Autoregressive order-1 (VAR(1)) operator for bivariate
time-series data.  The model follows:
\deqn{Y_t = A\,Y_{t-1} + \varepsilon_t, \quad
  A = \begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix}}
}
\section{Cayley re-parameterization}{

To guarantee stationarity (\eqn{\rho(A) < 1}) at every SGD step, the
\eqn{2 \times 2} coefficient matrix \eqn{A} is obtained via the
\emph{Cayley transform}:
\deqn{A = (I + S)(I - S)^{-1}}
where \eqn{S} is constructed from four unconstrained real parameters
\eqn{(p_1, p_2, p_3, p_4) \in \mathbb{R}^4} as \eqn{S = J - R}:
\describe{
  \item{Skew-symmetric part (rotation):}{
    \eqn{J = \begin{pmatrix} 0 & p_1 \\ -p_1 & 0 \end{pmatrix}}}
  \item{Positive-definite part (contraction):}{
    \eqn{R = L L^{\top} + \varepsilon I}, where
    \eqn{L = \begin{pmatrix} p_2 & 0 \\ p_3 & p_4 \end{pmatrix}}
    and \eqn{\varepsilon = 10^{-5}}.}
}
Because \eqn{S + S^{\top} = -2R} is negative definite, all eigenvalues of
\eqn{S} have strictly negative real parts, and the Cayley transform then
guarantees \eqn{|\lambda_i(A)| < 1} for every \eqn{i}.

The default values \eqn{(p_1, p_2, p_3, p_4) = (0, 1, 0, 1)} give
\eqn{A \approx 0} (no auto-regression at initialization).
}

\section{Precision operator}{

The 2T x 2T precision operator is:
\deqn{K = M_0 + a_{11}\,M_{11} + a_{22}\,M_{22}
         + a_{12}\,M_{12} + a_{21}\,M_{21}}
where the \eqn{M_{ij}} are fixed sparse block matrices constructed from the
\eqn{T \times T} first-order difference matrix \eqn{C_T}.
}

\examples{
set.seed(1)
n_obs <- 10
dat <- data.frame(
  y     = rnorm(2 * n_obs),
  idx   = rep(seq_len(n_obs), 2),
  group = factor(rep(c("y1", "y2"), each = n_obs))
)

fit <- ngme(
  y ~ 0 + f(idx, model = var1(mesh = 1:n_obs), group = group,
            noise = noise_nig()),
  data    = dat,
  family  = noise_normal(sigma = 0.01, fix_sigma = TRUE),
  control_opt = control_opt(estimation = FALSE)
)
print(fit)

}
