# gamcdf

Gamma cumulative distribution function

## Description

p = gamcdf(x,a) returns the cumulative distribution function (cdf) of the standard gamma distribution with the shape parameters in a, evaluated at the values in x.

example

p = gamcdf(x,a,b) returns the cdf of the gamma distribution with the shape parameters in a and scale parameters in b, evaluated at the values in x.

example

[p,pLo,pUp] = gamcdf(x,a,b,pCov) also returns the 95% confidence interval [pLo,pUp] of p when a and b are estimates. pCov is the covariance matrix of the estimated parameters.

[p,pLo,pUp] = gamcdf(x,a,b,pCov,alpha) specifies the confidence level for the confidence interval [pLo pUp] to be 100(1–alpha)%.

example

___ = gamcdf(___,'upper') returns the complement of the cdf, evaluated at the values in x, using an algorithm that more accurately computes the extreme upper-tail probabilities than subtracting the lower tail value from 1. 'upper' can follow any of the input argument combinations in the previous syntaxes.

## Examples

collapse all

Compute the cdf of the mean of the gamma distribution, which is equal to the product of the parameters ab.

a = 1:6;
b = 5:10;
prob = gamcdf(a.*b,a,b)
prob = 1×6

0.6321    0.5940    0.5768    0.5665    0.5595    0.5543

As ab increases, the distribution becomes more symmetric, and the mean approaches the median.

Find a confidence interval estimating the probability that an observation is in the interval [0 10] using gamma distributed data.

Generate a sample of 1000 gamma distributed random numbers with shape 2 and scale 5.

x = gamrnd(2,5,1000,1);

Compute estimates for the parameters.

[params,~] = gamfit(x)
params = 1×2

2.1089    4.8147

Store the parameters as ahat and bhat.

ahat = params(1);
bhat = params(2);

Find the covariance of the parameter estimates.

[~,nCov] = gamlike(params,x)
nCov = 2×2

0.0077   -0.0176
-0.0176    0.0512

Create a confidence interval estimating the probability that an observation is in the interval [0 10].

[prob,pLo,pUp] = gamcdf(10,ahat,bhat,nCov)
prob = 0.5830
pLo = 0.5587
pUp = 0.6069

Determine the probability that an observation from the gamma distribution with shape parameter 2 and scale parameter 3 will is in the interval [150 Inf].

p1 = 1 - gamcdf(150,2,3)
p1 = 0

gamcdf(150, 2, 3) is nearly 1, so p1 becomes 0. Specify 'upper' so that gamcdf computes the extreme upper-tail probabilities more accurately.

p2 = gamcdf(150,2,3,'upper')
p2 = 9.8366e-21

## Input Arguments

collapse all

Values at which to evaluate the cdf, specified as a nonnegative scalar value or an array of nonnegative scalar values.

If you specify pCov to compute the confidence interval [pLo,pUp], then x must be a scalar value.

• To evaluate the cdf at multiple values, specify x using an array.

• To evaluate the cdfs of multiple distributions, specify a and b using arrays.

If one or more of the input arguments x, a, and b are arrays, then the array sizes must be the same. In this case, gamcdf expands each scalar input into a constant array of the same size as the array inputs. Each element in p is the cdf value of the distribution specified by the corresponding elements in a and b, evaluated at the corresponding element in x.

Example: [3 4 7 9]

Data Types: single | double

Shape of the gamma distribution, specified as a positive scalar value or an array of positive scalar values.

• To evaluate the cdf at multiple values, specify x using an array.

• To evaluate the cdfs of multiple distributions, specify a and b using arrays.

If one or more of the input arguments x, a, and b are arrays, then the array sizes must be the same. In this case, gamcdf expands each scalar input into a constant array of the same size as the array inputs. Each element in p is the cdf value of the distribution specified by the corresponding elements in a and b, evaluated at the corresponding element in x.

Example: [1 2 3 5]

Data Types: single | double

Scale of the gamma distribution, specified as a positive scalar value or an array of positive scalar values.

• To evaluate the cdf at multiple values, specify x using an array.

• To evaluate the cdfs of multiple distributions, specify a and b using arrays.

If one or more of the input arguments x, a, and b are arrays, then the array sizes must be the same. In this case, gamcdf expands each scalar input into a constant array of the same size as the array inputs. Each element in p is the cdf value of the distribution specified by the corresponding elements in a and b, evaluated at the corresponding element in x.

Example: [1 1 2 2]

Data Types: single | double

Covariance of the estimates a and b, specified as a 2-by-2 matrix.

If you specify pCov to compute the confidence interval [pLo,pUp], then x, a, and b must be scalar values.

You can estimate a and b by using gamfit or mle, and estimate the covariance of a and b by using gamlike. For an example, see Confidence Interval of Gamma cdf Value.

Data Types: single | double

Significance level for the confidence interval, specified as a scalar in the range (0,1). The confidence level is 100(1–alpha)%, where alpha is the probability that the confidence interval does not contain the true value.

Example: 0.01

Data Types: single | double

## Output Arguments

collapse all

cdf values evaluated at the values in x, returned as a scalar value or an array of scalar values. p is the same size as x, a, and b after any necessary scalar expansion. Each element in p is the cdf value of the distribution specified by the corresponding elements in a and b, evaluated at the corresponding element in x.

Lower confidence bound for p, returned as a scalar value or an array of scalar values. pLo has the same size as p.

Upper confidence bound for p, returned as a scalar value or an array of scalar values. pUp has the same size as p.

collapse all

### Gamma cdf

The gamma distribution is a two-parameter family of curves. The parameters a and b are shape and scale, respectively.

The gamma cdf is

$p=F\left(x|a,b\right)=\frac{1}{{b}^{a}\Gamma \left(a\right)}\underset{0}{\overset{x}{\int }}{t}^{a-1}{e}^{\frac{-t}{b}}dt.$

The result p is the probability that a single observation from a gamma distribution with parameters a and b falls in the interval [0,x].

The gamma cdf is related to the incomplete gamma function gammainc by

$f\left(x|a,b\right)=\text{gammainc}\left(\frac{x}{b},a\right).$

The standard gamma distribution occurs when b = 1, which coincides with the incomplete gamma function precisely.

## Alternative Functionality

• gamcdf is a function specific to the gamma distribution. Statistics and Machine Learning Toolbox™ also offers the generic function cdf, which supports various probability distributions. To use cdf, create a GammaDistribution probability distribution object and pass the object as an input argument or specify the probability distribution name and its parameters. Note that the distribution-specific function gamcdf is faster than the generic function cdf.

• Use the Probability Distribution Function app to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.