hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_prob_gamma_vector (g01sf)

Purpose

nag_stat_prob_gamma_vector (g01sf) returns a number of lower or upper tail probabilities for the gamma distribution.

Syntax

[p, ivalid, ifail] = g01sf(tail, g, a, b, 'ltail', ltail, 'lg', lg, 'la', la, 'lb', lb)
[p, ivalid, ifail] = nag_stat_prob_gamma_vector(tail, g, a, b, 'ltail', ltail, 'lg', lg, 'la', la, 'lb', lb)

Description

The lower tail probability for the gamma distribution with parameters αiαi and βiβi, P(Gigi)P(Gigi), is defined by:
gi
P( Gi gi : αi,βi) = 1/( βiαi Γ (αi) )Giαi1eGi / βidGi,  αi > 0.0, ​βi > 0.0.
0
P( Gi gi :αi,βi) = 1 βi αi Γ (αi) 0 gi Gi αi-1 e -Gi/βi dGi ,   αi>0.0 , ​ βi>0.0 .
The mean of the distribution is αiβiαiβi and its variance is αiβi2αiβi2. The transformation Zi = (Gi)/(βi)Zi=Giβi is applied to yield the following incomplete gamma function in normalized form,
gi / βi
P( Gi gi : αi,βi) = P( Zi gi / βi : αi,1.0) = 1/( Γ (αi) )Ziαi1eZidZi.
0
P( Gi gi :αi,βi) = P( Zi gi / βi :αi,1.0) = 1 Γ (αi) 0 gi / βi Zi αi-1 e -Zi dZi .
This is then evaluated using nag_specfun_gamma_incomplete (s14ba).
The input arrays to this function are designed to allow maximum flexibility in the supply of vector parameters by re-using elements of any arrays that are shorter than the total number of evaluations required. See Section [Vectorized s] in the G01 Chapter Introduction for further information.

References

Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

Parameters

Compulsory Input Parameters

1:     tail(ltail) – cell array of strings
ltail, the dimension of the array, must satisfy the constraint ltail > 0ltail>0.
Indicates whether a lower or upper tail probability is required. For j = ((i1)  mod  ltail) + 1 j= ( (i-1) mod ltail ) +1 , for i = 1,2,,max (ltail,lg,la,lb)i=1,2,,max(ltail,lg,la,lb):
tail(j) = 'L'tailj='L'
The lower tail probability is returned, i.e., pi = P( Gi gi : αi,βi) pi = P( Gi gi :αi,βi) .
tail(j) = 'U'tailj='U'
The upper tail probability is returned, i.e., pi = P( Gi gi : αi,βi) pi = P( Gi gi :αi,βi) .
Constraint: tail(j) = 'L'tailj='L' or 'U''U', for j = 1,2,,ltailj=1,2,,ltail.
2:     g(lg) – double array
lg, the dimension of the array, must satisfy the constraint lg > 0lg>0.
gigi, the value of the gamma variate with gi = g(j)gi=gj, j = ((i1)  mod  lg) + 1j=((i-1) mod lg)+1.
Constraint: g(j)0.0gj0.0, for j = 1,2,,lgj=1,2,,lg.
3:     a(la) – double array
la, the dimension of the array, must satisfy the constraint la > 0la>0.
The parameter αiαi of the gamma distribution with αi = a(j)αi=aj, j = ((i1)  mod  la) + 1j=((i-1) mod la)+1.
Constraint: a(j) > 0.0aj>0.0, for j = 1,2,,laj=1,2,,la.
4:     b(lb) – double array
lb, the dimension of the array, must satisfy the constraint lb > 0lb>0.
The parameter βiβi of the gamma distribution with βi = b(j)βi=bj, j = ((i1)  mod  lb) + 1j=((i-1) mod lb)+1.
Constraint: b(j) > 0.0bj>0.0, for j = 1,2,,lbj=1,2,,lb.

Optional Input Parameters

1:     ltail – int64int32nag_int scalar
Default: The dimension of the array tail.
The length of the array tail.
Constraint: ltail > 0ltail>0.
2:     lg – int64int32nag_int scalar
Default: The dimension of the array g.
The length of the array g.
Constraint: lg > 0lg>0.
3:     la – int64int32nag_int scalar
Default: The dimension of the array a.
The length of the array a.
Constraint: la > 0la>0.
4:     lb – int64int32nag_int scalar
Default: The dimension of the array b.
The length of the array b.
Constraint: lb > 0lb>0.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     p( : :) – double array
Note: the dimension of the array p must be at least max (lg,la,lb,ltail)max(lg,la,lb,ltail).
pipi, the probabilities of the beta distribution.
2:     ivalid( : :) – int64int32nag_int array
Note: the dimension of the array ivalid must be at least max (lg,la,lb,ltail)max(lg,la,lb,ltail).
ivalid(i)ivalidi indicates any errors with the input arguments, with
ivalid(i) = 0ivalidi=0
No error.
ivalid(i) = 1ivalidi=1
On entry,invalid value supplied in tail when calculating pipi.
ivalid(i) = 2ivalidi=2
On entry,gi < 0.0gi<0.0.
ivalid(i) = 3ivalidi=3
On entry,αi0.0αi0.0,
orβi0.0βi0.0.
ivalid(i) = 4ivalidi=4
The solution did not converge in 600600 iterations, see nag_specfun_gamma_incomplete (s14ba) for details. The probability returned should be a reasonable approximation to the solution.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W ifail = 1ifail=1
On entry, at least one value of g, a, b or tail was invalid, or the solution did not converge.
Check ivalid for more information.
  ifail = 2ifail=2
Constraint: ltail > 0ltail>0.
  ifail = 3ifail=3
Constraint: lg > 0lg>0.
  ifail = 4ifail=4
Constraint: la > 0la>0.
  ifail = 5ifail=5
Constraint: lb > 0lb>0.
  ifail = 999ifail=-999
Dynamic memory allocation failed.

Accuracy

The result should have a relative accuracy of machine precision. There are rare occasions when the relative accuracy attained is somewhat less than machine precision but the error should not exceed more than 11 or 22 decimal places.

Further Comments

The time taken by nag_stat_prob_gamma_vector (g01sf) to calculate each probability varies slightly with the input parameters gigi, αiαi and βiβi.

Example

function nag_stat_prob_gamma_vector_example
tail = {'L'};
g = [15.5; 0.5; 10; 5];
a = [4; 4; 1; 2];
b = [2; 1; 2; 2];
% calculate probability
[p, ivalid, ifail] = nag_stat_prob_gamma_vector(tail, g, a, b);

fprintf('\nGamma deviate    Alpha     Beta    Probability\n');
lg = numel(g);
la = numel(a);
lb = numel(b);
ltail = numel(tail);
len = max ([lg, la, lb, ltail]);
for i=0:len-1
 fprintf('%9.2f%13.2f%9.2f%10.4f%8d\n', g(mod(i,lg)+1), a(mod(i,la)+1), ...
         b(mod(i,lb)+1), p(i+1), ivalid(i+1));
end
 

Gamma deviate    Alpha     Beta    Probability
    15.50         4.00     2.00    0.9499       0
     0.50         4.00     1.00    0.0018       0
    10.00         1.00     2.00    0.9933       0
     5.00         2.00     2.00    0.7127       0

function g01sf_example
tail = {'L'};
g = [15.5; 0.5; 10; 5];
a = [4; 4; 1; 2];
b = [2; 1; 2; 2];
% calculate probability
[p, ivalid, ifail] = g01sf(tail, g, a, b);

fprintf('\nGamma deviate    Alpha     Beta    Probability\n');
lg = numel(g);
la = numel(a);
lb = numel(b);
ltail = numel(tail);
len = max ([lg, la, lb, ltail]);
for i=0:len-1
 fprintf('%9.2f%13.2f%9.2f%10.4f%8d\n', g(mod(i,lg)+1), a(mod(i,la)+1), ...
         b(mod(i,lb)+1), p(i+1), ivalid(i+1));
end
 

Gamma deviate    Alpha     Beta    Probability
    15.50         4.00     2.00    0.9499       0
     0.50         4.00     1.00    0.0018       0
    10.00         1.00     2.00    0.9933       0
     5.00         2.00     2.00    0.7127       0


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013