Cumulative Distribution Function (CDF) of Gamma distribution FORMAT F = spm_Gcdf(x,h,l) x - Gamma-variate (Gamma has range [0,Inf) ) h - Shape parameter (h>0) l - Scale parameter (l>0) F - CDF of Gamma-distribution with shape & scale parameters h & l __________________________________________________________________________ spm_Gcdf implements the Cumulative Distribution of the Gamma-distribution. Definition: ----------------------------------------------------------------------- The CDF F(x) of the Gamma distribution with shape parameter h and scale l is the probability that a realisation of a Gamma random variable X has value less than x F(x)=Pr{X<x} for X~G(h,l). The Gamma distribution is defined for h>0 & l>0 and for x in [0,Inf) (See Evans et al., Ch18, but note that this reference uses the alternative parameterisation of the Gamma with scale parameter c=1/l) Variate relationships: (Evans et al., Ch18 & Ch8) ----------------------------------------------------------------------- For natural (strictly +ve integer) shape h this is an Erlang distribution. The Standard Gamma distribution has a single parameter, the shape h. The scale taken as l=1. The Chi-squared distribution with v degrees of freedom is equivalent to the Gamma distribution with scale parameter 1/2 and shape parameter v/2. Algorithm: ----------------------------------------------------------------------- The CDF of the Gamma distribution with scale parameter l and shape h is related to the incomplete Gamma function by F(x) = gammainc(l*x,h) See Abramowitz & Stegun, 6.5.1; Press et al., Sec6.2 for definitions of the incomplete Gamma function. The relationship is easily verified by substituting for t/c in the integral, where c=1/l. MatLab's implementation of the incomplete gamma function is used. References: ----------------------------------------------------------------------- Evans M, Hastings N, Peacock B (1993) "Statistical Distributions" 2nd Ed. Wiley, New York Abramowitz M, Stegun IA, (1964) "Handbook of Mathematical Functions" US Government Printing Office Press WH, Teukolsky SA, Vetterling AT, Flannery BP (1992) "Numerical Recipes in C" Cambridge __________________________________________________________________________ @(#)spm_Gcdf.m 2.2 Andrew Holmes 99/04/26
0001 function F = spm_Gcdf(x,h,l) 0002 % Cumulative Distribution Function (CDF) of Gamma distribution 0003 % FORMAT F = spm_Gcdf(x,h,l) 0004 % 0005 % x - Gamma-variate (Gamma has range [0,Inf) ) 0006 % h - Shape parameter (h>0) 0007 % l - Scale parameter (l>0) 0008 % F - CDF of Gamma-distribution with shape & scale parameters h & l 0009 %__________________________________________________________________________ 0010 % 0011 % spm_Gcdf implements the Cumulative Distribution of the Gamma-distribution. 0012 % 0013 % Definition: 0014 %----------------------------------------------------------------------- 0015 % The CDF F(x) of the Gamma distribution with shape parameter h and 0016 % scale l is the probability that a realisation of a Gamma random 0017 % variable X has value less than x F(x)=Pr{X<x} for X~G(h,l). The Gamma 0018 % distribution is defined for h>0 & l>0 and for x in [0,Inf) (See Evans 0019 % et al., Ch18, but note that this reference uses the alternative 0020 % parameterisation of the Gamma with scale parameter c=1/l) 0021 % 0022 % Variate relationships: (Evans et al., Ch18 & Ch8) 0023 %----------------------------------------------------------------------- 0024 % For natural (strictly +ve integer) shape h this is an Erlang distribution. 0025 % 0026 % The Standard Gamma distribution has a single parameter, the shape h. 0027 % The scale taken as l=1. 0028 % 0029 % The Chi-squared distribution with v degrees of freedom is equivalent 0030 % to the Gamma distribution with scale parameter 1/2 and shape parameter v/2. 0031 % 0032 % Algorithm: 0033 %----------------------------------------------------------------------- 0034 % The CDF of the Gamma distribution with scale parameter l and shape h 0035 % is related to the incomplete Gamma function by 0036 % 0037 % F(x) = gammainc(l*x,h) 0038 % 0039 % See Abramowitz & Stegun, 6.5.1; Press et al., Sec6.2 for definitions 0040 % of the incomplete Gamma function. The relationship is easily verified 0041 % by substituting for t/c in the integral, where c=1/l. 0042 % 0043 % MatLab's implementation of the incomplete gamma function is used. 0044 % 0045 % References: 0046 %----------------------------------------------------------------------- 0047 % Evans M, Hastings N, Peacock B (1993) 0048 % "Statistical Distributions" 0049 % 2nd Ed. Wiley, New York 0050 % 0051 % Abramowitz M, Stegun IA, (1964) 0052 % "Handbook of Mathematical Functions" 0053 % US Government Printing Office 0054 % 0055 % Press WH, Teukolsky SA, Vetterling AT, Flannery BP (1992) 0056 % "Numerical Recipes in C" 0057 % Cambridge 0058 %__________________________________________________________________________ 0059 % @(#)spm_Gcdf.m 2.2 Andrew Holmes 99/04/26 0060 0061 %-Format arguments, note & check sizes 0062 %----------------------------------------------------------------------- 0063 if nargin<3, error('Insufficient arguments'), end 0064 0065 ad = [ndims(x);ndims(h);ndims(l)]; 0066 rd = max(ad); 0067 as = [ [size(x),ones(1,rd-ad(1))];... 0068 [size(h),ones(1,rd-ad(2))];... 0069 [size(l),ones(1,rd-ad(3))] ]; 0070 rs = max(as); 0071 xa = prod(as,2)>1; 0072 if sum(xa)>1 & any(any(diff(as(xa,:)),1)) 0073 error('non-scalar args must match in size'), end 0074 0075 %-Computation 0076 %----------------------------------------------------------------------- 0077 %-Initialise result to zeros 0078 F = zeros(rs); 0079 0080 %-Only defined for strictly positive h & l. Return NaN if undefined. 0081 md = ( ones(size(x)) & h>0 & l>0 ); 0082 if any(~md(:)), F(~md) = NaN; 0083 warning('Returning NaN for out of range arguments'), end 0084 0085 %-Non-zero where defined and x>0 0086 Q = find( md & x>0 ); 0087 if isempty(Q), return, end 0088 if xa(1), Qx=Q; else Qx=1; end 0089 if xa(2), Qh=Q; else Qh=1; end 0090 if xa(3), Ql=Q; else Ql=1; end 0091 0092 %-Compute 0093 F(Q) = gammainc(l(Ql).*x(Qx),h(Qh));