%% Set Hyperparameters of Normal-Inverse-Gamma Conjugate Prior Model
% Consider the linear regression model in Default Diffuse Prior Model. Assume these prior distributions:
% \beta\vert\sigma^2 \sim N_4\left({\rm M},\sigma^2 V\right). {\rm M} is a 4-by-1 vector of means, and V is a scaled 4-by-4 positive definite covariance matrix. Suppose you have prior knowledge that {\rm M} = {\left[ {\begin{array}{*{20}{c}} { - 20}&4&{0.1}&2 \end{array}} \right]^\prime } and V is the identity matrix.
% \sigma^2 \sim IG(A,B). A and B are the shape and scale, respectively, of an inverse gamma distribution.
% These assumptions and the data likelihood imply a normal-inverse-gamma conjugate model.
% Create a normal-inverse-gamma conjugate prior model for the linear regression parameters. Specify the number of predictors p and set the regression coefficient names to the corresponding variable names.

p = 3;
Mdl = bayeslm(p,'ModelType','conjugate','Mu',[-20; 4; 0.1; 2],'V',eye(4),...
    'VarNames',["IPI" "E" "WR"])

% Mdl is a conjugateblm Bayesian linear regression model object representing the prior distribution of the regression coefficients and disturbance variance. bayeslm displays a summary of the prior distributions at the command line. Although bayeslm assigns names to the intercept and disturbance variance, all other coefficients have the specified names.
% By default, bayeslm sets the shape and scale to 3 and 1, respectively. Suppose you have prior knowledge that the shape and scale are 5 and 2.
%
% Set the prior shape and scale of \sigma^2 to their assumed values.

Mdl.A = 5;
Mdl.B = 2

% bayeslm updates the prior distribution summary based on the changes in the shape and scale.
% Copyright 2012 The MathWorks, Inc.