2017-05-16 12:42:01 +02:00
|
|
|
function [x,f,abscissa,dens,binf,bsup] = draw_prior_density(indx,bayestopt_)
|
2009-04-06 16:38:37 +02:00
|
|
|
% Computes values of prior densities at many points (before plotting)
|
2008-01-10 16:21:59 +01:00
|
|
|
%
|
|
|
|
% INPUTS
|
2009-02-04 11:44:54 +01:00
|
|
|
% indx [integer] Parameter number.
|
|
|
|
% bayestopt_ [structure] Describes the prior beliefs.
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2008-01-10 16:21:59 +01:00
|
|
|
% OUTPUTS
|
2009-02-04 11:44:54 +01:00
|
|
|
% x [double] Row vector, subset of 'abscissa' such as the density is less than 10
|
|
|
|
% f [double] Row vector, subset of 'dens' such as the density is less than 10
|
2017-05-16 15:10:20 +02:00
|
|
|
% abscissa [double] Row vector, abscissa
|
2009-02-04 11:44:54 +01:00
|
|
|
% dens [double] Row vector, density
|
|
|
|
% binf: [double] Scalar, first element of x
|
|
|
|
% bsup: [double] Scalar, last element of x
|
2009-04-06 16:38:37 +02:00
|
|
|
|
2008-01-10 16:21:59 +01:00
|
|
|
|
2023-03-16 15:33:42 +01:00
|
|
|
% Copyright © 2004-2023 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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-04-06 16:38:37 +02:00
|
|
|
pshape = bayestopt_.pshape;
|
2005-02-18 20:54:39 +01:00
|
|
|
p3 = bayestopt_.p3;
|
|
|
|
p4 = bayestopt_.p4;
|
2009-04-06 16:38:37 +02:00
|
|
|
p6 = bayestopt_.p6;
|
|
|
|
p7 = bayestopt_.p7;
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2008-08-05 15:31:33 +02:00
|
|
|
truncprior = 1e-3;
|
|
|
|
steps = 200;
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2008-08-05 12:48:04 +02:00
|
|
|
switch pshape(indx)
|
2009-04-06 16:38:37 +02:00
|
|
|
case 1% Beta prior
|
2008-08-05 15:31:33 +02:00
|
|
|
density = @(x,a,b,aa,bb) betapdf((x-aa)/(bb-aa), a, b)/(bb-aa);
|
2009-04-06 16:38:37 +02:00
|
|
|
infbound = betainv(truncprior,p6(indx),p7(indx))*(p4(indx)-p3(indx))+p3(indx);
|
|
|
|
supbound = betainv(1-truncprior,p6(indx),p7(indx))*(p4(indx)-p3(indx))+p3(indx);
|
2011-11-19 21:14:43 +01:00
|
|
|
abscissa = linspace(infbound,supbound,steps);
|
2009-04-06 16:38:37 +02:00
|
|
|
dens = density(abscissa,p6(indx),p7(indx),p3(indx),p4(indx));
|
|
|
|
case 2% Generalized Gamma prior
|
2008-08-05 15:31:33 +02:00
|
|
|
density = @(x,a,b,c) gampdf(x-c,a,b);
|
2023-03-16 15:33:42 +01:00
|
|
|
infbound = gaminv(truncprior,p6(indx),p7(indx))+p3(indx);
|
|
|
|
supbound = gaminv(1-truncprior,p6(indx),p7(indx))+p3(indx);
|
2011-11-19 21:14:43 +01:00
|
|
|
abscissa = linspace(infbound,supbound,steps);
|
2009-04-06 16:38:37 +02:00
|
|
|
dens = density(abscissa,p6(indx),p7(indx),p3(indx));
|
|
|
|
case 3% Gaussian prior
|
2017-05-16 15:10:20 +02:00
|
|
|
infbound = norminv(truncprior,p6(indx),p7(indx));
|
2009-04-06 16:38:37 +02:00
|
|
|
supbound = norminv(1-truncprior,p6(indx),p7(indx));
|
2011-11-19 21:14:43 +01:00
|
|
|
abscissa = linspace(infbound,supbound,steps);
|
2017-05-16 15:10:20 +02:00
|
|
|
dens = normpdf(abscissa,p6(indx),p7(indx));
|
2009-04-06 16:38:37 +02:00
|
|
|
case 4% Inverse-gamma of type 1 prior
|
2023-03-16 15:33:42 +01:00
|
|
|
infbound = 1/sqrt(gaminv(1-10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx);
|
|
|
|
supbound = 1/sqrt(gaminv(10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx);
|
2011-11-19 21:14:43 +01:00
|
|
|
abscissa = linspace(infbound,supbound,steps);
|
2017-05-16 15:10:20 +02:00
|
|
|
dens = exp(lpdfig1(abscissa-p3(indx),p6(indx),p7(indx)));
|
2009-04-06 16:38:37 +02:00
|
|
|
case 5% Uniform prior
|
|
|
|
infbound = p6(indx);
|
|
|
|
supbound = p7(indx);
|
2011-11-19 21:14:43 +01:00
|
|
|
abscissa = linspace(infbound,supbound,steps);
|
2008-08-05 15:31:33 +02:00
|
|
|
dens = ones(1, steps) / (supbound-infbound);
|
2009-04-06 16:38:37 +02:00
|
|
|
case 6% Inverse-gamma of type 2 prior
|
2023-03-16 15:33:42 +01:00
|
|
|
infbound = 1/(gaminv(1-10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx);
|
|
|
|
supbound = 1/(gaminv(10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx);
|
2011-11-19 21:14:43 +01:00
|
|
|
abscissa = linspace(infbound,supbound,steps);
|
2009-04-06 16:38:37 +02:00
|
|
|
dens = exp(lpdfig2(abscissa-p3(indx),p6(indx),p7(indx)));
|
2015-12-04 14:50:44 +01:00
|
|
|
case 8
|
|
|
|
density = @(x,a,b,c) exp(lpdfgweibull(x, a, b, c));
|
2015-12-14 15:32:03 +01:00
|
|
|
infbound = p3(indx)+wblinv(truncprior,p6(indx),p7(indx));
|
|
|
|
supbound = p3(indx)+wblinv(1-truncprior,p6(indx),p7(indx));
|
2015-12-04 14:50:44 +01:00
|
|
|
abscissa = linspace(infbound,supbound,steps);
|
|
|
|
dens = density(abscissa,p6(indx),p7(indx),p3(indx));
|
2009-04-06 16:38:37 +02:00
|
|
|
otherwise
|
|
|
|
error(sprintf('draw_prior_density: unknown distribution shape (index %d, type %d)', indx, pshape(indx)));
|
2017-05-16 15:10:20 +02:00
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
if pshape(indx) ~= 5
|
2018-11-13 17:58:42 +01:00
|
|
|
[~,k1] = max(dens);
|
2011-02-10 15:54:23 +01:00
|
|
|
if k1 == 1 || k1 == length(dens)
|
2011-11-19 21:14:43 +01:00
|
|
|
k = find(dens > 10);
|
|
|
|
dens(k) = NaN;
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
|
|
|
end
|
2011-11-19 21:14:43 +01:00
|
|
|
binf = abscissa(1);
|
|
|
|
bsup = abscissa(end);
|
|
|
|
x = abscissa;
|
2014-10-16 15:27:40 +02:00
|
|
|
f = dens;
|