2005-09-25 16:10:41 +02:00
|
|
|
function PlotPosteriorDistributions()
|
2008-01-10 16:13:48 +01:00
|
|
|
|
|
|
|
% function PlotPosteriorDistributions()
|
|
|
|
% plots posterior distributions
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
% part of DYNARE, copyright Dynare Team (2005-2008)
|
|
|
|
% Gnu Public License.
|
|
|
|
|
2005-09-25 16:10:41 +02:00
|
|
|
global estim_params_ M_ options_ bayestopt_ oo_
|
|
|
|
|
2006-03-03 16:54:17 +01:00
|
|
|
OutputDirectoryName = CheckPath('Output');
|
2005-09-25 16:10:41 +02: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;
|
|
|
|
|
|
|
|
MaxNumberOfPlotPerFigure = 9;% The square root must be an integer!
|
|
|
|
nn = sqrt(MaxNumberOfPlotPerFigure);
|
|
|
|
|
|
|
|
figurename = 'Priors and posteriors';
|
|
|
|
|
|
|
|
if TeX
|
2006-03-03 16:54:17 +01:00
|
|
|
fidTeX = fopen([OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors.TeX'],'w');
|
2005-09-25 16:10:41 +02: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;
|
2006-03-03 16:54:17 +01:00
|
|
|
|
2005-09-25 16:10:41 +02:00
|
|
|
for i=1:npar
|
|
|
|
subplotnum = subplotnum+1;
|
|
|
|
if subplotnum == 1
|
|
|
|
figunumber = figunumber+1;
|
2006-03-03 16:54:17 +01:00
|
|
|
if options_.nograph
|
|
|
|
hfig = figure('Name',figurename,'Visible','off');
|
|
|
|
else
|
|
|
|
hfig = figure('Name',figurename);
|
|
|
|
end
|
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
if subplotnum == 1
|
|
|
|
if TeX
|
|
|
|
TeXNAMES = [];
|
|
|
|
end
|
|
|
|
NAMES = [];
|
|
|
|
end
|
|
|
|
[nam,texnam] = get_the_name(i,TeX);
|
|
|
|
NAMES = strvcat(NAMES,nam);
|
|
|
|
if TeX
|
|
|
|
TeXNAMES = strvcat(TeXNAMES,texnam);
|
|
|
|
end
|
|
|
|
[x2,f2,abscissa,dens,binf2,bsup2] = draw_prior_density(i);
|
|
|
|
top2 = max(f2);
|
|
|
|
if i <= nvx
|
2006-03-03 16:54:17 +01:00
|
|
|
name = deblank(M_.exo_names(estim_params_.var_exo(i,1),:));
|
2005-09-25 16:10:41 +02:00
|
|
|
eval(['x1 = oo_.posterior_density.shocks_std.' name '(:,1);'])
|
2006-03-03 16:54:17 +01:00
|
|
|
eval(['f1 = oo_.posterior_density.shocks_std.' name '(:,2);'])
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['oo_.prior_density.shocks_std.' name '(:,1) = x2;'])
|
|
|
|
eval(['oo_.prior_density.shocks_std.' name '(:,2) = f2;'])
|
2006-07-28 12:00:31 +02:00
|
|
|
if options_.posterior_mode_estimation
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['pmod = oo_.posterior_mode.shocks_std.' name ';'])
|
2006-07-28 12:00:31 +02:00
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
elseif i <= nvx+nvn
|
|
|
|
name = deblank(options_.varobs(estim_params_.var_endo(i-nvx,1),:));
|
|
|
|
eval(['x1 = oo_.posterior_density.measurement_errors_std.' name '(:,1);'])
|
|
|
|
eval(['f1 = oo_.posterior_density.measurement_errors_std.' name '(:,2);'])
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['oo_.prior_density.mearsurement_errors_std.' name '(:,1) = x2;'])
|
|
|
|
eval(['oo_.prior_density.measurement_errors_std.' name '(:,2) = f2;'])
|
2006-07-28 12:00:31 +02:00
|
|
|
if options_.posterior_mode_estimation
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['pmod = oo_.posterior_mode.measurement_errors_std.' name ';'])
|
2006-07-28 12:00:31 +02:00
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
elseif i <= nvx+nvn+ncx
|
|
|
|
j = i - (nvx+nvn)
|
|
|
|
k1 = estim_params_.corrx(j,1);
|
|
|
|
k2 = estim_params_.corrx(j,2);
|
|
|
|
name = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];
|
|
|
|
eval(['x1 = oo_.posterior_density.shocks_corr.' name '(:,1);'])
|
|
|
|
eval(['f1 = oo_.posterior_density.shocks_corr.' name '(:,2);'])
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['oo_.prior_density.shocks_corr.' name '(:,1) = x2;'])
|
|
|
|
eval(['oo_.prior_density.shocks_corr.' name '(:,2) = f2;'])
|
2006-07-28 12:00:31 +02:00
|
|
|
if options_.posterior_mode_estimation
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['pmod = oo_.posterior_mode.shocks_corr.' name ';'])
|
2006-07-28 12:00:31 +02:00
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
elseif i <= nvx+nvn+ncx+ncn
|
|
|
|
j = i - (nvx+nvn+ncx);
|
|
|
|
k1 = estim_params_.corrn(j,1);
|
|
|
|
k2 = estim_params_.corrn(j,2);
|
|
|
|
name = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
|
|
|
|
eval(['x1 = oo_.posterior_density.measurement_errors_corr.' name '(:,1);'])
|
|
|
|
eval(['f1 = oo_.posterior_density.measurement_errors_corr.' name '(:,2);'])
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['oo_.prior_density.mearsurement_errors_corr.' name '(:,1) = x2;'])
|
|
|
|
eval(['oo_.prior_density.measurement_errors_corr.' name '(:,2) = f2;'])
|
2006-07-28 12:00:31 +02:00
|
|
|
if options_.posterior_mode_estimation
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['pmod = oo_.posterior_mode.measurement_errors_corr.' name ';'])
|
2006-07-28 12:00:31 +02:00
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
else
|
|
|
|
j = i - (nvx+nvn+ncx+ncn);
|
|
|
|
name = deblank(M_.param_names(estim_params_.param_vals(j,1),:));
|
2006-12-15 12:37:24 +01:00
|
|
|
eval(['x1 = oo_.posterior_density.parameters.' name '(:,1);'])
|
|
|
|
eval(['f1 = oo_.posterior_density.parameters.' name '(:,2);'])
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['oo_.prior_density.parameters.' name '(:,1) = x2;'])
|
|
|
|
eval(['oo_.prior_density.parameters.' name '(:,2) = f2;'])
|
2006-07-28 12:00:31 +02:00
|
|
|
if options_.posterior_mode_estimation
|
2007-04-15 14:54:35 +02:00
|
|
|
eval(['pmod = oo_.posterior_mode.parameters.' name ';'])
|
2006-07-28 12:00:31 +02:00
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
end
|
|
|
|
top1 = max(f1);
|
|
|
|
top0 = max([top1;top2]);
|
|
|
|
binf1 = x1(1);
|
|
|
|
bsup1 = x1(end);
|
|
|
|
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]);
|
|
|
|
hold on;
|
|
|
|
plot(x1,f1,'-k','linewidth',2);
|
2006-07-28 12:00:31 +02:00
|
|
|
if options_.posterior_mode_estimation
|
2007-04-15 14:54:35 +02:00
|
|
|
plot( [pmod pmod], [0.0 1.1*top0], '--g', 'linewidth', 2);
|
2006-07-28 12:00:31 +02:00
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
box on;
|
|
|
|
axis([borneinf bornesup 0 1.1*top0]);
|
|
|
|
title(nam,'Interpreter','none');
|
|
|
|
hold off;
|
|
|
|
drawnow
|
|
|
|
if subplotnum == MaxNumberOfPlotPerFigure | i == npar;
|
2008-06-24 20:20:48 +02:00
|
|
|
eval(['print -depsc2 ' OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors' int2str(figunumber) '.eps']);
|
|
|
|
if ~exist('OCTAVE_VERSION')
|
|
|
|
eval(['print -dpdf ' OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors' int2str(figunumber)]);
|
|
|
|
end
|
2006-05-04 11:00:29 +02:00
|
|
|
if options_.nograph,
|
|
|
|
set(hfig,'Visible','on');
|
|
|
|
end
|
2008-06-24 20:20:48 +02:00
|
|
|
if ~exist('OCTAVE_VERSION')
|
|
|
|
saveas(hfig,[OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors' int2str(figunumber) '.fig']);
|
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
if TeX
|
|
|
|
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
|
|
|
for j = 1:size(NAMES,1)
|
|
|
|
fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(j,:)),deblank(TeXNAMES(j,:)));
|
|
|
|
end
|
|
|
|
fprintf(fidTeX,'\\centering\n');
|
|
|
|
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_PriorsAndPosteriors%s}\n',M_.fname,int2str(figunumber));
|
|
|
|
fprintf(fidTeX,'\\caption{Priors and posteriors.}');
|
|
|
|
fprintf(fidTeX,'\\label{Fig:PriorsAndPosteriors:%s}\n',int2str(figunumber));
|
|
|
|
fprintf(fidTeX,'\\end{figure}\n');
|
|
|
|
fprintf(fidTeX,' \n');
|
|
|
|
if i == npar
|
|
|
|
fprintf(fidTeX,'%% End of TeX file.\n');
|
|
|
|
fclose(fidTeX);
|
|
|
|
end
|
|
|
|
end
|
2006-05-04 11:00:29 +02:00
|
|
|
if options_.nograph,
|
|
|
|
close(hfig),
|
|
|
|
end
|
2005-09-25 16:10:41 +02:00
|
|
|
subplotnum = 0;
|
|
|
|
end
|
|
|
|
end
|