2005-02-18 20:54:39 +01:00
|
|
|
function [s,nu] = inverse_gamma_specification(mu,sigma,type)
|
2008-01-11 17:05:00 +01:00
|
|
|
|
|
|
|
% function [s,nu] = inverse_gamma_specification(mu,sigma,type)
|
|
|
|
% Specification of the inverse Gamma function parameters
|
|
|
|
% X ~ IG(s,nu)
|
2005-02-18 20:54:39 +01:00
|
|
|
%
|
2008-01-11 17:05:00 +01:00
|
|
|
% INPUTS
|
|
|
|
% mu: expectation
|
|
|
|
% sigma: standard deviation
|
|
|
|
% type=1: inverse Gamma 1
|
|
|
|
% type=2: inverse Gamma 2
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2008-01-11 17:05:00 +01:00
|
|
|
% OUTPUTS
|
|
|
|
% s: shape parameter
|
|
|
|
% nu: scale parameter
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
% part of DYNARE, copyright Dynare Team (2003-2008)
|
|
|
|
% Gnu Public License.
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
|
|
sigma2 = sigma^2;
|
|
|
|
mu2 = mu^2;
|
|
|
|
|
|
|
|
if type == 2; % Inverse Gamma 2
|
|
|
|
nu = 2*(2+mu2/sigma2);
|
|
|
|
s = 2*mu*(1+mu2/sigma2);
|
|
|
|
elseif type == 1; % Inverse Gamma 1
|
|
|
|
if sigma2 < Inf;
|
|
|
|
nu = sqrt(2*(2+mu2/sigma2));
|
|
|
|
nu2 = 2*nu;
|
|
|
|
nu1 = 2;
|
|
|
|
err = 2*mu2*gamma(nu/2)^2-(sigma2+mu2)*(nu-2)*gamma((nu-1)/2)^2;
|
|
|
|
while abs(nu2-nu1) > 1e-12
|
|
|
|
if err > 0
|
|
|
|
nu1 = nu;
|
|
|
|
if nu < nu2
|
|
|
|
nu = nu2;
|
|
|
|
else
|
|
|
|
nu = 2*nu;
|
|
|
|
nu2 = nu;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
nu2 = nu;
|
|
|
|
end
|
|
|
|
nu = (nu1+nu2)/2;
|
|
|
|
err = 2*mu2*gamma(nu/2)^2-(sigma2+mu2)*(nu-2)*gamma((nu-1)/2)^2;
|
|
|
|
end
|
|
|
|
s = (sigma2+mu2)*(nu-2);
|
|
|
|
else;
|
|
|
|
nu = 2;
|
|
|
|
s = 2*mu2/pi;
|
|
|
|
end;
|
|
|
|
else;
|
|
|
|
s = -1;
|
|
|
|
nu = -1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
% 01/18/2004 MJ replaced fsolve with secant
|
|
|
|
% suppressed chck
|
|
|
|
% changed order of output parameters
|