%% Specify Values for Density Evaluation and Plotting
% Consider the regression model in docid:econ_ug.bvmukh8.
% Load the Nelson-Plosser data set and create a default conjugate prior model for the regression coefficients and disturbance variance. Then, estimate the posterior distribution and obtain the estimation summary table from summarize.

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

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

PosteriorMdl = estimate(PriorMdl,X,y);
summaryTbl = summarize(PosteriorMdl);
summaryTbl = summaryTbl.MarginalDistributions;

% summaryTbl is a table containing the statistics that estimate displays at the command line.
%
% For each parameter, determine a set of 50 evenly spaced values within three standard deviations of the mean. Put the values into the cells of a 5-by-1 cell vector following the order of the parameters that comprise the rows of the estimation summary table.

Points = cell(numel(summaryTbl.Mean),1); % Preallocation

for j = 1:numel(summaryTbl.Mean)
    Points{j} = linspace(summaryTbl.Mean(j) - 3*summaryTbl.Std(j),...
        summaryTbl.Mean(j) + 2*summaryTbl.Std(j),50);
end

%
% Plot the posterior distributions within their respective intervals.

plot(PosteriorMdl,'Points',Points)

% Copyright 2018 The MathWorks, Inc.