Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - English


cdfgam

cumulative distribution function gamma distribution

Syntax

[P,Q]=cdfgam("PQ",X,Shape,Rate)
[X]=cdfgam("X",Shape,Rate,P,Q)
[Shape]=cdfgam("Shape",Rate,P,Q,X)
[Rate]=cdfgam("Rate",P,Q,X,Shape)

Arguments

P,Q,X,Shape,Rate

five real vectors of the same size.

P,Q (Q=1-P)

The integral from 0 to X of the gamma density. Input range: [0,1].

X

The upper limit of integration of the gamma density. Input range: [0, +infinity). Search range: [0,1E300]

Shape

The shape parameter of the gamma density. Input range: (0, +infinity). Search range: [1E-300,1E300]

Rate

The rate parameter of the gamma density. Input range: (0, +infinity). Search range: (1E-300,1E300]

Description

Calculates any one parameter of the gamma distribution given values for the others.

The gamma density is

\begin{eqnarray}
                f(x,a,r) = \frac{1}{r^{-a}\Gamma(a)} \int_0^x t^{a-1} \exp\left(-rt\right) dt
                \end{eqnarray}

where a is the shape and r is the rate.

Caution. As opposed to other technical computing languages, this function makes use of the rate parameter, and not the scale parameter. The rate parameter is linked to the scale parameter with the equation rate=1/scale.

Computation of parameters such as X, Shape or Rate involve a search for a value that produces the desired value of P. The search relies on the monotonicity of P with the other parameter.

Examples

In the following example, we compute the probability of the event x=0.1 for the Gamma distribution function with Shape=1.0 and Rate=1.0.

Shape = 0.1
Rate = 1.0
x = 0.1
// Expected : P = 0.8275518
[P,Q]=cdfgam("PQ",x,Shape,Rate)

In the following example, we compute the probability of the event x=0.1 and check that the search algorithms allows to consistently invert the function.

Shape = 0.1
Rate = 2.0
x = 0.3
[P,Q]    = cdfgam("PQ",x,Shape,Rate)
[X1]     = cdfgam("X",Shape,Rate,P,Q)
[Shape1] = cdfgam("Shape",Rate,P,Q,x)
[Rate1]  = cdfgam("Rate",P,Q,x,Shape)

In the following example, we draw the Gamma distribution function for various values of the Shape and Rate.

N = 1000;
x = linspace(0,20,N)';
Shape = [1 2 3 5 9];
Rate = 1 ./ [2 2 2 1 0.5];
C = ["red" "green" "blue" "cyan" "orange"];
lstr = [];
drawlater();
h = gcf();
for i = 1 : 5
  P = cdfgam("PQ",x,Shape(i)*ones(N,1),Rate(i)*ones(N,1));
  lstr(i) = msprintf("Shape=%s, Rate=%s",string(Shape(i)),string(Rate(i)));
  plot(x,P);
  h.children.children(1).children.foreground = color(C(i));
end
legend(lstr);
xtitle("CDF of the Gamma distribution function","X","P");
drawnow();

Bibliography

Cumulative distribution function (P) is calculated directly by the code associated with:

DiDinato, A. R. and Morris, A. H. Computation of the incomplete gamma function ratios and their inverse. ACM Trans. Math. Softw. 12 (1986), 377-393.

From DCDFLIB: Library of Fortran Routines for Cumulative Distribution Functions, Inverses, and Other Parameters (February, 1994) Barry W. Brown, James Lovato and Kathy Russell. The University of Texas.

See also

  • cdfbet — cumulative distribution function Beta distribution
  • cdfbin — cumulative distribution function Binomial distribution
  • cdfchi — cumulative distribution function chi-square distribution
  • cdfchn — cumulative distribution function non-central chi-square distribution
  • cdff — cumulative distribution function Fisher distribution
  • cdffnc — cumulative distribution function non-central f-distribution
  • cdfnbn — cumulative distribution function negative binomial distribution
  • cdfnor — cumulative distribution function normal distribution
  • cdfpoi — cumulative distribution function poisson distribution
  • cdft — cumulative distribution function Student's T distribution
Report an issue
<< cdffnc Cumulated Distribution Functions cdfnbn >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 24 11:13:09 CEST 2024