2014-09-17 20:09:33 +02:00
|
|
|
function [logged_prior_density, dlprior, d2lprior, info] = priordens(x, pshape, p6, p7, p3, p4,initialization)
|
2009-04-06 16:38:37 +02:00
|
|
|
% Computes a prior density for the structural parameters of DSGE models
|
2008-01-10 15:47:31 +01:00
|
|
|
%
|
2009-04-06 16:38:37 +02:00
|
|
|
% INPUTS
|
2010-02-06 14:43:16 +01:00
|
|
|
% 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).
|
2014-01-28 18:41:07 +01:00
|
|
|
% p3: [double] vector with n elements, lower bounds of the untruncated standard or generalized distribution
|
|
|
|
% p4: [double] vector with n elements, upper bound of the untruncated standard or generalized distribution
|
2010-02-06 14:43:16 +01:00
|
|
|
% initialization [integer] if 1: initialize persistent variables
|
2008-01-10 15:47:31 +01:00
|
|
|
%
|
2009-04-06 16:38:37 +02:00
|
|
|
% OUTPUTS
|
|
|
|
% logged_prior_density [double] scalar, log of the prior density evaluated at x.
|
2014-09-17 20:09:33 +02:00
|
|
|
% info [double] error code for index of Inf-prior parameter
|
2008-01-10 15:47:31 +01:00
|
|
|
%
|
2008-08-01 14:40:33 +02:00
|
|
|
|
2013-06-12 16:42:09 +02:00
|
|
|
% Copyright (C) 2003-2012 Dynare Team
|
2008-08-01 14:40:33 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2015-12-04 14:50:44 +01:00
|
|
|
persistent id1 id2 id3 id4 id5 id6 id8
|
|
|
|
persistent tt1 tt2 tt3 tt4 tt5 tt6 tt8
|
2009-04-06 16:38:37 +02:00
|
|
|
|
2014-09-17 20:09:33 +02:00
|
|
|
info=0;
|
|
|
|
|
2010-02-06 14:43:16 +01:00
|
|
|
if nargin > 6 && initialization == 1
|
2009-04-06 16:38:37 +02:00
|
|
|
% Beta indices.
|
|
|
|
tt1 = 1;
|
|
|
|
id1 = find(pshape==1);
|
|
|
|
if isempty(id1)
|
|
|
|
tt1 = 0;
|
|
|
|
end
|
|
|
|
% Gamma indices.
|
|
|
|
tt2 = 1;
|
|
|
|
id2 = find(pshape==2);
|
|
|
|
if isempty(id2)
|
|
|
|
tt2 = 0;
|
|
|
|
end
|
|
|
|
% Gaussian indices.
|
|
|
|
tt3 = 1;
|
|
|
|
id3 = find(pshape==3);
|
|
|
|
if isempty(id3)
|
|
|
|
tt3 = 0;
|
|
|
|
end
|
|
|
|
% Inverse-Gamma-1 indices.
|
|
|
|
tt4 = 1;
|
|
|
|
id4 = find(pshape==4);
|
|
|
|
if isempty(id4)
|
|
|
|
tt4 = 0;
|
|
|
|
end
|
|
|
|
% Uniform indices.
|
|
|
|
tt5 = 1;
|
|
|
|
id5 = find(pshape==5);
|
|
|
|
if isempty(id5)
|
|
|
|
tt5 = 0;
|
|
|
|
end
|
|
|
|
% Inverse-Gamma-2 indices.
|
|
|
|
tt6 = 1;
|
|
|
|
id6 = find(pshape==6);
|
|
|
|
if isempty(id6)
|
|
|
|
tt6 = 0;
|
|
|
|
end
|
2015-12-04 14:50:44 +01:00
|
|
|
% Weibull indices.
|
|
|
|
tt8 = 1;
|
|
|
|
id8 = find(pshape==8);
|
|
|
|
if isempty(id8)
|
|
|
|
tt8 = 0;
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
pflag = 1;
|
|
|
|
end
|
|
|
|
|
|
|
|
logged_prior_density = 0.0;
|
2012-12-19 13:15:24 +01:00
|
|
|
dlprior = 0.0;
|
|
|
|
d2lprior = 0.0;
|
2009-04-06 16:38:37 +02:00
|
|
|
|
|
|
|
if tt1
|
|
|
|
logged_prior_density = logged_prior_density + sum(lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1))) ;
|
|
|
|
if isinf(logged_prior_density)
|
2014-09-17 20:09:33 +02:00
|
|
|
if nargout ==4
|
|
|
|
info=id1(isinf(lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1))));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
return
|
|
|
|
end
|
2011-11-07 09:17:38 +01:00
|
|
|
if nargout == 2,
|
|
|
|
[tmp, dlprior(id1)]=lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1));
|
|
|
|
elseif nargout == 3
|
|
|
|
[tmp, dlprior(id1), d2lprior(id1)]=lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if tt2
|
|
|
|
logged_prior_density = logged_prior_density + sum(lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2))) ;
|
|
|
|
if isinf(logged_prior_density)
|
2014-09-17 20:09:33 +02:00
|
|
|
if nargout ==4
|
|
|
|
info=id2(isinf(lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2))));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
return
|
|
|
|
end
|
2011-11-07 09:17:38 +01:00
|
|
|
if nargout == 2,
|
|
|
|
[tmp, dlprior(id2)]=lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2));
|
|
|
|
elseif nargout == 3
|
|
|
|
[tmp, dlprior(id2), d2lprior(id2)]=lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if tt3
|
|
|
|
logged_prior_density = logged_prior_density + sum(lpdfnorm(x(id3),p6(id3),p7(id3))) ;
|
2011-11-07 09:17:38 +01:00
|
|
|
if nargout == 2,
|
|
|
|
[tmp, dlprior(id3)]=lpdfnorm(x(id3),p6(id3),p7(id3));
|
|
|
|
elseif nargout == 3
|
|
|
|
[tmp, dlprior(id3), d2lprior(id3)]=lpdfnorm(x(id3),p6(id3),p7(id3));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if tt4
|
|
|
|
logged_prior_density = logged_prior_density + sum(lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4))) ;
|
|
|
|
if isinf(logged_prior_density)
|
2014-09-17 20:09:33 +02:00
|
|
|
if nargout ==4
|
|
|
|
info=id4(isinf(lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4))));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
return
|
|
|
|
end
|
2011-11-07 09:17:38 +01:00
|
|
|
if nargout == 2,
|
|
|
|
[tmp, dlprior(id4)]=lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4));
|
|
|
|
elseif nargout == 3
|
|
|
|
[tmp, dlprior(id4), d2lprior(id4)]=lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-04-06 16:38:37 +02:00
|
|
|
if tt5
|
|
|
|
if any(x(id5)-p3(id5)<0) || any(x(id5)-p4(id5)>0)
|
|
|
|
logged_prior_density = -Inf ;
|
2014-09-17 20:09:33 +02:00
|
|
|
if nargout ==4
|
|
|
|
info=id5((x(id5)-p3(id5)<0) || (x(id5)-p4(id5)>0));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
logged_prior_density = logged_prior_density + sum(log(1./(p4(id5)-p3(id5)))) ;
|
2011-11-07 09:17:38 +01:00
|
|
|
if nargout >1,
|
|
|
|
dlprior(id5)=zeros(length(id5),1);
|
|
|
|
end
|
|
|
|
if nargout == 3
|
|
|
|
d2lprior(id5)=zeros(length(id5),1);
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-04-06 16:38:37 +02:00
|
|
|
if tt6
|
|
|
|
logged_prior_density = logged_prior_density + sum(lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6))) ;
|
|
|
|
if isinf(logged_prior_density)
|
2014-09-17 20:09:33 +02:00
|
|
|
if nargout ==4
|
|
|
|
info=id6(isinf(lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6))));
|
|
|
|
end
|
2009-04-06 16:38:37 +02:00
|
|
|
return
|
|
|
|
end
|
2011-11-07 09:17:38 +01:00
|
|
|
if nargout == 2,
|
|
|
|
[tmp, dlprior(id6)]=lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6));
|
|
|
|
elseif nargout == 3
|
|
|
|
[tmp, dlprior(id6), d2lprior(id6)]=lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6));
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-04 14:50:44 +01:00
|
|
|
if tt8
|
|
|
|
logged_prior_density = logged_prior_density + sum(lpdfgweibull(x(id8),p6(id8),p7(id8)));
|
|
|
|
if isinf(logged_prior_density)
|
|
|
|
if nargout ==4
|
|
|
|
info=id8(isinf(log(lpdfgweibull(x(id8),p6(id8),p7(id8)))));
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if nargout==2
|
|
|
|
[tmp, dlprior(id8)] = lpdfgweibull(x(id8),p6(id8),p7(id8))
|
|
|
|
elseif nargout==3
|
|
|
|
[tmp, dlprior(id8), ds2lprior(id8)] = lpdfgweibull(x(id8),p6(id8),p7(id8))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-07 09:17:38 +01:00
|
|
|
if nargout==3,
|
|
|
|
d2lprior = diag(d2lprior);
|
2009-04-06 16:38:37 +02:00
|
|
|
end
|