%% Inspect Minnesota Prior Assumptions Among Models
% Consider the 3-D VAR(4) model for the US inflation (INFL), unemployment (UNRATE), and federal funds (FEDFUNDS) rates.
% \left[ {\begin{array}{*{20}{l}}
% {\texttt{INFL}_t}\\
% {\texttt{UNRATE}_t}\\
% {\texttt{FEDFUNDS}_t}
% \end{array}} \right] = c + \sum\limits_{j = 1}^4 {{\Phi _j}\left[ {\begin{array}{*{20}{l}}
% {\texttt{INFL}_{t-j}\\
% {\texttt{UNRATE}_{t-j}\\
% {\texttt{FEDFUNDS}_{t-j}
% \end{array}} \right]} + \left[ {\begin{array}{*{20}{c}}
% {{\varepsilon _{1,t}}}\\
% {{\varepsilon _{2,t}}}\\
% {{\varepsilon _{3,t}}}
% \end{array}} \right].
% For all t, \varepsilon_t is a series of independent 3-D normal innovations with a mean of 0 and covariance \Sigma. Assume that a prior distribution \pi \left({\left\lbrack \Phi_1 ,\ldotp \ldotp \ldotp ,\Phi_4 ,c\right\rbrack }^{\prime } ,\Sigma \right) governs the behavior of the parameters. Consider using Minnesota regularization to obtain a parsimonious  representation of the coefficient posterior distribution.
% For each supported prior assumption, create the corresponding Bayesian VAR(4) model object for the three response variables by using bayesvarm. For each model that supports the option, specify all the following.
% The response variable names.
% Prior self-lag coefficients have variance 100. This large-variance setting allows the data to influence the posterior more than the prior.
% Prior cross-lag coefficients have variance 1. This small-variance setting tightens the cross-lag coefficients to zero during estimation.
% Prior coefficient covariances decay with increasing lag at a rate of 2 (that is, lower lags are more important than larger lags).
% For the normal conjugate prior model, assume that the innovations covariance is the 3-D identity matrix.

seriesnames = ["INFL" "UNRATE" "FEDFUNDS"];
numseries = numel(seriesnames);
numlags = 4;

DiffusePriorMdl = bayesvarm(numseries,numlags,'SeriesNames',seriesnames);
ConjugatePriorMdl = bayesvarm(numseries,numlags,'ModelType','conjugate',...
    'SeriesNames',seriesnames,'Center',0.75,'SelfLag',100,'Decay',2);
SemiConjugatePriorMdl = bayesvarm(numseries,numlags,'ModelType','semiconjugate',...
    'SeriesNames',seriesnames,'Center',0.75,'SelfLag',100,'CrossLag',1,'Decay',2);
NormalPriorMdl = bayesvarm(numseries,numlags,'ModelType','normal',...
    'SeriesNames',seriesnames,'Center',0.75,'SelfLag',100,'CrossLag',1,'Decay',2,...
    'Sigma',eye(numseries));

% For each model, display summary of the prior distribution.

summarize(DiffusePriorMdl)

% Diffuse prior models put equal weight on all model coefficients.  This specification allows the data to determine the posterior distribution.

summarize(ConjugatePriorMdl)

% With a tighter prior variance around 0 for larger lags, the posterior of the conjugate model is likely to be more sparse that the posterior of the diffuse model.

summarize(SemiConjugatePriorMdl)
summarize(NormalPriorMdl)

% Semiconjugate and normal conjugate prior models yield a richer prior specification than the conjugate and diffuse models.
% Copyright 2019 The MathWorks, Inc.