Home > matlab > priordens.m

priordens

PURPOSE ^

Computes a prior density for the structural parameters of DSGE models

SYNOPSIS ^

function [logged_prior_density, dlprior, d2lprior] = priordens(x, pshape, p6, p7, p3, p4,initialization)

DESCRIPTION ^

 Computes a prior density for the structural parameters of DSGE models

 INPUTS 
    x              [double]      vector with n elements.
    pshape         [integer]     vector with n elements (bayestopt_.pshape).
    p6:            [double]      vector with n elements, first  parameter of the prior distribution (bayestopt_.p6).
    p7:            [double]      vector with n elements, second parameter of the prior distribution (bayestopt_.p7).
    p3:            [double]      vector with n elements, lower bounds.
    p4:            [double]      vector with n elements, upper bound.
    initialization [integer]     if 1: initialize persistent variables
    
 OUTPUTS 
    logged_prior_density  [double]  scalar, log of the prior density evaluated at x.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [logged_prior_density, dlprior, d2lprior] = priordens(x, pshape, p6, p7, p3, p4,initialization)
0002 % Computes a prior density for the structural parameters of DSGE models
0003 %
0004 % INPUTS
0005 %    x              [double]      vector with n elements.
0006 %    pshape         [integer]     vector with n elements (bayestopt_.pshape).
0007 %    p6:            [double]      vector with n elements, first  parameter of the prior distribution (bayestopt_.p6).
0008 %    p7:            [double]      vector with n elements, second parameter of the prior distribution (bayestopt_.p7).
0009 %    p3:            [double]      vector with n elements, lower bounds.
0010 %    p4:            [double]      vector with n elements, upper bound.
0011 %    initialization [integer]     if 1: initialize persistent variables
0012 %
0013 % OUTPUTS
0014 %    logged_prior_density  [double]  scalar, log of the prior density evaluated at x.
0015 %
0016 
0017 % Copyright (C) 2003-2010 Dynare Team
0018 %
0019 % This file is part of Dynare.
0020 %
0021 % Dynare is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % Dynare is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 persistent id1 id2 id3 id4 id5 id6
0035 persistent tt1 tt2 tt3 tt4 tt5 tt6
0036 
0037 if nargin > 6  && initialization == 1
0038     % Beta indices.
0039     tt1 = 1;
0040     id1 = find(pshape==1);
0041     if isempty(id1)
0042         tt1 = 0;
0043     end
0044     % Gamma indices.
0045     tt2 = 1;
0046     id2 = find(pshape==2);
0047     if isempty(id2)
0048         tt2 = 0;
0049     end
0050     % Gaussian indices.
0051     tt3 = 1;
0052     id3 = find(pshape==3);
0053     if isempty(id3)
0054         tt3 = 0;
0055     end
0056     % Inverse-Gamma-1 indices.
0057     tt4 = 1;
0058     id4 = find(pshape==4);
0059     if isempty(id4)
0060         tt4 = 0;
0061     end
0062     % Uniform indices.
0063     tt5 = 1;
0064     id5 = find(pshape==5);
0065     if isempty(id5)
0066         tt5 = 0;
0067     end
0068     % Inverse-Gamma-2 indices.
0069     tt6 = 1;
0070     id6 = find(pshape==6);
0071     if isempty(id6)
0072         tt6 = 0;
0073     end
0074     pflag = 1;
0075 end
0076 
0077 logged_prior_density = 0.0;
0078 
0079 if tt1
0080     logged_prior_density = logged_prior_density + sum(lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1))) ;
0081     if isinf(logged_prior_density)
0082         return
0083     end
0084     if nargout == 2,
0085         [tmp, dlprior(id1)]=lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1));
0086     elseif nargout == 3
0087         [tmp, dlprior(id1), d2lprior(id1)]=lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1));
0088     end
0089 end
0090 
0091 if tt2
0092     logged_prior_density = logged_prior_density + sum(lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2))) ;
0093     if isinf(logged_prior_density)
0094         return
0095     end
0096     if nargout == 2,
0097         [tmp, dlprior(id2)]=lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2));
0098     elseif nargout == 3
0099         [tmp, dlprior(id2), d2lprior(id2)]=lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2));
0100     end
0101 end
0102 
0103 if tt3
0104     logged_prior_density = logged_prior_density + sum(lpdfnorm(x(id3),p6(id3),p7(id3))) ;
0105     if nargout == 2,
0106         [tmp, dlprior(id3)]=lpdfnorm(x(id3),p6(id3),p7(id3));
0107     elseif nargout == 3
0108         [tmp, dlprior(id3), d2lprior(id3)]=lpdfnorm(x(id3),p6(id3),p7(id3));
0109     end
0110 end
0111 
0112 if tt4
0113     logged_prior_density = logged_prior_density + sum(lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4))) ;
0114     if isinf(logged_prior_density)
0115         return
0116     end
0117     if nargout == 2,
0118         [tmp, dlprior(id4)]=lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4));
0119     elseif nargout == 3
0120         [tmp, dlprior(id4), d2lprior(id4)]=lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4));
0121     end
0122 end
0123 
0124 if tt5
0125     if any(x(id5)-p3(id5)<0) || any(x(id5)-p4(id5)>0)
0126         logged_prior_density = -Inf ;
0127         return
0128     end
0129     logged_prior_density = logged_prior_density + sum(log(1./(p4(id5)-p3(id5)))) ;
0130     if nargout >1,
0131         dlprior(id5)=zeros(length(id5),1);
0132     end
0133     if nargout == 3
0134         d2lprior(id5)=zeros(length(id5),1);
0135     end
0136 end
0137 
0138 if tt6
0139     logged_prior_density = logged_prior_density + sum(lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6))) ;
0140     if isinf(logged_prior_density)
0141         return
0142     end
0143     if nargout == 2,
0144         [tmp, dlprior(id6)]=lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6));
0145     elseif nargout == 3
0146         [tmp, dlprior(id6), d2lprior(id6)]=lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6));
0147     end
0148 end
0149 
0150 if nargout==3,
0151     d2lprior = diag(d2lprior);
0152 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005