| 1 |
function P = invgamcdf(X, a, b); |
| 2 |
|
| 3 |
% This function computes the cumulative density for the inverse gamma |
| 4 |
% distribution with shape parameter a and scale parameter b. It uses the |
| 5 |
% following closed-form solution for the cdf of the inverse gamma |
| 6 |
% distribution: |
| 7 |
% ---------Cumulative density function for Inverse-Gamma distribution------- |
| 8 |
% --- P(x; a, b) = G(b/x, a)/G(a), where G(b/x, a) is the upper incomplete |
| 9 |
% gamma function and G(a) is the gamma function defined as |
| 10 |
% G(b/x, a) = int_{b/x}^{\infty} t^{a-1} e^{-t} dt. |
| 11 |
% The Matlab definition is different, which is |
| 12 |
% gammainc(b/x, a) = (1.0/Gamma(a)) int_{0}^{b/x} t^{a-1} e^{-t} dt. |
| 13 |
% Thus, we have |
| 14 |
% G(b/x, a)/G(a) = (1-gammainc(b./X, a)). |
| 15 |
|
| 16 |
% First, check for input errors |
| 17 |
% |
| 18 |
% Copyright (C) 1997-2012 Tao Zha |
| 19 |
% |
| 20 |
% This free software: you can redistribute it and/or modify |
| 21 |
% it under the terms of the GNU General Public License as published by |
| 22 |
% the Free Software Foundation, either version 3 of the License, or |
| 23 |
% (at your option) any later version. |
| 24 |
% |
| 25 |
% It is distributed in the hope that it will be useful, |
| 26 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
% GNU General Public License for more details. |
| 29 |
% |
| 30 |
% If you did not received a copy of the GNU General Public License |
| 31 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 32 |
% |
| 33 |
|
| 34 |
if X<=0; |
| 35 |
error('the support for the inverse gamma function needs to be positive') |
| 36 |
end; |
| 37 |
if a<= 0 || b <=0; |
| 38 |
a = abs(a); |
| 39 |
b = abs(b); |
| 40 |
% abs() is used to allow continuous search for the fsolve function find_invgampar.m. |
| 41 |
%error('parameter requirements: a>0, b>0'); |
| 42 |
end; |
| 43 |
|
| 44 |
P = (1-gammainc(b./X, a)); |