Home > . > PlotPosteriorDistributions.m

PlotPosteriorDistributions

PURPOSE ^

stephane.adjemian@ens.fr [09-09-2005]

SYNOPSIS ^

function PlotPosteriorDistributions()

DESCRIPTION ^

 stephane.adjemian@ens.fr [09-09-2005]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function PlotPosteriorDistributions()
0002 % stephane.adjemian@ens.fr [09-09-2005]
0003 global estim_params_ M_ options_ bayestopt_ oo_
0004 
0005 OutputDirectoryName = CheckPath('Output');
0006 
0007 TeX       = options_.TeX;
0008 nblck     = options_.mh_nblck;
0009 nvx       = estim_params_.nvx;
0010 nvn       = estim_params_.nvn;
0011 ncx       = estim_params_.ncx;
0012 ncn       = estim_params_.ncn;
0013 np        = estim_params_.np ;
0014 npar       = nvx+nvn+ncx+ncn+np;
0015 
0016 MaxNumberOfPlotPerFigure = 9;% The square root must be an integer!
0017 nn = sqrt(MaxNumberOfPlotPerFigure);
0018 
0019 figurename = 'Priors and posteriors';
0020 
0021 if TeX    
0022   fidTeX = fopen([OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors.TeX'],'w');
0023   fprintf(fidTeX,'%% TeX eps-loader file generated by PlotPosteriorDistributions.m (Dynare).\n');
0024   fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
0025   fprintf(fidTeX,' \n');
0026 end
0027 
0028 figunumber = 0;
0029 subplotnum = 0;
0030 
0031 for i=1:npar
0032   subplotnum = subplotnum+1;
0033   if subplotnum == 1
0034     figunumber = figunumber+1;
0035     if options_.nograph
0036       hfig = figure('Name',figurename,'Visible','off');
0037     else
0038       hfig = figure('Name',figurename);
0039     end
0040   end
0041   if subplotnum == 1
0042     if TeX
0043       TeXNAMES = [];
0044     end
0045     NAMES = [];
0046   end
0047   [nam,texnam] = get_the_name(i,TeX);
0048   NAMES = strvcat(NAMES,nam);
0049   if TeX
0050     TeXNAMES = strvcat(TeXNAMES,texnam);
0051   end
0052   [x2,f2,abscissa,dens,binf2,bsup2] = draw_prior_density(i);
0053   top2 = max(f2); 
0054   if i <= nvx
0055     name = deblank(M_.exo_names(estim_params_.var_exo(i,1),:));  
0056     eval(['x1 = oo_.posterior_density.shocks_std.' name '(:,1);'])
0057     eval(['f1 = oo_.posterior_density.shocks_std.' name '(:,2);'])
0058     eval(['pmode = oo_.posterior_mode.shocks_std.' name ';'])
0059   elseif i <= nvx+nvn
0060     name = deblank(options_.varobs(estim_params_.var_endo(i-nvx,1),:));
0061     eval(['x1 = oo_.posterior_density.measurement_errors_std.' name '(:,1);'])
0062     eval(['f1 = oo_.posterior_density.measurement_errors_std.' name '(:,2);'])    
0063     eval(['pmode = oo_.posterior_mode.measurement_errors_std.' name ';'])  
0064   elseif i <= nvx+nvn+ncx
0065     j = i - (nvx+nvn)
0066     k1 = estim_params_.corrx(j,1);
0067     k2 = estim_params_.corrx(j,2);
0068     name = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];  
0069     eval(['x1 = oo_.posterior_density.shocks_corr.' name '(:,1);'])
0070     eval(['f1 = oo_.posterior_density.shocks_corr.' name '(:,2);'])    
0071     eval(['pmode = oo_.posterior_mode.shocks_corr.' name ';'])  
0072   elseif i <= nvx+nvn+ncx+ncn
0073     j = i - (nvx+nvn+ncx);
0074     k1 = estim_params_.corrn(j,1);
0075     k2 = estim_params_.corrn(j,2);
0076     name = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
0077     eval(['x1 = oo_.posterior_density.measurement_errors_corr.' name '(:,1);'])
0078     eval(['f1 = oo_.posterior_density.measurement_errors_corr.' name '(:,2);'])
0079     eval(['pmode = oo_.posterior_mode.measurement_errors_corr.' name ';'])
0080   else
0081     j = i - (nvx+nvn+ncx+ncn);
0082     name = deblank(M_.param_names(estim_params_.param_vals(j,1),:));
0083     eval(['x1 = oo_.posterior_density.' name '(:,1);'])
0084     eval(['f1 = oo_.posterior_density.' name '(:,2);'])
0085     eval(['pmode = oo_.posterior_mode.parameters.' name ';'])
0086   end
0087   top1 = max(f1);
0088   top0 = max([top1;top2]);
0089   binf1 = x1(1);
0090   bsup1 = x1(end);
0091   borneinf = min(binf1,binf2);
0092   bornesup = max(bsup1,bsup2);
0093   subplot(nn,nn,subplotnum)
0094   hh = plot(x2,f2,'-k','linewidth',2);
0095   set(hh,'color',[0.7 0.7 0.7]);
0096   hold on;
0097   plot(x1,f1,'-k','linewidth',2);
0098   plot( [pmode pmode], [0.0 1.1*top0], '--g', 'linewidth', 2);
0099   box on;
0100   axis([borneinf bornesup 0 1.1*top0]);
0101   title(nam,'Interpreter','none');
0102   hold off;
0103   drawnow
0104   if subplotnum == MaxNumberOfPlotPerFigure | i == npar;
0105     eval(['print -depsc2 ' OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors' int2str(figunumber)]);
0106     eval(['print -dpdf ' OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors' int2str(figunumber)]);
0107     if options_.nograph, 
0108       set(hfig,'Visible','on');
0109     end
0110     saveas(hfig,[OutputDirectoryName '/' M_.fname '_PriorsAndPosteriors' int2str(figunumber) '.fig']);
0111     if TeX
0112       fprintf(fidTeX,'\\begin{figure}[H]\n');
0113       for j = 1:size(NAMES,1)
0114     fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(j,:)),deblank(TeXNAMES(j,:)));
0115       end    
0116       fprintf(fidTeX,'\\centering\n');
0117       fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_PriorsAndPosteriors%s}\n',M_.fname,int2str(figunumber));
0118       fprintf(fidTeX,'\\caption{Priors and posteriors.}');
0119       fprintf(fidTeX,'\\label{Fig:PriorsAndPosteriors:%s}\n',int2str(figunumber));
0120       fprintf(fidTeX,'\\end{figure}\n');
0121       fprintf(fidTeX,' \n');
0122       if i == npar
0123     fprintf(fidTeX,'%% End of TeX file.\n');
0124     fclose(fidTeX);
0125       end
0126     end
0127     if options_.nograph, 
0128       close(hfig), 
0129     end
0130     subplotnum = 0;
0131   end
0132 end

Generated on Fri 16-Jun-2006 09:09:06 by m2html © 2003