%% Access Estimates in Estimation Summary Display
% Consider the regression model in docid:econ_ug.mw_33fe5bc0-0b85-4cc1-9474-d2497f40714b.
% Create a prior model for performing SSVS. Assume that \beta and \sigma^2 \;are dependent (a conjugate mixture model). Specify the number of predictors p and the names of the regression coefficients.

p = 3;
PriorMdl = mixconjugateblm(p,'VarNames',["IPI" "E" "WR"]);

%
% Load the Nelson-Plosser data set. Create variables for the response and predictor series.

load Data_NelsonPlosser
X = DataTable{:,PriorMdl.VarNames(2:end)};
y = DataTable{:,'GNPR'};

% Implement SSVS by estimating the marginal posterior distributions of \beta and \sigma^2. Because SSVS uses Markov chain Monte Carlo for estimation, set a random number seed to reproduce the results. Suppress the estimation display, but return the estimation summary table.

rng(1);
[PosteriorMdl,Summary] = estimate(PriorMdl,X,y,'Display',false);

% PosteriorMdl is an empiricalblm model object that stores draws from the posterior distributions of \beta and \sigma^2 given the data. Summary is a table with columns corresponding to posterior characteristics and rows corresponding to the coefficients (PosteriorMdl.VarNames) and disturbance variance (Sigma2).
% Display the estimated parameter covariance matrix (Covariances) and proportion of times the algorithm includes each predictor (Regime).

Covariances = Summary(:,"Covariances")
Regime = Summary(:,"Regime")

% Regime contains the marginal posterior probability of variable inclusion (\gamma =1 for a variable). For example, the posterior probability that E should be included in the model is 0.0925.
% Assuming that variables with Regime < 0.1 should be removed from the model, the results suggest that you can exclude the unemployment rate from the model.
% Copyright 2018 The MathWorks, Inc.