


This function computes the mode of the prior distribution given the (two, three or four) hyperparameters
of the prior distribution.
INPUTS
hyperparameters [double] 1*n vector of hyper parameters.
shape [integer] scalar specifying the prior shape:
shape=1 => Beta distribution,
shape=2 => Gamma distribution,
shape=3 => Gaussian distribution,
shape=4 => Inverse Gamma (type 1) distribution,
shape=5 => Uniform distribution,
shape=6 => Inverse Gamma (type 2) distribution.
OUTPUTS
m [double] scalar or 2*1 vector, the prior mode.
REMARKS
[1] The size of the vector of hyperparameters is 3 when the Gamma or Inverse Gamma is shifted and 4 when
the support of the Beta distribution is not [0,1].
[2] The hyperparameters of the uniform distribution are the lower and upper bounds.
[3] The uniform distribution has an infinity of modes. In this case the function returns the prior mean.
[4] For the beta distribution we can have 1, 2 or an infinity of modes.

0001 function m = compute_prior_mode(hyperparameters,shape) 0002 % This function computes the mode of the prior distribution given the (two, three or four) hyperparameters 0003 % of the prior distribution. 0004 % 0005 % INPUTS 0006 % hyperparameters [double] 1*n vector of hyper parameters. 0007 % shape [integer] scalar specifying the prior shape: 0008 % shape=1 => Beta distribution, 0009 % shape=2 => Gamma distribution, 0010 % shape=3 => Gaussian distribution, 0011 % shape=4 => Inverse Gamma (type 1) distribution, 0012 % shape=5 => Uniform distribution, 0013 % shape=6 => Inverse Gamma (type 2) distribution. 0014 % 0015 % OUTPUTS 0016 % m [double] scalar or 2*1 vector, the prior mode. 0017 % 0018 % REMARKS 0019 % [1] The size of the vector of hyperparameters is 3 when the Gamma or Inverse Gamma is shifted and 4 when 0020 % the support of the Beta distribution is not [0,1]. 0021 % [2] The hyperparameters of the uniform distribution are the lower and upper bounds. 0022 % [3] The uniform distribution has an infinity of modes. In this case the function returns the prior mean. 0023 % [4] For the beta distribution we can have 1, 2 or an infinity of modes. 0024 0025 % Copyright (C) 2009 Dynare Team 0026 % 0027 % This file is part of Dynare. 0028 % 0029 % Dynare is free software: you can redistribute it and/or modify 0030 % it under the terms of the GNU General Public License as published by 0031 % the Free Software Foundation, either version 3 of the License, or 0032 % (at your option) any later version. 0033 % 0034 % Dynare is distributed in the hope that it will be useful, 0035 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0036 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0037 % GNU General Public License for more details. 0038 % 0039 % You should have received a copy of the GNU General Public License 0040 % along with Dynare. If not, see <http://www.gnu.org/licenses/>. 0041 m = NaN ; 0042 switch shape 0043 case 1 0044 if (hyperparameters(1)>1 && hyperparameters(2)>1) 0045 m = (hyperparameters(1)-1)/(hyperparameters(1)+hyperparameters(2)-2) ; 0046 elseif (hyperparameters(1)<1 && hyperparameters(2)<1) 0047 m = [ 0 ; 1 ] ; 0048 elseif ( hyperparameters(1)<1 && hyperparameters(2)>1-eps ) || ( abs(hyperparameters(1)-1)<2*eps && hyperparameters(2)>1 ) 0049 m = 0; 0050 elseif ( hyperparameters(1)>1 && hyperparameters(2)<1+eps ) || ( abs(hyperparameters(1)-1)<2*eps && hyperparameters(2)<1 ) 0051 m = 1; 0052 elseif ( abs(hyperparameters(1)-1)<2*eps && abs(hyperparameters(2)-1)<2*eps )% Uniform distribution! 0053 m = .5 ; 0054 end 0055 if length(hyperparameters)==4 0056 m = m*(hyperparameters(4)-hyperparameters(3)) + hyperparameters(3) ; 0057 end 0058 case 2 0059 if hyperparameters(1)<1 0060 m = 0; 0061 else 0062 m = (hyperparameters(1)-1)*hyperparameters(2); 0063 end 0064 if length(hyperparameters)>2 0065 m = m + hyperparameters(3); 0066 end 0067 case 3 0068 m = hyperparameters(1); 0069 case 4 0070 % s = hyperparameters(1) 0071 % nu = hyperparameters(2) 0072 m = 1/sqrt((hyperparameters(2)+1)/hyperparameters(1));%sqrt((hyperparameters(2)-1)/hyperparameters(1)) 0073 if length(hyperparameters)>2 0074 m = m + hyperparameters(3); 0075 end 0076 case 5 0077 m = .5*(hyperparameters(2)-hyperparameters(1)) ; 0078 case 6 0079 % s = hyperparameters(1) 0080 % nu = hyperparameters(2) 0081 m = hyperparameters(1)/(hyperparameters(2)+2) ; 0082 if length(hyperparameters)>2 0083 m = m + hyperparameters(3) ; 0084 end 0085 otherwise 0086 error('Unknown prior shape!') 0087 end