217 lines
14 KiB
HTML
217 lines
14 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
|
"http://www.w3.org/TR/REC-html40/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Description of compDist</title>
|
|
<meta name="keywords" content="compDist">
|
|
<meta name="description" content="">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<meta name="generator" content="m2html © 2003 Guillaume Flandin">
|
|
<meta name="robots" content="index, follow">
|
|
<link type="text/css" rel="stylesheet" href="../m2html.css">
|
|
</head>
|
|
<body>
|
|
<a name="_top"></a>
|
|
<div><a href="../index.html">Home</a> > <a href="index.html">.</a> > compDist.m</div>
|
|
|
|
<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td>
|
|
<td align="right"><a href="index.html">Index for . <img alt=">" border="0" src="../right.png"></a></td></tr></table>-->
|
|
|
|
<h1>compDist
|
|
</h1>
|
|
|
|
<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
|
<div class="box"><strong></strong></div>
|
|
|
|
<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
|
<div class="box"><strong>function compdist(xparam1, x2, pltopt, figurename) </strong></div>
|
|
|
|
<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
|
<div class="fragment"><pre class="comment"></pre></div>
|
|
|
|
<!-- crossreference -->
|
|
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
|
This function calls:
|
|
<ul style="list-style-image:url(../matlabicon.gif)">
|
|
<li><a href="lpdfgam.html" class="code" title="function ldens = lpdfgam(x,a,b);">lpdfgam</a> log GAMMA PDF</li><li><a href="mj_qgamma.html" class="code" title="function x = mj_qgamma(p,a)">mj_qgamma</a> MJ_QGAMMA The gamma inverse distribution function</li><li><a href="posterior_density_estimate.html" class="code" title="function [abscissa,f,h] = posterior_density_estimate(data,number_of_grid_points,bandwidth,kernel_function)">posterior_density_estimate</a> %</li><li><a href="qbeta.html" class="code" title="function x = qbeta(p,a,b)">qbeta</a> QBETA The beta inverse distribution function</li><li><a href="qgamma.html" class="code" title="function x = qgamma(p,a)">qgamma</a> QGAMMA The gamma inverse distribution function</li><li><a href="qnorm.html" class="code" title="function x = qnorm(p,m,s)">qnorm</a> QNORM The normal inverse distribution function</li></ul>
|
|
This function is called by:
|
|
<ul style="list-style-image:url(../matlabicon.gif)">
|
|
</ul>
|
|
<!-- crossreference -->
|
|
|
|
|
|
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
|
|
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function compdist(xparam1, x2, pltopt, figurename)</a>
|
|
0002 <span class="keyword">global</span> bayestopt_ estim_params_ M_ options_
|
|
0003
|
|
0004 <span class="comment">% NOTE: If pltopt ~= 'All' compdist.m just draws prior densities.</span>
|
|
0005
|
|
0006 <span class="comment">%% Set density estimation parameters:</span>
|
|
0007 number_of_grid_points = 2^9; <span class="comment">% 2^9 = 512 !... Must be a power of two.</span>
|
|
0008 bandwidth = 0; <span class="comment">% Rule of thumb optimal bandwidth parameter.</span>
|
|
0009 kernel_function = <span class="string">'gaussian'</span>; <span class="comment">% You can switch to: 'epanechnikov', 'quartic', 'triangle',</span>
|
|
0010 <span class="comment">% 'triweight', 'uniform' or 'cosinus' kernels (iff bandwidth=0, see posterior_density_estimate.m).</span>
|
|
0011 truncprior = 10^(-3);
|
|
0012
|
|
0013
|
|
0014 npar=length(xparam1);
|
|
0015 nruns=length(x2);
|
|
0016 icol=ceil(sqrt(npar));
|
|
0017 iraw=icol;
|
|
0018 <span class="keyword">if</span> (icol-1)*(icol-2)>=npar
|
|
0019 iraw = icol-2;
|
|
0020 icol=icol-1;
|
|
0021 <span class="keyword">elseif</span> (icol)*(icol-2)>=npar
|
|
0022 iraw = icol-2;
|
|
0023 <span class="keyword">elseif</span> icol*(icol-1)>=npar
|
|
0024 iraw=icol-1;
|
|
0025 <span class="keyword">end</span>
|
|
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(<span class="string">'Name'</span>,figurename)
|
|
0035 <span class="keyword">for</span> i=1:npar;
|
|
0036 <span class="keyword">if</span> i<=estim_params_.nvx
|
|
0037 vname = deblank(M_.exo_name(estim_params_.var_exo(i,1),:));
|
|
0038 nam=[<span class="string">'SE_{'</span>,vname,<span class="string">'}'</span>];
|
|
0039 <span class="keyword">elseif</span> i<=(estim_params_.nvx+estim_params_.nvn)
|
|
0040 deblank(options_.varobs(estim_params_.var_endo(i-estim_params_.nvx,1),:));
|
|
0041 nam=[<span class="string">'SE_{EOBS_'</span>,vname,<span class="string">'}'</span>];
|
|
0042 <span class="keyword">elseif</span> 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,:)) <span class="string">','</span> deblank(M_.exo_name(k2,:))];
|
|
0047 nam=[<span class="string">'CC_{'</span>,vname,<span class="string">'}'</span>];
|
|
0048 <span class="keyword">elseif</span> i<=(estim_params_.nvx+estim_params_.nvn+estim_params_.ncx+ <span class="keyword">...</span>
|
|
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,:)) <span class="string">','</span> deblank(M_.exo_name(k2,:))];
|
|
0054 nam=[<span class="string">'CC_{EOBS_'</span>,vname,<span class="string">'}'</span>];
|
|
0055 <span class="keyword">else</span>
|
|
0056 j = i - (estim_params_.nvx+estim_params_.nvn+estim_params_.ncx+ <span class="keyword">...</span>
|
|
0057 estim_params_.ncn);
|
|
0058 nam = deblank(estim_params_.param_names(j,:));
|
|
0059 <span class="keyword">end</span>
|
|
0060 subplot(iraw, icol, i);
|
|
0061 <span class="keyword">if</span> strcmpi(pltopt,<span class="string">'all'</span>); <span class="comment">% Estimation of the density...</span>
|
|
0062 [abscissa,ff,h] = <a href="posterior_density_estimate.html" class="code" title="function [abscissa,f,h] = posterior_density_estimate(data,number_of_grid_points,bandwidth,kernel_function)">posterior_density_estimate</a>(x2(round(options_.mh_drop*nruns):<span class="keyword">end</span>,i),<span class="keyword">...</span>
|
|
0063 number_of_grid_points,bandwidth,kernel_function);
|
|
0064 plot(abscissa,ff,<span class="string">'-k'</span>,<span class="string">'linewidth'</span>,2);
|
|
0065 <span class="keyword">end</span>;
|
|
0066 a = 0;
|
|
0067 b = 0;
|
|
0068 <span class="keyword">if</span> pshape(i) == 1; <span class="comment">%/* BETA Prior */</span>
|
|
0069 density = inline(<span class="string">'((1-x).^(b-1)).*x.^(a-1)./beta(a,b)'</span>,<span class="string">'x'</span>,<span class="string">'a'</span>,<span class="string">'b'</span>);
|
|
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 = <a href="qbeta.html" class="code" title="function x = qbeta(p,a,b)">qbeta</a>(truncprior,a,b);
|
|
0075 supbound = <a href="qbeta.html" class="code" title="function x = qbeta(p,a,b)">qbeta</a>(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 <span class="keyword">if</span> strcmp(pltopt,<span class="string">'all'</span>);
|
|
0081 top = max([max(ff);max(f)]);
|
|
0082 <span class="keyword">end</span>;
|
|
0083 <span class="keyword">elseif</span> pshape(i) == 2; <span class="comment">%/* GAMMA PRIOR */</span>
|
|
0084 <span class="comment">% density =</span>
|
|
0085 <span class="comment">% inline('((x/b).^(a-1)).*exp(-x/b)*inv(b*gamma(a))','x','a','b');</span>
|
|
0086 mu = p1(i)-p3(i);
|
|
0087 b = p2(i)^2/mu;
|
|
0088 a = mu/b;
|
|
0089 infbound = <a href="mj_qgamma.html" class="code" title="function x = mj_qgamma(p,a)">mj_qgamma</a>(truncprior,a)*b;
|
|
0090 supbound = <a href="mj_qgamma.html" class="code" title="function x = mj_qgamma(p,a)">mj_qgamma</a>(1-truncprior,a)*b;
|
|
0091 stepsize = (supbound-infbound)/200;
|
|
0092 abscissa = infbound:stepsize:supbound;
|
|
0093 f = exp(<a href="lpdfgam.html" class="code" title="function ldens = lpdfgam(x,a,b);">lpdfgam</a>(abscissa,a,b));
|
|
0094 abscissa = abscissa + p3(i);
|
|
0095 <span class="keyword">if</span> strcmp(pltopt,<span class="string">'all'</span>);
|
|
0096 top = max([max(ff);max(f)]);
|
|
0097 <span class="keyword">end</span>;
|
|
0098 <span class="keyword">elseif</span> pshape(i) == 3; <span class="comment">%/* GAUSSIAN PRIOR */</span>
|
|
0099 density = inline(<span class="string">'inv(sqrt(2*pi)*b)*exp(-0.5*((x-a)/b).^2)'</span>,<span class="string">'x'</span>,<span class="string">'a'</span>,<span class="string">'b'</span>);
|
|
0100 a = p1(i);
|
|
0101 b = p2(i);
|
|
0102 infbound = <a href="qnorm.html" class="code" title="function x = qnorm(p,m,s)">qnorm</a>(truncprior,a,b);
|
|
0103 supbound = <a href="qnorm.html" class="code" title="function x = qnorm(p,m,s)">qnorm</a>(1-truncprior,a,b);
|
|
0104 stepsize = (supbound-infbound)/200;
|
|
0105 abscissa = infbound:stepsize:supbound;
|
|
0106 f = density(abscissa,a,b);
|
|
0107 <span class="keyword">if</span> strcmp(pltopt,<span class="string">'all'</span>);
|
|
0108 top = max([max(ff);max(f)]);
|
|
0109 <span class="keyword">end</span>;
|
|
0110 <span class="keyword">elseif</span> pshape(i) == 4; <span class="comment">%/* INVGAMMA PRIOR type 1 */</span>
|
|
0111 density = inline(<span class="string">'2*inv(gamma(nu/2))*(x.^(-nu-1))*((s/2)^(nu/2)).*exp(-s./(2*x.^2))'</span>,<span class="string">'x'</span>,<span class="string">'s'</span>,<span class="string">'nu'</span>);
|
|
0112 nu = p2(i);
|
|
0113 s = p1(i);
|
|
0114 a = nu/2;
|
|
0115 b = 2/s;
|
|
0116 infbound = 1/sqrt(<a href="mj_qgamma.html" class="code" title="function x = mj_qgamma(p,a)">mj_qgamma</a>(1-10*truncprior,a)*b);
|
|
0117 supbound = 1/sqrt(<a href="mj_qgamma.html" class="code" title="function x = mj_qgamma(p,a)">mj_qgamma</a>(10*truncprior,a)*b);
|
|
0118 stepsize = (supbound-infbound)/200;
|
|
0119 abscissa = infbound:stepsize:supbound;
|
|
0120 f = density(abscissa,s,nu);
|
|
0121 <span class="keyword">if</span> strcmp(pltopt,<span class="string">'all'</span>);
|
|
0122 top = max([max(ff);max(f)]);
|
|
0123 <span class="keyword">end</span>;
|
|
0124 <span class="keyword">elseif</span> pshape(i) == 5; <span class="comment">%/* UNIFORM PRIOR */</span>
|
|
0125 density = inline(<span class="string">'(x.^0)/(b-a)'</span>,<span class="string">'x'</span>,<span class="string">'a'</span>,<span class="string">'b'</span>);
|
|
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 <span class="keyword">if</span> strcmp(pltopt,<span class="string">'all'</span>);
|
|
0134 top = max([max(ff);max(f)]);
|
|
0135 <span class="keyword">end</span>;
|
|
0136 <span class="keyword">elseif</span> pshape(i) == 6; <span class="comment">%/* INVGAMMA PRIOR type 2 */</span>
|
|
0137 density = inline(<span class="string">'inv(gamma(nu/2))*(x.^(-.5(nu+2)))*((s/2)^(nu/2)).*exp(-s./(2*x))'</span>,<span class="string">'x'</span>,<span class="string">'s'</span>,<span class="string">'nu'</span>);
|
|
0138 nu = p2(i);
|
|
0139 s = p1(i);
|
|
0140 a = nu/2;
|
|
0141 b = 2/s;
|
|
0142 infbound = 1/(<a href="qgamma.html" class="code" title="function x = qgamma(p,a)">qgamma</a>(1-truncprior,a)*b);
|
|
0143 supbound = 1/(<a href="qgamma.html" class="code" title="function x = qgamma(p,a)">qgamma</a>(truncprior,a)*b);
|
|
0144 stepsize = (supbound-infbound)/200;
|
|
0145 abscissa = infbound:stepsize:supbound;
|
|
0146 f = density(abscissa,s,nu);
|
|
0147 <span class="keyword">if</span> strcmp(pltopt,<span class="string">'all'</span>);
|
|
0148 top = max([max(ff);max(f)]);
|
|
0149 <span class="keyword">end</span>;
|
|
0150 <span class="keyword">end</span>;
|
|
0151 hold on;
|
|
0152 k = [1:length(f)];
|
|
0153 <span class="keyword">if</span> pshape(i) ~= 5
|
|
0154 [junk,k1] = max(f);
|
|
0155 <span class="keyword">if</span> k1 == 1 | k1 == length(f)
|
|
0156 k = find(f < 10);
|
|
0157 <span class="keyword">end</span>
|
|
0158 <span class="keyword">end</span>
|
|
0159 hh = plot(abscissa(k),f(k),<span class="string">'-k'</span>,<span class="string">'linewidth'</span>,2);
|
|
0160 set(hh,<span class="string">'color'</span>,[0.7 0.7 0.7]);
|
|
0161 <span class="comment">%hold on; %% ?!</span>
|
|
0162 <span class="keyword">if</span> strcmp(pltopt,<span class="string">'all'</span>);
|
|
0163 plot( [xparam1(i) xparam1(i)], [0,top], <span class="string">'--g'</span>, <span class="string">'linewidth'</span>, 2);
|
|
0164 <span class="keyword">end</span>;
|
|
0165 title(nam,<span class="string">'Interpreter'</span>,<span class="string">'none'</span>);
|
|
0166 hold off;
|
|
0167 <span class="keyword">end</span>;
|
|
0168 drawnow
|
|
0169
|
|
0170 <span class="comment">% 12/01/03 MJ adapted from M. Ratto's version</span>
|
|
0171</pre></div>
|
|
<hr><address>Generated on Fri 16-Jun-2006 09:09:06 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address>
|
|
</body>
|
|
</html> |