gammaCdf

Evaluates the gamma distribution function.

Synopsis

gammaCdf (x, a)

Required Arguments

float x (Input)
Argument for which the gamma distribution function is to be evaluated.
float a (Input)
Shape parameter of the gamma distribution. This parameter must be positive.

Return Value

The probability that a gamma random variable takes a value less than or equal to x.

Description

Function gammaCdf evaluates the distribution function, F, of a gamma random variable with shape parameter a,

\[F(x) = \frac{1}{\mathit{\Gamma}(a)} \int_0^x e^{-t} t^{a-1} dt\]

where Γ(⋅) is the gamma function. (The gamma function is the integral from 0 to ∞ of the same integrand as above.) The value of the distribution function at the point x is the probability that the random variable takes a value less than or equal to x.

The gamma distribution is often defined as a two-parameter distribution with a scale parameter b (which must be positive) or as a three-parameter distribution in which the third parameter c is a location parameter. In the most general case, the probability density function over (c, ∞) is as follows:

\[f(t) = \frac{1}{b^a \mathit{\Gamma}(a)} e^{-(t-c)/b} (x-c)^{a-1}\]

If T is a random variable with parameters a, b, and c, the probability that \(T\leq t_0\) can be obtained from gammaCdf by setting \(x=(t_0-c)/b\).

If x is less than a or less than or equal to 1.0, gammaCdf uses a series expansion; otherwise, a continued fraction expansion is used. (See Abramowitz and Stegun 1964.)

Example

Let X be a gamma random variable with a shape parameter of four. (In this case, it has an Erlang distribution since the shape parameter is an integer.) This example finds the probability that X is less than 0.5 and the probability that X is between 0.5 and 1.0.

from __future__ import print_function
from numpy import *
from pyimsl.stat.gammaCdf import gammaCdf

a = 4.0
x = 0.5
pr1 = gammaCdf(x, a)
print("The probability that X is less than 0.5 is %6.4f" % pr1)

x = 1.0
pr2 = gammaCdf(x, a) - pr1
print("The probability that X is between 0.5 and 1.0 is %6.4f" % pr2)

Output

The probability that X is less than 0.5 is 0.0018
The probability that X is between 0.5 and 1.0 is 0.0172

Informational Errors

IMSLS_ARG_LESS_THAN_ZERO Since “x” = # is less than zero, the distribution function is zero at “x”.

Fatal Errors

IMSLS_X_AND_A_TOO_LARGE Since “x” = # and “a” = # are so large, the algorithm would overflow.