Main Content

gaminv

Gamma inverse cumulative distribution function

Description

x = gaminv(p,a) returns the inverse cumulative distribution function (icdf) of the standard gamma distribution with the shape parameter a, evaluated at the values in p.

x = gaminv(p,a,b) returns the icdf of the gamma distribution with shape parameter a and the scale parameter b, evaluated at the values in p.

example

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

example

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

Examples

collapse all

Find the median of the gamma distribution with shape parameter 3 and scale parameter 5.

x = gaminv(0.5,3,5)
x = 
13.3703

Find a confidence interval estimating the median using gamma distributed data.

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

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

Compute estimates for the parameters.

params = gamfit(x)
params = 1×2

    1.9820    5.0601

Store the estimates for the parameters as ahat and bhat.

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

Compute the covariance of the parameter estimates.

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

    0.0135   -0.0346
   -0.0346    0.1141

Create a confidence interval estimating x.

[x,xLo,xUp] = gaminv(0.50,ahat,bhat,nCov)
x = 
8.4021
xLo = 
7.8669
xUp = 
8.9737

Input Arguments

collapse all

Probability values at which to evaluate the inverse cdf (icdf), specified as a scalar value or an array of scalar values, where each element is in the range [0,1].

If you specify pCov to compute the confidence interval [xLo,xUp], then p must be a scalar value (not an array).

  • To evaluate the icdf at multiple values, specify p using an array.

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

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

Example: [0.1,0.5,0.9]

Data Types: single | double

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

  • To evaluate the icdf at multiple values, specify p using an array.

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

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

Example: [1 2 3 5]

Data Types: single | double

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

  • To evaluate the icdf at multiple values, specify p using an array.

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

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

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 [xLo,xUp], then p, 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 icdf 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

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

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

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

More About

collapse all

Gamma icdf

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

The gamma inverse function in terms of the gamma cdf is

x=F1(p|a,b)={x:F(x|a,b)=p},

where

p=F(x|a,b)=1baΓ(a)0xta1etbdt.

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

For more information, see Gamma Distribution.

Algorithms

No known analytical solution exists for the integral equation shown in Gamma icdf. gaminv uses an iterative approach (Newton's method) to converge on the solution.

Alternative Functionality

  • gaminv is a function specific to the gamma distribution. Statistics and Machine Learning Toolbox™ also offers the generic function icdf, which supports various probability distributions. To use icdf, 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 gaminv is faster than the generic function icdf.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a