%% Create Prior Model for SSVS
% Consider the multiple linear regression model that predicts the US real gross national product (GNPR) using a linear combination of industrial production index (IPI), total employment (E), and real wages (WR).
% \texttt{GNPR}_t=\beta_0+\beta_1\texttt{IPI}_t+\beta_2\texttt{E}_t+\beta_3\texttt{WR}_t+\varepsilon_t.
% For all t, \varepsilon_t is a series of independent Gaussian disturbances with a mean of 0 and variance \sigma^2.
% Assume these prior distributions for k = 0,...,3:
% \beta_k\vert\sigma^2,\gamma_k = \gamma_k\sqrt{V_{k1}}Z_1 + (1 - \gamma_k)\sqrt{V_{k2}}Z_2, where Z_1 and Z_2 \;are independent, standard normal random variables. Therefore, the coefficients have a Gaussian mixture distribution. Assume all coefficients are conditionally independent, a priori.
% \sigma^2 \sim IG(A,B). A and B are the shape and scale, respectively, of an inverse gamma distribution.
% \gamma_k \in \left\lbrace 0,1\right\rbraceand it represents the random variable-inclusion regime variable with a  discrete uniform distribution.
% Create a prior model for SSVS. Specify the number of predictors p.

p = 3;
PriorMdl = mixsemiconjugateblm(p);

% PriorMdl is a mixsemiconjugateblm Bayesian linear regression model object representing the prior distribution of the regression coefficients and disturbance variance. mixsemiconjugateblm displays a summary of the prior distributions at the command line.
% Alternatively, you can create a prior model for SSVS by passing the number of predictors to bayeslm and setting the ModelType name-value pair argument to 'mixsemiconjugate'.

MdlBayesLM = bayeslm(p,'ModelType','mixsemiconjugate')

% Mdl and MdlBayesLM are equivalent model objects.
%
% You can set writable property values of created models using dot notation. Set the regression coefficient names to the corresponding variable names.

PriorMdl.VarNames = ["IPI" "E" "WR"]

% MATLAB® associates the variable names to the regression coefficients in displays.
% Plot the prior distributions.

plot(PriorMdl);

% The prior distribution of each coefficient is a mixture of two Gaussians: both components have a mean of zero, but component 1 has a large variance relative to component 2. Therefore, their  distributions are centered at zero and have the spike-and-slab appearance.
%
% Copyright 2018 The MathWorks, Inc.
%