\documentclass[notitlepage]{article}
\usepackage{../../Math545}
\usepackage{listings}
\usepackage{numprint}
\usepackage{enumerate}
\usepackage{bbm}
\usepackage{bm}

\usepackage{amsfonts,amsmath,amssymb}

\newtheorem{alg}{Algorithm}
\newtheorem{ex}{Example}
\newtheorem{note}{Note}
\newenvironment{proof}{\par\noindent{\normalfont{\bf{Proof
}}}}
{\hfill \small$\blacksquare$\\[2mm]}


\setlength{\parindent}{0in}

\def\E{\mathbb{E}}
\def\Var{\text{Var}}
\def\Cov{\text{Cov}}
\def\Corr{\text{Corr}}

\def\bW{\mathbf{W}}

\newcommand{\bs}[1]{\bm{#1}}
\newcommand{\Rho}{\mathrm{P}}
\newcommand{\cif}{\text{ if }}
\newcommand{\Ra}{\Longrightarrow}
\newcommand{\ra}{\longrightarrow}

\def\bphi{\boldsymbol \phi}


\lstloadlanguages{R}

\definecolor{keywordcolor}{rgb}{0,0.6,0.6}
\definecolor{delimcolor}{rgb}{0.461,0.039,0.102}
\definecolor{Rcommentcolor}{rgb}{0.101,0.043,0.432}

\lstdefinestyle{Rsettings}{
  basicstyle=\ttfamily,
  breaklines=true,
  showstringspaces=false,
  keywords={if, else, function, theFunction, tmp}, % Write as many keywords
  otherkeywords={},
  commentstyle=\itshape\color{Rcommentcolor},
  keywordstyle=\color{keywordcolor},
  moredelim=[s][\color{delimcolor}]{"}{"},
}

\lstset{basicstyle=\ttfamily, numbers=none, literate={~} {$\sim$}{2}}

\def\ctitle{MATH 545: Introduction to Time Series Analysis}
\def\ttitle{Winter 2025}
\def\stitle{Vector Autoregression Models}

\begin{document}

<<setup, cache=FALSE, echo=FALSE>>=
library(knitr)
# global chunk options
opts_chunk$set(cache=TRUE, autodep=TRUE)
options(scipen=999)
options(repos=c(CRAN="https://cloud.r-project.org/"))
@

\maketitle

Consider the model
\begin{eqnarray*}
X_{1,t} &=& \phi_{10} + \phi_{11} X_{1,t-1} + \phi_{12} X_{2,t-1} + Z_{1,t}\\
X_{2,t} &=& \phi_{20} + \phi_{21} X_{1,t-1} + \phi_{22} X_{2,t-1} + Z_{2,t}
\end{eqnarray*}
The elements of
\[
\bPhi = \left[\begin{array}{cc} \phi_{11} & \phi_{12} \\  \phi_{21} & \phi_{22} \end{array} \right]
\]
define the dependence of current elements of $\bX_t$ on past elements.  Let
\[
\Sigma = \bL \bG \bL^\top
\]
be a Cholesky decomposition where $\bG$ is a diagonal matrix, and $\bL$ is a lower-triangular matrix, where the diagonal elements of $\bL$ are all equal to 1.  Define $\bU_t = \bL^{-1} \bZ_t$.  Then
\[
\E[\bU_t] = \bm{0} \qquad \qquad \Var[\bU_t] = \bG
\]
so that the elements of $\bU_t$ are uncorrelated.  Then
\[
\bL^{-1} \bX_t = \bL^{-1} \bphi_0 + \bL^{-1} \bPhi \bX_{t-1} + \bL^{-1} \bZ_t
\]
so that
\[
\bL^{-1} \bX_t = \bphi^\star + \bPhi^\star \bX_{t-1} + \bU_t
\]
say. Thus, as $\bL$ is lower-triangular, the $K$th row of this vector equation is
\[
X_{K,t} + \sum_{k=1}^{K-1} L_{Kk} X_{k,t} = \phi_{K0}^\star + \sum_{k=1}^{K} \phi_{Kk}^\star X_{k,t-1} + U_{K,t}
\]
As the elements of $\bU_t$ are uncorrelated, this equation shows explicitly the concurrent dependence of $X_{K,t}$ on $X_{k,t}$, for $k=1,\ldots,K-1$.  A similar expression can be found for each of the elements of $\bX_t$. 

\medskip

\textbf{Example:} Let
\[
\left[ \begin{array}{c} X_{1,t} \\ X_{2,t} \end{array} \right] =
\left[ \begin{array}{c} 0.2 \\ 0.4 \end{array} \right] +
\left[ \begin{array}{rr} 0.2 & 0.3 \\ -0.6 & 1.1 \end{array} \right]
\left[ \begin{array}{c} X_{1,t-1} \\ X_{2,t-1} \end{array} \right] +
\left[ \begin{array}{c} Z_{1,t} \\ Z_{2,t} \end{array} \right]
\]
with
\[
\Sigma = \left[ \begin{array}{rr} 2 & 1 \\ 1 & 1 \end{array} \right]
\]
Then
\[
\bL^{-1} = \left[ \begin{array}{rr} 1.0 & 0.0 \\ -0.5 & 1.0 \end{array} \right]  \qquad
\bG = \bL^{-1} \Sigma ( \bL^\top )^{-1} = \left[ \begin{array}{rr} 2.0 & 0.0 \\ 0.0 & 0.5 \end{array} \right]
\]

Using the above structural equation formulation:
\begin{eqnarray*}
X_{2,t} & = & 0.3 + 0.5 X_{1,t} -0.7 X_{1,t-1} + 0.95 X_{2,t-1} + U_{2,t}
\end{eqnarray*}
and
\begin{eqnarray*}
X_{1,t} & = & -0.2 + 1.0 X_{2,t} -0.8 X_{2,t-1} + 0.8 X_{1,t-1} + U_{1,t}
\end{eqnarray*}
where $U_{2,t} \sim \calN(0,0.5)$ and $U_{1,t} \sim \calN(0,1)$ are independent random
variables.

<<var1,fig.height=6,fig.width=8>>=
library(mvnfast)
n<-1000
Sigma<-matrix(c(2,1,1,1),nrow=2,byrow=T)
Phi<-matrix(c(0.2,0.3,-0.6,1.1),nrow=2,byrow=T)
Phi0<-c(0.2,0.4)
Zt<-rmvn(n,c(0,0),Sigma)
Xt<-matrix(0,nrow=n,ncol=2)
for(i in 2:n){
    Xt[i,]<-Phi0+Phi %*% Xt[i-1,] + Zt[i,]
}
par(mar=c(2,2,4,4))
acf(Xt)
@

\medskip

Now for the usual Cholesky decomposition, we have
\[
\bC \bC^\top = \Sigma
\]
where $\bC$ is lower triangular, but here we want
\[
\bL \bG \bL^\top = \Sigma.
\]
The diagonal elements of $\bC$ are square roots of the diagonal elements of $\Sigma$.  Hence $\bC = \bL \bG^{1/2}$ so that $\bL = \bC \bG^{-1/2}$.  We then have
\[
\Var[\bU_t] = \Var[ \bL^{-1} \bZ_t] = \bL^{-1} \Var[ \bZ_t] \bL^{-\top} = \bL^{-1} \Sigma \bL^{-\top} = \bG.
\]
where $\bL^{-\top}$ is the transpose of $\bL^{-1}$.

<<var2,fig.height=6,fig.width=8>>=
Sigma
Cmat<-t(chol(Sigma))
Cmat
Gmat.root<-diag(diag(Cmat))
Gmat.root
Lmat<-Cmat %*% solve(Gmat.root)
Gmat<-Gmat.root^2
Lmat
Gmat
Linv<-solve(Lmat)
Linv
@
We can then compute
\[
\bphi^\ast = \bL^{-1} \bphi_0
\]
<<var3>>=
Phi0star<-Linv %*% Phi0
Phi0star
@
and
\[
\bPhi^\ast = \bL^{-1} \bPhi
\]
<<var4>>=
Phistar<-Linv %*% Phi
Phistar
@
To obtain the structural equation for $X_{2,t}$, we note that
\[
\bL^{-1} \bX_t = \bphi^\star + \bPhi^\star \bX_{t-1} + \bU_t
\]
becomes
\[
\begin{bmatrix}
  \Sexpr{Linv[1,1]} & \Sexpr{Linv[1,2]} \\[6pt]
  \Sexpr{Linv[2,1]} & \Sexpr{Linv[2,2]} 
\end{bmatrix}
\begin{bmatrix}
  X_{1,t} \\[6pt]
  X_{2,t}
\end{bmatrix} = \begin{bmatrix}
  \Sexpr{Phi0star[1]} \\[6pt]
  \Sexpr{Phi0star[2]}
\end{bmatrix} + \begin{bmatrix}
  \Sexpr{Phistar[1,1]} & \Sexpr{Phistar[1,2]} \\[6pt]
  \Sexpr{Phistar[2,1]} & \Sexpr{Phistar[2,2]} 
\end{bmatrix}
\begin{bmatrix}
  X_{1,t-1} \\[6pt]
  X_{2,t-1}
\end{bmatrix} + \begin{bmatrix}
  U_{1,t} \\[6pt]
  U_{2,t}
\end{bmatrix}
\]
from which we can deduce via the second equation that
\[
-0.5 X_{1,t} + X_{2,t} = 0.3 - 0.7 X_{1,t-1} + 0.95 X_{2,t-1} + U_{2,t}
\]
that is
\[
X_{2,t} = 0.5 X_{1,t} + 0.3 - 0.7 X_{1,t-1} + 0.95 X_{2,t-1} + U_{2,t}.
\]
Note that from the first equation, we have
\[
X_{1,t} = 0.2 + 0.2 X_{1,t-1} + 0.3 X_{2,t-1} + U_{1,t}
\]
which shows the dependence of $\{X_{1,t}\}$ on lagged values only.

\medskip
To obtain the structural equation for $\{X_{1,t}\}$, we swap the positions of the two variables:  we have
\[
\left[ \begin{array}{c} X_{2,t} \\ X_{1,t} \end{array} \right] =
\left[ \begin{array}{c} 0.4 \\ 0.2 \end{array} \right] +
\left[ \begin{array}{rr} 1.1 & -0.6 \\ 0.3 & 0.2 \end{array} \right]
\left[ \begin{array}{c} X_{1,t-1} \\ X_{2,t-1} \end{array} \right] +
\left[ \begin{array}{c} Z_{2,t} \\ Z_{1,t} \end{array} \right]
\]
with now
\[
\Sigma = \left[ \begin{array}{rr} 1 & 1 \\ 1 & 2 \end{array} \right]
\]

<<var5,fig.height=6,fig.width=8>>=
Sigma<-matrix(c(1,1,1,2),nrow=2,byrow=T)
Phi<-matrix(c(1.1,-0.6,0.3,0.2),nrow=2,byrow=T)
Phi0<-c(0.4,0.2)

Sigma
Cmat<-t(chol(Sigma))
Cmat
Gmat.root<-diag(diag(Cmat))
Gmat.root
Lmat<-Cmat %*% solve(Gmat.root)
Gmat<-Gmat.root^2
Lmat
Gmat
Linv<-solve(Lmat)
Linv
Phi0star<-Linv %*% Phi0
Phi0star
Phistar<-Linv %*% Phi
Phistar
@
so that
\[
\begin{bmatrix}
  \Sexpr{Linv[1,1]} & \Sexpr{Linv[1,2]} \\[6pt]
  \Sexpr{Linv[2,1]} & \Sexpr{Linv[2,2]} 
\end{bmatrix}
\begin{bmatrix}
  X_{2,t} \\[6pt]
  X_{1,t}
\end{bmatrix} = \begin{bmatrix}
  \Sexpr{Phi0star[1]} \\[6pt]
  \Sexpr{Phi0star[2]}
\end{bmatrix} + \begin{bmatrix}
  \Sexpr{Phistar[1,1]} & \Sexpr{Phistar[1,2]} \\[6pt]
  \Sexpr{Phistar[2,1]} & \Sexpr{Phistar[2,2]} 
\end{bmatrix}
\begin{bmatrix}
  X_{2,t-1} \\[6pt]
  X_{1,t-1}
\end{bmatrix} + \begin{bmatrix}
  U_{2,t} \\[6pt]
  U_{1,t}
\end{bmatrix}
\]
yielding the structural equation
\[
X_{1,t} = -0.2 + X_{2,t} + 0.8 X_{1,t-1} - 0.8 X_{2,t-1} + U_{1,t}
\]
where $\Var[U_{1,t}] = 1$, as note that here
\[
\bG = \begin{bmatrix}
        1 & 0 \\[6pt]
        0 & 1 
      \end{bmatrix}
\]
\end{document}
