%% Create Custom Multivariate _t_ Prior Model for Coefficients
% 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$ time points, $\varepsilon_t$ is a series of independent Gaussian
% disturbances with a mean of 0 and variance $\sigma^2$. Assume these
% prior distributions:
%
% * $\beta_j\vert\sigma^2$ is 4-D _t_ distribution with 50
% degrees of freedom for each component and the identity matrix for the
% correlation matrix.  Also, the distribution is centered at ${\left[
% {\begin{array}{*{20}{c}} { - 25}&4&0&3 \end{array}} \right]^\prime }$ and
% each component is scaled by the corresponding elements of the vector
% ${\left[ {\begin{array}{*{20}{c}} {1}&1&1&1 \end{array}}
% \right]^\prime }$.
%
% * $\sigma^2 \sim IG(3,1)$. 
%
% |bayeslm| treats these assumptions and the data likelihood as if the
% corresponding posterior is analytically intractable.
%%
% Declare a MATLAB(R) function that:
%
% * Accepts values of $\beta$ and $\sigma^2$ together in a column vector,
% and accepts values of the hyperparameters
% * Returns the value of the joint prior distribution,
% $\pi\left(\beta,\sigma^2\right)$, given the values of $\beta$ and
% $\sigma^2$
%
% <include>priorMVTIG.m</include>
%
%%
% Create an anonymous function that operates like |priorMVTIG|, but accepts
% only the parameter values, and holds the hyperparameter values fixed.
dof = 50;
C = eye(4);
ct = [-25; 4; 0; 3];
st = ones(4,1);
a = 3;
b = 1;
logPDF = @(params)priorMVTIG(params,ct,st,dof,C,a,b);
%%
% Create a custom joint prior model for the linear regression parameters.
% Specify the number of predictors |p|. Also, specify the function handle
% for |priorMVTIG| and the variable names.
p = 3;
PriorMdl = bayeslm(p,'ModelType','custom','LogPDF',logPDF,...
    'VarNames',["IPI" "E" "WR"])
%%
% |PriorMdl| is a |customblm| Bayesian linear regression model object
% representing the prior distribution of the regression coefficients and
% disturbance variance. In this case, |bayeslm| does not display a summary
% of the prior distributions at the command line.


%% 
% Copyright 2012 The MathWorks, Inc.