From 2dee7d4c9e07537bcd4c020f0b0b7b844204cb40 Mon Sep 17 00:00:00 2001 From: stepan Date: Fri, 5 Jun 2009 08:30:26 +0000 Subject: [PATCH] Bug fix. The mode of the Inverted Gamma -- type 1 distribution was wrong. git-svn-id: https://www.dynare.org/svn/dynare/trunk@2722 ac1d8469-bf42-47a9-8791-bf33cf982152 --- matlab/distributions/compute_prior_mode.m | 2 +- matlab/distributions/mode_and_variance_to_mean.m | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/matlab/distributions/compute_prior_mode.m b/matlab/distributions/compute_prior_mode.m index 121c45261..061b12858 100644 --- a/matlab/distributions/compute_prior_mode.m +++ b/matlab/distributions/compute_prior_mode.m @@ -69,7 +69,7 @@ function m = compute_prior_mode(hyperparameters,shape) case 4 % s = hyperparameters(1) % nu = hyperparameters(2) - m = sqrt((hyperparameters(2)-1)/hyperparameters(1)); + m = 1/sqrt((hyperparameters(2)+1)/hyperparameters(1));%sqrt((hyperparameters(2)-1)/hyperparameters(1)) if length(hyperparameters)>2 m = m + hyperparameters(3); end diff --git a/matlab/distributions/mode_and_variance_to_mean.m b/matlab/distributions/mode_and_variance_to_mean.m index c632ef35c..31e9a4b8a 100644 --- a/matlab/distributions/mode_and_variance_to_mean.m +++ b/matlab/distributions/mode_and_variance_to_mean.m @@ -119,13 +119,13 @@ function [mu, parameters] = mode_and_variance_to_mean(m,s2,distribution,lower_bo m = m - lower_bound ; if isinf(s2) nu = 2; - s = 1/(m*m); + s = 3*(m*m); else [mu, parameters] = mode_and_variance_to_mean(m,s2,2); nu = sqrt(parameters(1)); nu2 = 2*nu; nu1 = 2; - err = s2*(m*m) - (nu-1)/(nu-2) + .5*(nu-1)*(gamma((nu-1)/2)/gamma(nu/2))^2; + err = s2/(m*m) - (nu+1)/(nu-2) + .5*(nu+1)*(gamma((nu-1)/2)/gamma(nu/2))^2; while abs(nu2-nu1) > 1e-12 if err < 0 nu1 = nu; @@ -139,9 +139,9 @@ function [mu, parameters] = mode_and_variance_to_mean(m,s2,distribution,lower_bo nu2 = nu; end nu = (nu1+nu2)/2; - err = s2*(m*m) - (nu-1)/(nu-2) + .5*(nu-1)*(gamma((nu-1)/2)/gamma(nu/2))^2; + err = s2/(m*m) - (nu+1)/(nu-2) + .5*(nu+1)*(gamma((nu-1)/2)/gamma(nu/2))^2; end - s = (nu-1)/(m*m) ; + s = (nu+1)*(m*m) ; end parameters(1) = nu; parameters(2) = s;