Home > matlab > PlotPosteriorDistributions.m

PlotPosteriorDistributions

PURPOSE ^

function PlotPosteriorDistributions()

SYNOPSIS ^

function oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt_, oo_)

DESCRIPTION ^

 function PlotPosteriorDistributions()
 plots posterior distributions

 INPUTS
    estim_params_   [structure] 
    M_              [structure]
    options_        [structure] 
    bayestopt_      [structure]
    oo_             [structure]
    
 OUTPUTS
    oo_             [structure]  
    
 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt_, oo_)
0002 
0003 % function PlotPosteriorDistributions()
0004 % plots posterior distributions
0005 %
0006 % INPUTS
0007 %    estim_params_   [structure]
0008 %    M_              [structure]
0009 %    options_        [structure]
0010 %    bayestopt_      [structure]
0011 %    oo_             [structure]
0012 %
0013 % OUTPUTS
0014 %    oo_             [structure]
0015 %
0016 % SPECIAL REQUIREMENTS
0017 %    none
0018 
0019 % Copyright (C) 2005-2011 Dynare Team
0020 %
0021 % This file is part of Dynare.
0022 %
0023 % Dynare is free software: you can redistribute it and/or modify
0024 % it under the terms of the GNU General Public License as published by
0025 % the Free Software Foundation, either version 3 of the License, or
0026 % (at your option) any later version.
0027 %
0028 % Dynare is distributed in the hope that it will be useful,
0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0031 % GNU General Public License for more details.
0032 %
0033 % You should have received a copy of the GNU General Public License
0034 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0035 
0036 OutputDirectoryName = CheckPath('Output',M_.dname);
0037 
0038 TeX     = options_.TeX;
0039 nblck   = options_.mh_nblck;
0040 nvx     = estim_params_.nvx;
0041 nvn     = estim_params_.nvn;
0042 ncx     = estim_params_.ncx;
0043 ncn     = estim_params_.ncn;
0044 np      = estim_params_.np ;
0045 npar    = nvx+nvn+ncx+ncn+np;
0046 
0047 MaxNumberOfPlotPerFigure = 9;% The square root must be an integer!
0048 nn = sqrt(MaxNumberOfPlotPerFigure);
0049 
0050 figurename = 'Priors and posteriors';
0051 
0052 if TeX    
0053     fidTeX = fopen([OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors.TeX'],'w');
0054     fprintf(fidTeX,'%% TeX eps-loader file generated by PlotPosteriorDistributions.m (Dynare).\n');
0055     fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
0056     fprintf(fidTeX,' \n');
0057 end
0058 
0059 figunumber = 0;
0060 subplotnum = 0;
0061 
0062 for i=1:npar
0063     subplotnum = subplotnum+1;
0064     if subplotnum == 1
0065         figunumber = figunumber+1;
0066         hfig=dyn_figure(options_,'Name',figurename);
0067     end
0068     [nam,texnam] = get_the_name(i,TeX,M_,estim_params_,options_);
0069     if subplotnum == 1
0070         NAMES = nam;
0071         if TeX
0072             TeXNAMES = texnam;
0073         end
0074     else
0075         NAMES = char(NAMES,nam);
0076         if TeX
0077             TeXNAMES = char(TeXNAMES,texnam);
0078         end
0079     end
0080     [x2,f2,abscissa,dens,binf2,bsup2] = draw_prior_density(i,bayestopt_);
0081     top2 = max(f2); 
0082     if i <= nvx
0083         name = deblank(M_.exo_names(estim_params_.var_exo(i,1),:));  
0084         eval(['x1 = oo_.posterior_density.shocks_std.' name '(:,1);'])
0085         eval(['f1 = oo_.posterior_density.shocks_std.' name '(:,2);'])
0086         eval(['oo_.prior_density.shocks_std.' name '(:,1) = x2;'])
0087         eval(['oo_.prior_density.shocks_std.' name '(:,2) = f2;'])
0088         if ~options_.mh_posterior_mode_estimation
0089             eval(['pmod = oo_.posterior_mode.shocks_std.' name ';'])
0090         end
0091     elseif i <= nvx+nvn
0092         name = deblank(options_.varobs(estim_params_.var_endo(i-nvx,1),:));
0093         eval(['x1 = oo_.posterior_density.measurement_errors_std.' name '(:,1);'])
0094         eval(['f1 = oo_.posterior_density.measurement_errors_std.' name '(:,2);'])    
0095         eval(['oo_.prior_density.mearsurement_errors_std.' name '(:,1) = x2;'])
0096         eval(['oo_.prior_density.measurement_errors_std.' name '(:,2) = f2;'])
0097         if ~options_.mh_posterior_mode_estimation
0098             eval(['pmod = oo_.posterior_mode.measurement_errors_std.' name ';'])
0099         end     
0100     elseif i <= nvx+nvn+ncx
0101         j = i - (nvx+nvn);
0102         k1 = estim_params_.corrx(j,1);
0103         k2 = estim_params_.corrx(j,2);
0104         name = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];  
0105         eval(['x1 = oo_.posterior_density.shocks_corr.' name '(:,1);'])
0106         eval(['f1 = oo_.posterior_density.shocks_corr.' name '(:,2);'])    
0107         eval(['oo_.prior_density.shocks_corr.' name '(:,1) = x2;'])
0108         eval(['oo_.prior_density.shocks_corr.' name '(:,2) = f2;'])
0109         if ~options_.mh_posterior_mode_estimation
0110             eval(['pmod = oo_.posterior_mode.shocks_corr.' name ';'])  
0111         end
0112     elseif i <= nvx+nvn+ncx+ncn
0113         j = i - (nvx+nvn+ncx);
0114         k1 = estim_params_.corrn(j,1);
0115         k2 = estim_params_.corrn(j,2);
0116         name = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
0117         eval(['x1 = oo_.posterior_density.measurement_errors_corr.' name '(:,1);'])
0118         eval(['f1 = oo_.posterior_density.measurement_errors_corr.' name '(:,2);'])
0119         eval(['oo_.prior_density.mearsurement_errors_corr.' name '(:,1) = x2;'])
0120         eval(['oo_.prior_density.measurement_errors_corr.' name '(:,2) = f2;'])
0121         if ~options_.mh_posterior_mode_estimation
0122             eval(['pmod = oo_.posterior_mode.measurement_errors_corr.' name ';'])
0123         end
0124     else
0125         j = i - (nvx+nvn+ncx+ncn);
0126         name = deblank(M_.param_names(estim_params_.param_vals(j,1),:));
0127         eval(['x1 = oo_.posterior_density.parameters.' name '(:,1);'])
0128         eval(['f1 = oo_.posterior_density.parameters.' name '(:,2);'])
0129         eval(['oo_.prior_density.parameters.' name '(:,1) = x2;'])
0130         eval(['oo_.prior_density.parameters.' name '(:,2) = f2;'])
0131         if ~options_.mh_posterior_mode_estimation
0132             eval(['pmod = oo_.posterior_mode.parameters.' name ';'])
0133         end
0134     end
0135     top1 = max(f1);
0136     top0 = max([top1;top2]);
0137     binf1 = x1(1);
0138     bsup1 = x1(end);
0139     borneinf = min(binf1,binf2);
0140     bornesup = max(bsup1,bsup2);
0141     subplot(nn,nn,subplotnum)
0142     hh = plot(x2,f2,'-k','linewidth',2);
0143     set(hh,'color',[0.7 0.7 0.7]);
0144     hold on;
0145     plot(x1,f1,'-k','linewidth',2);
0146     if ~options_.mh_posterior_mode_estimation
0147         plot( [pmod pmod], [0.0 1.1*top0], '--g', 'linewidth', 2);
0148     end
0149     box on;
0150     axis([borneinf bornesup 0 1.1*top0]);
0151     title(nam,'Interpreter','none');
0152     hold off;
0153     drawnow
0154     if subplotnum == MaxNumberOfPlotPerFigure || i == npar;
0155         dyn_saveas(hfig,[OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors' int2str(figunumber)],options_);
0156         if TeX
0157             fprintf(fidTeX,'\\begin{figure}[H]\n');
0158             for j = 1:size(NAMES,1)
0159                 fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(j,:)),deblank(TeXNAMES(j,:)));
0160             end    
0161             fprintf(fidTeX,'\\centering\n');
0162             fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_PriorsAndPosteriors%s}\n',M_.fname,int2str(figunumber));
0163             fprintf(fidTeX,'\\caption{Priors and posteriors.}');
0164             fprintf(fidTeX,'\\label{Fig:PriorsAndPosteriors:%s}\n',int2str(figunumber));
0165             fprintf(fidTeX,'\\end{figure}\n');
0166             fprintf(fidTeX,' \n');
0167             if i == npar
0168                 fprintf(fidTeX,'%% End of TeX file.\n');
0169                 fclose(fidTeX);
0170             end
0171         end
0172         subplotnum = 0;
0173     end
0174 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005