%% Compare Default Prior and Marginal Posterior Estimation to OLS Estimates
% Consider a model that predicts the fuel economy (in MPG) of a car given its engine displacement and weight.
%
% Load the carsmall data set.

load carsmall
x = [Displacement Weight];
y = MPG;

%
% Regress fuel economy onto engine displacement and weight, including an intercept to obtain ordinary least-squares (OLS) estimates.

Mdl = fitlm(x,y)
Mdl.MSE

%
% Create a default, diffuse prior distribution for one predictor.

p = 2;
PriorMdl = bayeslm(p);

% PriorMdl is a diffuseblm model object.
%
% Use default options to estimate the posterior distribution.

PosteriorMdl = estimate(PriorMdl,x,y);

% PosteriorMdl is a conjugateblm model object.
% The posterior means and the OLS coefficient estimates are almost identical. Also, the posterior standard deviations and OLS standard errors are almost identical. The posterior mean of Sigma2 is close to the OLS mean squared error (MSE).
% Copyright 2012 The MathWorks, Inc.