%% Empirical Prior Model
% Consider the multiple linear regression model from Default Diffuse Prior Model, but instead suppose that from prior experience, the distributions are:
% \beta_j\vert\sigma^2 is 4-dimensional t distribution with 3 degrees of freedom for each component and correlation matrix
% \;\;\;C = \left[ {\begin{array}{*{20}{c}} 1&{0.6}&{ - 0.1}&0\\
% {0.6}&1&{0.25}&{ - 0.7}\\ { - 0.1}&{0.25}&1&{0.1}\\ 0&{ - 0.7}&{0.1}&1
% \end{array}} \right].
% \sigma^2 \sim IG(4,5).
% bayeslm treats these assumptions and the data likelihood as if the corresponding posterior is analytically intractable.
% Draw a random sample of size 1e6 from each prior distribution. Successive samples should correspond to columns, and parameters to rows.

n = 1e6;
C = [1 0.6 -0.1 0; 0.6 1 0.25 -0.7; -0.1 0.25 1 0.1; 0 -0.7 0.1 1];
dof = 3;
a = 4;
b = 5;
rng(1); % For reproducibility
BetaDraws = (mvtrnd(C,dof,n))';
Sigma2Draws = 1./gamrnd(a,b,1,n);

% BetaDraws is a 1e6-by-4 matrix representing draws from the multivariate t distribution. Sigma2Draws is a 1-by-|1e6| vector of draws from the inverse gamma distribution.
%
% Create an empirical joint prior model for the linear regression parameters. Specify the number of predictors, p, and specify the draws from the respective prior distributions.

p = 3;
Mdl = bayeslm(p,'ModelType','empirical','BetaDraws',BetaDraws,...
    'Sigma2Draws',Sigma2Draws)

% Mdl is an empiricalblm Bayesian linear regression model object representing the prior distribution of the regression coefficients and disturbance variance. At the command window, bayeslm displays a summary of the prior distributions.
% Copyright 2012 The MathWorks, Inc.