% A demo for basic Bayesian Model Averaging
% with R and Matlab
% see http://bms.zeugner.eu for further information


%load all the neccessary information
% and start an R session in the background:
libraryBMS;

% load some sample data on economic growth;
load('datafls') %Note that this is the data from Fernandez, Ley and Steel (2001): Model uncertainty in cross-country growth regressions; JAE

% do BMA with the default settings, with 3000 bur-in draws and 5000 counted
% iterations
% type 'help bms' for more information
mm=bms(datafls, 3000, 5000);
% note that this produces a chart that can be reproduced with plotConv


% show the PIPs and coefficients in their original order
coef_bma(mm,'',false);

% show the Posterior model probabilities of the 10 best models
pmp_bma(mm,1:10);

% plot prior and posterior model size distribution
plotModelsize(mm)

%plot the Posterior model probabilities and signs for the the 50 best
% models
image_bma(mm, NaN, false, 1:50);

set(gca,'FontSize',7); %this decreases font size in the chart in order to deal with the many variables

%plot the posterior density for the first regressor
ll=density_bma(mm,1);

%reprint the information from the bms call
print_bma(mm);


% Consider moreover the example in 
help saveRworkspace

%Now try to do more with bms command. 
%try for instance the according GUI
bmsGUI('datafls');


%close the R session and remove Matlab paths
closeBMS;
