2009-12-16 18:17:34 +01:00
|
|
|
function oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt_, oo_)
|
|
|
|
|
|
|
|
% function PlotPosteriorDistributions()
|
|
|
|
% plots posterior distributions
|
|
|
|
%
|
|
|
|
% INPUTS
|
2017-05-16 15:10:20 +02:00
|
|
|
% estim_params_ [structure]
|
2009-12-16 18:17:34 +01:00
|
|
|
% M_ [structure]
|
2017-05-16 15:10:20 +02:00
|
|
|
% options_ [structure]
|
2009-12-16 18:17:34 +01:00
|
|
|
% bayestopt_ [structure]
|
|
|
|
% oo_ [structure]
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2009-12-16 18:17:34 +01:00
|
|
|
% OUTPUTS
|
2017-05-16 15:10:20 +02:00
|
|
|
% oo_ [structure]
|
|
|
|
%
|
2009-12-16 18:17:34 +01:00
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
% Copyright (C) 2005-2018 Dynare Team
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2011-12-15 11:56:23 +01:00
|
|
|
OutputDirectoryName = CheckPath('Output',M_.dname);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2010-01-05 11:46:10 +01:00
|
|
|
TeX = options_.TeX;
|
|
|
|
nblck = options_.mh_nblck;
|
|
|
|
nvx = estim_params_.nvx;
|
|
|
|
nvn = estim_params_.nvn;
|
|
|
|
ncx = estim_params_.ncx;
|
|
|
|
ncn = estim_params_.ncn;
|
|
|
|
np = estim_params_.np ;
|
|
|
|
npar = nvx+nvn+ncx+ncn+np;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
MaxNumberOfPlotPerFigure = 9;% The square root must be an integer!
|
|
|
|
nn = sqrt(MaxNumberOfPlotPerFigure);
|
|
|
|
|
|
|
|
figurename = 'Priors and posteriors';
|
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
2016-06-14 09:48:35 +02:00
|
|
|
fidTeX = fopen([OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors.tex'],'w');
|
2009-12-16 18:17:34 +01:00
|
|
|
fprintf(fidTeX,'%% TeX eps-loader file generated by PlotPosteriorDistributions.m (Dynare).\n');
|
|
|
|
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
|
|
|
fprintf(fidTeX,' \n');
|
|
|
|
end
|
|
|
|
|
|
|
|
figunumber = 0;
|
|
|
|
subplotnum = 0;
|
|
|
|
|
|
|
|
for i=1:npar
|
|
|
|
subplotnum = subplotnum+1;
|
|
|
|
if subplotnum == 1
|
|
|
|
figunumber = figunumber+1;
|
2017-10-10 10:05:59 +02:00
|
|
|
hfig=dyn_figure(options_.nodisplay, 'Name', figurename);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
[nam,texnam] = get_the_name(i, TeX, M_, estim_params_, options_);
|
|
|
|
[x2, f2, abscissa, dens, binf2, bsup2] = draw_prior_density(i, bayestopt_);
|
2017-05-16 15:10:20 +02:00
|
|
|
top2 = max(f2);
|
2009-12-16 18:17:34 +01:00
|
|
|
if i <= nvx
|
2017-10-10 10:05:59 +02:00
|
|
|
name = M_.exo_names{estim_params_.var_exo(i,1)};
|
2016-12-17 18:20:58 +01:00
|
|
|
x1 = oo_.posterior_density.shocks_std.(name)(:,1);
|
|
|
|
f1 = oo_.posterior_density.shocks_std.(name)(:,2);
|
|
|
|
oo_.prior_density.shocks_std.(name)(:,1) = x2;
|
|
|
|
oo_.prior_density.shocks_std.(name)(:,2) = f2;
|
2010-09-01 22:15:47 +02:00
|
|
|
if ~options_.mh_posterior_mode_estimation
|
2016-12-17 18:20:58 +01:00
|
|
|
pmod = oo_.posterior_mode.shocks_std.(name);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
elseif i <= nvx+nvn
|
2013-05-21 16:38:17 +02:00
|
|
|
name = options_.varobs{estim_params_.nvn_observable_correspondence(i-nvx,1)};
|
2016-12-17 18:20:58 +01:00
|
|
|
x1 = oo_.posterior_density.measurement_errors_std.(name)(:,1);
|
|
|
|
f1 = oo_.posterior_density.measurement_errors_std.(name)(:,2);
|
|
|
|
oo_.prior_density.measurement_errors_std.(name)(:,1) = x2;
|
|
|
|
oo_.prior_density.measurement_errors_std.(name)(:,2) = f2;
|
2010-09-01 22:15:47 +02:00
|
|
|
if ~options_.mh_posterior_mode_estimation
|
2016-12-17 18:20:58 +01:00
|
|
|
pmod = oo_.posterior_mode.measurement_errors_std.(name);
|
2017-05-16 15:10:20 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
elseif i <= nvx+nvn+ncx
|
|
|
|
j = i - (nvx+nvn);
|
|
|
|
k1 = estim_params_.corrx(j,1);
|
|
|
|
k2 = estim_params_.corrx(j,2);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s_%s', M_.exo_names{k1}, M_.exo_names{k2});
|
2016-12-17 18:20:58 +01:00
|
|
|
x1 = oo_.posterior_density.shocks_corr.(name)(:,1);
|
|
|
|
f1 = oo_.posterior_density.shocks_corr.(name)(:,2);
|
|
|
|
oo_.prior_density.shocks_corr.(name)(:,1) = x2;
|
|
|
|
oo_.prior_density.shocks_corr.(name)(:,2) = f2;
|
2010-09-01 22:15:47 +02:00
|
|
|
if ~options_.mh_posterior_mode_estimation
|
2017-05-16 15:10:20 +02:00
|
|
|
pmod = oo_.posterior_mode.shocks_corr.(name);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
elseif i <= nvx+nvn+ncx+ncn
|
|
|
|
j = i - (nvx+nvn+ncx);
|
|
|
|
k1 = estim_params_.corrn(j,1);
|
|
|
|
k2 = estim_params_.corrn(j,2);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s_%s', M_.endo_names{k1}, M_.endo_names{k2});
|
2016-12-17 18:20:58 +01:00
|
|
|
x1 = oo_.posterior_density.measurement_errors_corr.(name)(:,1);
|
|
|
|
f1 = oo_.posterior_density.measurement_errors_corr.(name)(:,2);
|
|
|
|
oo_.prior_density.measurement_errors_corr.(name)(:,1) = x2;
|
|
|
|
oo_.prior_density.measurement_errors_corr.(name)(:,2) = f2;
|
2010-09-01 22:15:47 +02:00
|
|
|
if ~options_.mh_posterior_mode_estimation
|
2016-12-17 18:20:58 +01:00
|
|
|
pmod = oo_.posterior_mode.measurement_errors_corr.(name);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
j = i - (nvx+nvn+ncx+ncn);
|
2017-10-10 10:05:59 +02:00
|
|
|
name = M_.param_names{estim_params_.param_vals(j,1)};
|
2016-12-17 18:20:58 +01:00
|
|
|
x1 = oo_.posterior_density.parameters.(name)(:,1);
|
|
|
|
f1 = oo_.posterior_density.parameters.(name)(:,2);
|
|
|
|
oo_.prior_density.parameters.(name)(:,1) = x2;
|
|
|
|
oo_.prior_density.parameters.(name)(:,2) = f2;
|
2010-09-01 22:15:47 +02:00
|
|
|
if ~options_.mh_posterior_mode_estimation
|
2016-12-17 18:20:58 +01:00
|
|
|
pmod = oo_.posterior_mode.parameters.(name);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
top1 = max(f1);
|
2017-10-10 10:05:59 +02:00
|
|
|
top0 = max([top1; top2]);
|
2009-12-16 18:17:34 +01:00
|
|
|
binf1 = x1(1);
|
|
|
|
bsup1 = x1(end);
|
2017-10-10 10:05:59 +02:00
|
|
|
borneinf = min(binf1, binf2);
|
|
|
|
bornesup = max(bsup1, bsup2);
|
|
|
|
subplot(nn, nn, subplotnum)
|
|
|
|
hh = plot(x2, f2, '-k', 'linewidth', 2);
|
|
|
|
set(hh, 'color', [0.7 0.7 0.7]);
|
2009-12-16 18:17:34 +01:00
|
|
|
hold on;
|
2017-10-10 10:05:59 +02:00
|
|
|
plot(x1, f1, '-k', 'linewidth', 2);
|
2010-09-01 22:15:47 +02:00
|
|
|
if ~options_.mh_posterior_mode_estimation
|
2017-10-10 10:05:59 +02:00
|
|
|
plot([pmod pmod], [0.0 1.1*top0], '--g', 'linewidth', 2);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
box on
|
|
|
|
axis([borneinf bornesup 0 1.1*top0])
|
2020-06-17 20:23:49 +02:00
|
|
|
if TeX
|
|
|
|
title(texnam, 'Interpreter', 'latex')
|
|
|
|
else
|
|
|
|
title(nam, 'Interpreter', 'none')
|
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
hold off
|
2009-12-16 18:17:34 +01:00
|
|
|
drawnow
|
2017-05-16 12:42:01 +02:00
|
|
|
if subplotnum == MaxNumberOfPlotPerFigure || i == npar
|
2017-10-10 10:05:59 +02:00
|
|
|
dyn_saveas(hfig,[OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors' int2str(figunumber)], options_.nodisplay, options_.graph_format);
|
|
|
|
if TeX && any(strcmp('eps', cellstr(options_.graph_format)))
|
|
|
|
fprintf(fidTeX, '\\begin{figure}[H]\n');
|
|
|
|
fprintf(fidTeX, '\\centering\n');
|
|
|
|
fprintf(fidTeX, '\\includegraphics[width=%2.2f\\textwidth]{%s/%s_PriorsAndPosteriors%s}\n', ...
|
|
|
|
options_.figures.textwidth*min(subplotnum/nn,1), OutputDirectoryName, M_.fname, int2str(figunumber));
|
2009-12-16 18:17:34 +01:00
|
|
|
fprintf(fidTeX,'\\caption{Priors and posteriors.}');
|
2017-10-10 10:05:59 +02:00
|
|
|
fprintf(fidTeX,'\\label{Fig:PriorsAndPosteriors:%s}\n', int2str(figunumber));
|
2009-12-16 18:17:34 +01:00
|
|
|
fprintf(fidTeX,'\\end{figure}\n');
|
|
|
|
fprintf(fidTeX,' \n');
|
|
|
|
if i == npar
|
|
|
|
fprintf(fidTeX,'%% End of TeX file.\n');
|
|
|
|
fclose(fidTeX);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
subplotnum = 0;
|
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
end
|