Home > . > compDist.m

compDist

PURPOSE ^

SYNOPSIS ^

function compdist(xparam1, x2, pltopt, figurename)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function compdist(xparam1, x2, pltopt, figurename)
0002 global bayestopt_  estim_params_ M_ options_
0003 
0004 % NOTE: If pltopt ~= 'All' compdist.m just draws prior densities.
0005 
0006 %% Set density estimation parameters:
0007 number_of_grid_points = 2^9;      % 2^9 = 512 !... Must be a power of two.
0008 bandwidth = 0;                    % Rule of thumb optimal bandwidth parameter.
0009 kernel_function = 'gaussian';     % You can switch to: 'epanechnikov', 'quartic', 'triangle',
0010 % 'triweight', 'uniform' or 'cosinus' kernels (iff bandwidth=0, see posterior_density_estimate.m).
0011 truncprior = 10^(-3);             
0012   
0013   
0014 npar=length(xparam1);
0015 nruns=length(x2);
0016 icol=ceil(sqrt(npar));
0017 iraw=icol;
0018 if (icol-1)*(icol-2)>=npar
0019     iraw = icol-2;
0020     icol=icol-1;
0021 elseif (icol)*(icol-2)>=npar
0022     iraw = icol-2;
0023 elseif icol*(icol-1)>=npar
0024     iraw=icol-1;
0025 end
0026 
0027 pmean=bayestopt_.pmean;
0028 pshape=bayestopt_.pshape; 
0029 p1 = bayestopt_.p1;
0030 p2 = bayestopt_.p2;
0031 p3 = bayestopt_.p3;
0032 p4 = bayestopt_.p4;
0033   
0034 figure('Name',figurename)
0035 for i=1:npar;
0036   if i<=estim_params_.nvx
0037     vname = deblank(M_.exo_name(estim_params_.var_exo(i,1),:));
0038     nam=['SE_{',vname,'}'];
0039   elseif  i<=(estim_params_.nvx+estim_params_.nvn)
0040     deblank(options_.varobs(estim_params_.var_endo(i-estim_params_.nvx,1),:));
0041     nam=['SE_{EOBS_',vname,'}'];
0042   elseif  i<=(estim_params_.nvx+estim_params_.nvn+estim_params_.ncx)
0043     j = i - (estim_params_.nvx+estim_params_.nvn);
0044     k1 = estim_params_.corrx(j,1);
0045     k2 = estim_params_.corrx(j,2);
0046     vname = [deblank(M_.exo_name(k1,:)) ',' deblank(M_.exo_name(k2,:))];
0047     nam=['CC_{',vname,'}'];
0048   elseif  i<=(estim_params_.nvx+estim_params_.nvn+estim_params_.ncx+ ...
0049               estim_params_.ncn)
0050     j = i - (estim_params_.nvx+estim_params_.nvn+estim_params_.ncx);
0051     k1 = estim_params_.corrn(j,1);
0052     k2 = estim_params_.corrn(j,2);
0053     vname = [deblank(M_.exo_name(k1,:)) ',' deblank(M_.exo_name(k2,:))];
0054     nam=['CC_{EOBS_',vname,'}'];
0055   else
0056     j = i - (estim_params_.nvx+estim_params_.nvn+estim_params_.ncx+ ...
0057       estim_params_.ncn);
0058     nam = deblank(estim_params_.param_names(j,:));
0059   end
0060   subplot(iraw, icol, i);   
0061   if strcmpi(pltopt,'all'); % Estimation of the density...
0062       [abscissa,ff,h] = posterior_density_estimate(x2(round(options_.mh_drop*nruns):end,i),...
0063                       number_of_grid_points,bandwidth,kernel_function);
0064       plot(abscissa,ff,'-k','linewidth',2); 
0065   end;
0066   a = 0;
0067   b = 0;
0068   if pshape(i) == 1;     %/* BETA Prior */
0069       density = inline('((1-x).^(b-1)).*x.^(a-1)./beta(a,b)','x','a','b');
0070       mu = (p1(i)-p3(i))/(p4(i)-p3(i));
0071       stdd = p2(i)/(p4(i)-p3(i));
0072       a = (1-mu)*mu^2/stdd^2 - mu;
0073       b = a*(1/mu - 1);
0074       infbound = qbeta(truncprior,a,b);
0075       supbound = qbeta(1-truncprior,a,b);
0076       stepsize = (supbound-infbound)/200;
0077       abscissa = infbound:stepsize:supbound;
0078       f = density(abscissa,a,b);
0079       abscissa = abscissa*(p4(i)-p3(i))+p3(i);
0080       if strcmp(pltopt,'all');
0081           top = max([max(ff);max(f)]);
0082       end;
0083   elseif pshape(i) == 2; %/* GAMMA PRIOR */
0084 %      density =
0085 %      inline('((x/b).^(a-1)).*exp(-x/b)*inv(b*gamma(a))','x','a','b');
0086       mu = p1(i)-p3(i);
0087       b  = p2(i)^2/mu;
0088       a  = mu/b;
0089       infbound = mj_qgamma(truncprior,a)*b; 
0090       supbound = mj_qgamma(1-truncprior,a)*b;
0091       stepsize = (supbound-infbound)/200;
0092       abscissa = infbound:stepsize:supbound;
0093       f = exp(lpdfgam(abscissa,a,b));
0094       abscissa = abscissa + p3(i);
0095       if strcmp(pltopt,'all');
0096           top = max([max(ff);max(f)]);
0097       end;
0098   elseif pshape(i) == 3; %/* GAUSSIAN PRIOR */
0099       density = inline('inv(sqrt(2*pi)*b)*exp(-0.5*((x-a)/b).^2)','x','a','b');
0100       a = p1(i);
0101       b = p2(i);
0102       infbound = qnorm(truncprior,a,b); 
0103       supbound = qnorm(1-truncprior,a,b);
0104       stepsize = (supbound-infbound)/200;
0105       abscissa = infbound:stepsize:supbound;
0106       f = density(abscissa,a,b);  
0107       if strcmp(pltopt,'all');
0108           top = max([max(ff);max(f)]);
0109       end;
0110   elseif pshape(i) == 4; %/* INVGAMMA PRIOR type 1 */
0111       density = inline('2*inv(gamma(nu/2))*(x.^(-nu-1))*((s/2)^(nu/2)).*exp(-s./(2*x.^2))','x','s','nu');
0112       nu = p2(i);
0113       s  = p1(i);
0114       a  = nu/2;
0115       b  = 2/s;
0116       infbound = 1/sqrt(mj_qgamma(1-10*truncprior,a)*b); 
0117       supbound = 1/sqrt(mj_qgamma(10*truncprior,a)*b);
0118       stepsize = (supbound-infbound)/200;
0119       abscissa = infbound:stepsize:supbound;
0120       f = density(abscissa,s,nu);  
0121       if strcmp(pltopt,'all');
0122           top = max([max(ff);max(f)]);
0123       end;
0124   elseif pshape(i) == 5; %/* UNIFORM PRIOR */
0125       density = inline('(x.^0)/(b-a)','x','a','b');
0126       a  = p1(i);
0127       b  = p2(i);
0128       infbound = a; 
0129       supbound = b;
0130       stepsize = (supbound-infbound)/200;
0131       abscissa = infbound:stepsize:supbound;
0132       f = density(abscissa,a,b);  
0133       if strcmp(pltopt,'all');
0134           top = max([max(ff);max(f)]);
0135       end;
0136   elseif pshape(i) == 6; %/*  INVGAMMA PRIOR type 2 */
0137       density = inline('inv(gamma(nu/2))*(x.^(-.5(nu+2)))*((s/2)^(nu/2)).*exp(-s./(2*x))','x','s','nu');
0138       nu = p2(i);
0139       s  = p1(i);
0140       a  = nu/2;
0141       b  = 2/s;
0142       infbound = 1/(qgamma(1-truncprior,a)*b); 
0143       supbound = 1/(qgamma(truncprior,a)*b);
0144       stepsize = (supbound-infbound)/200;
0145       abscissa = infbound:stepsize:supbound;
0146       f = density(abscissa,s,nu);  
0147       if strcmp(pltopt,'all');
0148           top = max([max(ff);max(f)]);
0149       end;
0150   end;
0151   hold on;
0152   k = [1:length(f)];
0153   if pshape(i) ~= 5 
0154     [junk,k1] = max(f);
0155     if k1 == 1 | k1 == length(f)
0156       k = find(f < 10);
0157     end
0158   end
0159   hh = plot(abscissa(k),f(k),'-k','linewidth',2);
0160   set(hh,'color',[0.7 0.7 0.7]);
0161   %hold on; %% ?!
0162   if strcmp(pltopt,'all');
0163       plot( [xparam1(i) xparam1(i)], [0,top], '--g', 'linewidth', 2);
0164   end;
0165   title(nam,'Interpreter','none');
0166   hold off;
0167 end;
0168 drawnow
0169 
0170 % 12/01/03 MJ adapted from M. Ratto's version
0171

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