### 11.1 Vector Autoregressive (VAR) model for time-series data

Mathematical representation

${\mathbf{y}}_{t}={\mathbf{A}}_{0}{\mathbf{w}}_{t}+\sum _{j=1}^{p}{\mathbf{A}}_{j}{\mathbf{y}}_{t-j}+{𝜀}_{t},\phantom{\rule{2em}{0ex}}\phantom{\rule{1em}{0ex}}{𝜀}_{t}\sim \mathrm{N}\left(\mathbf{0},{\Omega }^{-1}\right)$

where:

• the model contains $M$ endogenous variables ($y$s)
• the model is estimated using $T$ observations ($t=1,2,\dots ,T$)
• ${\mathbf{y}}_{t}$ is an $M×1$ vector, which contains the values of the $M$ endogenous variables at time $t$
• ${\mathbf{w}}_{t}$ is a $K\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector, which contains the values of the exogenous variables (common to all equations) at time $t$
• ${\mathbf{A}}_{0}$ is an $M×K$ matrix of parameters associated with the exogenous variables
• ${\mathbf{A}}_{j}$ is an $M×M$ matrix of parameters, $j=1,2\dots ,p$
• in total, there are $L\phantom{\rule{0.3em}{0ex}}=\phantom{\rule{0.3em}{0ex}}\left(M\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}p\phantom{\rule{0.3em}{0ex}}+\phantom{\rule{0.3em}{0ex}}K\right)\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}M$ slope parameters to be estimated (in all $\mathbf{A}$s)
• ${𝜀}_{t}$ is an $M×1$ vector of errors at time $t$, which follows a multivariate Normal distribution with mean $\mathbf{0}$ and precision matrix $\Omega$

With $T$ time observations, an equivalent representation of the model is:

$\mathbf{Y}=\mathbf{X}\mathbf{A}+\mathbf{E}$

where:

$\underset{\left(T-p\right)×M}{\mathbf{Y}}=\left[\begin{array}{c}\hfill {\mathbf{y}}_{p+1}^{\prime }\hfill \\ \hfill {\mathbf{y}}_{p+2}^{\prime }\hfill \\ \hfill ⋮\hfill \\ \hfill {\mathbf{y}}_{T}^{\prime }\hfill \end{array}\right]\phantom{\rule{2em}{0ex}}\phantom{\rule{2em}{0ex}}\underset{\left(T-p\right)×M}{\mathbf{E}}=\left[\begin{array}{c}\hfill {𝜀}_{p+1}^{\prime }\hfill \\ \hfill {𝜀}_{p+2}^{\prime }\hfill \\ \hfill ⋮\hfill \\ \hfill {𝜀}_{T}^{\prime }\hfill \end{array}\right]\phantom{\rule{2em}{0ex}}\phantom{\rule{2em}{0ex}}\underset{\left(M\cdot p+K\right)×M}{\mathbf{A}}=\left[\begin{array}{c}\hfill {\mathbf{A}}_{0}^{\prime }\hfill \\ \hfill {\mathbf{A}}_{1}^{\prime }\hfill \\ \hfill ⋮\hfill \\ \hfill {\mathbf{A}}_{p}^{\prime }\hfill \end{array}\right]$

and:

$\underset{\left(T-p\right)×\left(K+M\cdot p\right)}{\mathbf{X}}=\left[\begin{array}{ccccc}\hfill {\mathbf{w}}_{p+1}^{\prime }\hfill & \hfill {\mathbf{y}}_{p}^{\prime }\hfill & \hfill {\mathbf{y}}_{p-1}^{\prime }\hfill & \hfill \dots \hfill & \hfill {\mathbf{y}}_{1}^{\prime }\hfill \\ \hfill {\mathbf{w}}_{p+2}^{\prime }\hfill & \hfill {\mathbf{y}}_{p+1}^{\prime }\hfill & \hfill {\mathbf{y}}_{p}^{\prime }\hfill & \hfill \dots \hfill & \hfill {\mathbf{y}}_{2}^{\prime }\hfill \\ \hfill ⋮\hfill & \hfill ⋮\hfill & \hfill ⋮\hfill & \hfill \ddots \hfill & \hfill ⋮\hfill \\ \hfill {\mathbf{w}}_{T}^{\prime }\hfill & \hfill {\mathbf{y}}_{T-1}^{\prime }\hfill & \hfill {\mathbf{y}}_{T-2}^{\prime }\hfill & \hfill \dots \hfill & \hfill {\mathbf{y}}_{T-p}^{\prime }\hfill \end{array}\right]$

In this representation the endogenous variables are expanded over the columns of $\mathbf{Y}$ and the time observations are stacked one under the other.

Yet another representation is:

$\mathbf{y}=\left({\mathbf{I}}_{M}\otimes \mathbf{X}\right)\alpha +𝜀,\phantom{\rule{2em}{0ex}}𝜀\sim \mathrm{N}\left(\mathbf{0},{\left(\Omega \otimes {\mathbf{I}}_{M}\right)}^{-1}\right)$

where:

• $\mathbf{y}$ is the $\left(T-p\right)\cdot M×1$ obtained by stacking the columns of $\mathbf{Y}$
• $𝜀$ is the $\left(T-p\right)\cdot M×1$ obtained by stacking the columns of $\mathbf{E}$
• $\alpha$ is the $\left(M\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}p\phantom{\rule{0.3em}{0ex}}+\phantom{\rule{0.3em}{0ex}}K\right)\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}M\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector obtained by stacking the columns of $\mathbf{A}$

In this representation the data are ﬁrst stacked over time and then by variable.

Priors

 Parameter Probability density function Default hyperparameters $\alpha$ $p\left(\alpha \right)=\frac{|\mathbf{P}{|}^{1∕2}}{{\left(2\pi \right)}^{L∕2}}exp\left\{-\frac{1}{2}{\left(\alpha -\mathbf{m}\right)}^{\prime }\mathbf{P}\left(\alpha -\mathbf{m}\right)\right\}$ $\mathbf{m}={\mathbf{0}}_{L}$, $\mathbf{P}=0.001\cdot {\mathbf{I}}_{L}$ $\Omega$ $p\left(\Omega \right)=\frac{|\Omega {|}^{\frac{n-M-1}{2}}|{\mathbf{V}}^{-1}{|}^{n∕2}}{{2}^{nM∕2}{\Gamma }_{M}\left(\frac{n}{2}\right)}exp\left\{-\frac{1}{2}tr\left({\mathbf{V}}^{-1}\Omega \right)\right\}$ $n={M}^{2}$, $\mathbf{V}=\frac{100}{M}\cdot {\mathbf{I}}_{M}$

Syntax

$\left[$<model name> = $\right]$ varm( { y1, y2, , yM } $\left[$ ~w1 w2 …wK $\right]$ $\left[$, <options> $\right]$ );

where:

• y1, y2, …, yM are the names of the endogenous variables, as they appear in the dataset used for estimation
• w1 w2 $\dots$wK is a list of the $K$ exogenous variable names, as they appear in the dataset used for estimation; these variables will be included in all equations, but if there is need to restrict the model so that of any of them do not appear in an equation, this can be achieved by restricting the associated parameters in the prior; when a constant term is to be included in the model, this must be requested explicitly

 Before using the varm() function the dataset used for estimation must be declared as a time-series dataset using the set_ts() function (see section B.13).

The optional arguments for the vector autoregressive model are:1

 Specification of lags "lags" a vector of integers (either row or column vector) indicating the lags of the endogenous variables to be included in the right-hand side of the model; for example, if this vector is set equal to [1, 4, 9], then the 1st, 4th and 9th lags are included; the default value is 1, in which case, only the ﬁrst lag of all endogenous are included Gibbs parameters "chains" number of chains to run in parallel (positive integer); the default value is 1 "burnin" number of burn-in draws per chain (positive integer); the default value is 10000 "draws" number of retained draws per chain (positive integer); the default value is 20000 "thin" value of the thinning parameter (positive integer); the default value is 1 "seed" value of the seed for the random-number generator (positive integer); the default value is 42 Hyperparameters "m" mean vector of the prior for $\alpha$ ($L\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}1$ vector); the default value is ${\mathbf{0}}_{L}$ "P" precision matrix of the prior for $\alpha$ ($L\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}L$ symmetric and positive-deﬁnite matrix); the default value is $0.001\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}{\mathbf{I}}_{L}$ "V" scale matrix of the prior for $\Omega$ ($M\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}M$ symmetric and positive-deﬁnite matrix); the default value is $\frac{100}{M}\phantom{\rule{0.3em}{0ex}}\cdot \phantom{\rule{0.3em}{0ex}}{\mathbf{I}}_{M}$ "n" degrees-of-freedom parameter of the prior for $\Omega$ (real number greater than or equal to $M$); the default value is ${M}^{2}$ Dataset and log-marginal likelihood "dataset" the id value of the dataset that will be used for estimation; the default value is the ﬁrst dataset in memory (in alphabetical order) "logML_CJ" boolean indicating whether the Chib (1995)/Chib & Jeliazkov (2001) approximation to the log-marginal likelihood should be calculated (true$|$false); the default value is false

Reported Parameters

 $\alpha$ variable_name vector of parameters associated with the exogenous variables and the lags of the endogenous variables; these are broken into groups according to the equation in which the variables appear and the parameters associated with the exogenous variables are listed ﬁrst

Stored values and post-estimation analysis
If a left-hand-side id value is provided when a VAR model is created, then the following results are saved in the model item and are accessible via the ‘.’ operator:

 Samples a matrix containing the draws from the posterior of $\alpha$ (across all equations, starting from the ﬁrst equation) and the unique elements of $\Omega$ ym$w1,$\dots$,ym$wK vectors containing the draws from the posterior of the parameters associated with the exogenous variables w1,$\dots$,wK, for $m=1,2,\dots ,M$ (the names of these vectors are the names of the exogenous variables that were included in the model, prepended by ym$, where ym is the name of the dependent variable in equation $m$) ym$yl_tms,$\dots$ vectors containing the draws from the posterior of the parameters associated with the lags of the endogenous variables for $m,l=1,2,\dots ,M$ (the names of these vectors are the names of the exogenous variables, appended by _tms, where s is the sth lag, and prepended by ym$, where ym is the name of the dependent variable in equation $m$) Omega_i_j vectors containing the draws from the posterior of the unique elements of $\Omega$; because $\Omega$ is symmetric, only $\frac{\left(M-1\right)M}{2}\phantom{\rule{0.3em}{0ex}}+\phantom{\rule{0.3em}{0ex}}M$ of its elements are stored (instead of all ${M}^{2}$ elements); i and j index the row and column of $\Omega$, respectively, at which the corresponding element is located Omega $M\phantom{\rule{0.3em}{0ex}}×\phantom{\rule{0.3em}{0ex}}M$ matrix that stores the posterior mean of $\Omega$ logML the Lewis & Raftery (1997) approximation of the log-marginal likelihood logML_CJ the Chib (1995)/Chib & Jeliazkov (2001) approximation to the log-marginal likelihood; this is available only if the model was estimated with the "logML_CJ"=true option nchains the number of chains that were used to estimate the model nburnin the number of burn-in draws per chain that were used when estimating the model ndraws the total number of retained draws from the posterior ($=$chains $\cdot$ draws) nthin value of the thinning parameter that was used when estimating the model nseed value of the seed for the random-number generator that was used when estimating the model Additionally, the following functions are available for post-estimation analysis (see section B.14): • diagnostics() • test() • pmp() • forecast() • irf() Examples Example 1 myData = import("$BayESHOME/Datasets/dataset6.csv", ",");
myData.constant = 1;
set_ts( time, "dataset"=myData);

varm( {y1,y2,y3} ~ constant w );

Example 2

myData = import("\$BayESHOME/Datasets/dataset6.csv", ",");
myData.constant = 1;
set_ts( time, "dataset"=myData);

myModel = varm( {y1,y2,y3} ~ constant w );

forecast( "horizon"=10, "model"=myModel );

irf( "horizon"=20, "model"=myModel );

1Optional arguments are always given in option-value pairs (eg. "chains"=3).