%% Matrix-Normal-Inverse-Wishart Conjugate Prior Model
% Consider the 3-D VAR(4) model in docid:econ_ug.mw_9054b8c2-0e9b-4703-9eed-8be7f867fb43. Assume the following:
% [\Phi_1,...,\Phi_4,c]^\prime\vert\Sigma \sim N_{13\times3}\left({\rm M},V,\Sigma\right). M is a 13-by-3 matrix of prior coefficient means (M\left(1:3,1:3\right) is the prior mean matrix of \Phi_1^{\prime }, M\left(4:6,1:3\right) is the prior mean matrix of \Phi_2^{\prime },..., and M\left(13,1:3\right) is the prior mean vector of c), Vis a 13-by-13 matrix representing the among-coefficient prior covariance matrix within an equation, and \Sigma is the 3-by-3 random innovations covariance matrix.
% \Sigma \sim {\rm Inverse\;Wishart}(\Omega,\nu). \Omega is the 3-by-3 scale matrix and \nu is the degrees of freedom of the inverse Wishart distribution.
% The coefficients and the innovations covariance matrix are dependent.
% Prior coefficient variances among the equations are proportional.
% These assumptions and the data likelihood imply a matrix-normal-inverse-Wishart conjugate model.
% Create a matrix-normal-inverse-gamma conjugate prior model for the VAR model parameters.

numseries = 3;
numlags = 4;
PriorMdl = bayesvarm(numseries,numlags,'ModelType','conjugate')

% PriorMdl is a conjugatebvarm Bayesian VAR model object representing the prior distribution of the coefficients and innovations covariance matrix. bayesvarm displays a summary of the prior distributions at the command line; it returns the prior mean matrix in vectorized form.
% The model contains many estimable parameters. To achieve a parsimonious model, by default, bayesvarm applies the Minnesota  regularization method to the AR coefficient matrices.
% Display the prior means (centers of shrinkage) of the AR coefficient matrices.

AR1 = PriorMdl.AR{1}
AR2 = PriorMdl.AR{2}
AR3 = PriorMdl.AR{3}
AR4 = PriorMdl.AR{4}

% A priori, each series is an AR(1) model with AR coefficient 0.5.
% The tightness on shrinkage of the coefficients are proportional among the equations. Display the diagonal elements of the property V of Mdl, which contains the scaled tightness on shrinkage matrix of the coefficients of one equation (the unscaled shrinkage is \Sigma \otimes V = kron(PriorMdl.Covariance,PriorMdl.V)).

format long
ScaledTightness = diag(PriorMdl.V)

% ScaledTightness(1:3) corresponds to the prior scaled variance of \Phi_{11,1}, \Phi_{12,1}, and \Phi_{13,1}; ScaledTightness(4:6) corresponds to the prior scaled variance of \Phi_{11,2}, \Phi_{12,2}, and \Phi_{13,2}; and so on. The tightnesses decrease with lag, which suggests that, a priori, the means of the corresponding greater-lagged coefficients are more tightly locked around their center of 0.
% Display the tightness of the model constants.

ScaledTightness(end)

% The center of the model constants is 0, but with large variance, which allows the estimation procedure to defer more to the data than the prior for the posterior mean of the constants.
% You can specify alternative values after you create a model by using dot notation.  For example, increase the tightness of all coefficients by a factor of 100.

PriorMdl.V = 100*PriorMdl.V;

% Copyright 2019 The MathWorks, Inc.