From d60a19ce4943d26393c44b8bb740d95622c54394 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 6 Sep 2023 12:46:41 +0200 Subject: [PATCH] Finish implementation of truncated normal distribution Closes https://git.dynare.org/Dynare/dynare/-/issues/1593 --- doc/manual/source/the-model-file.rst | 7 ++++--- matlab/draw_prior_density.m | 4 ++-- matlab/prior_bounds.m | 8 ++++---- tests/estimation/fs2000.mod | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst index 6fdcac9ff..86eb7b36a 100644 --- a/doc/manual/source/the-model-file.rst +++ b/doc/manual/source/the-model-file.rst @@ -5912,13 +5912,14 @@ observed variables. .. option:: PRIOR_3RD_PARAMETER A third parameter of the prior used for generalized beta - distribution, generalized gamma, generalized Weibull and for - the uniform distribution. Default: ``0``. + distribution, generalized gamma, generalized Weibull, the truncated normal, and for + the uniform distribution. Default: ``-Inf`` for normal distribution, ``0`` otherwise. .. option:: PRIOR_4TH_PARAMETER A fourth parameter of the prior used for generalized beta - distribution and for the uniform distribution. Default: ``1``. + distribution, the truncated normal, and for the uniform distribution. + Default: ``Inf`` for normal distribution, ``1`` otherwise. .. option:: SCALE_PARAMETER diff --git a/matlab/draw_prior_density.m b/matlab/draw_prior_density.m index c8b77e67f..59a471957 100644 --- a/matlab/draw_prior_density.m +++ b/matlab/draw_prior_density.m @@ -54,8 +54,8 @@ switch pshape(indx) abscissa = linspace(infbound,supbound,steps); dens = density(abscissa,p6(indx),p7(indx),p3(indx)); case 3% Gaussian prior - infbound = norminv(truncprior,p6(indx),p7(indx)); - supbound = norminv(1-truncprior,p6(indx),p7(indx)); + infbound = max(p3(indx),norminv(truncprior,p6(indx),p7(indx))); + supbound = min(p4(indx),norminv(1-truncprior,p6(indx),p7(indx))); abscissa = linspace(infbound,supbound,steps); dens = normpdf(abscissa,p6(indx),p7(indx)); case 4% Inverse-gamma of type 1 prior diff --git a/matlab/prior_bounds.m b/matlab/prior_bounds.m index 8749f6818..c4871bc77 100644 --- a/matlab/prior_bounds.m +++ b/matlab/prior_bounds.m @@ -93,11 +93,11 @@ for i=1:length(p6) end case 3 if prior_trunc == 0 - bounds.lb(i) = -Inf; - bounds.ub(i) = Inf; + bounds.lb(i) = max(-Inf,p3(i)); + bounds.ub(i) = min(Inf,p4(i)); else - bounds.lb(i) = norminv(prior_trunc,p6(i),p7(i)); - bounds.ub(i) = norminv(1-prior_trunc,p6(i),p7(i)); + bounds.lb(i) = max(norminv(prior_trunc,p6(i),p7(i)),p3(i)); + bounds.ub(i) = min(norminv(1-prior_trunc,p6(i),p7(i)),p4(i)); end case 4 if prior_trunc == 0 diff --git a/tests/estimation/fs2000.mod b/tests/estimation/fs2000.mod index f584d3ce9..82ea58e95 100644 --- a/tests/estimation/fs2000.mod +++ b/tests/estimation/fs2000.mod @@ -70,7 +70,7 @@ estimated_params; alp, beta_pdf, 0.356, 0.02; bet, beta_pdf, 0.993, 0.002; gam, normal_pdf, 0.0085, 0.003; -mst, normal_pdf, 1.0002, 0.007; +mst, normal_pdf, 1.0002, 0.007,1.0002-3*0.007,1.0002+3*0.007; rho, beta_pdf, 0.129, 0.223; psi, beta_pdf, 0.65, 0.05; del, beta_pdf, 0.01, 0.005;