10.7 Cumulative Distribution Functions
For most of the univariate probability functions, there is a corresponding cumulative distribution function, log cumulative distribution function, and log complementary cumulative distribution function.
For a univariate random variable \(Y\) with probability function \(p_Y(y \, | \, \theta)\), the cumulative distribution function (CDF) \(F_Y\) is defined by \[ F_Y(y) \ = \ \text{Pr}[Y \le y] \ = \ \int_{-\infty}^y p(y \, | \, \theta) \ \text{d}y. \] The complementary cumulative distribution function (CCDF) is defined as \[ \text{Pr}[Y > y] \ = \ 1 - F_Y(y). \] The reason to use CCDFs instead of CDFs in floating-point arithmetic is that it is possible to represent numbers very close to 0 (the closest you can get is roughly \(10^{-300}\)), but not numbers very close to 1 (the closest you can get is roughly \(1 - 10^{-15}\)).
In Stan, there is a cumulative distribution function for each
probability function. For instance, normal_cdf(y, mu, sigma)
is
defined by \[ \int_{-\infty}^y \text{Normal}(y \, | \, \mu, \sigma) \
\text{d}y. \] There are also log forms of the CDF and CCDF for most
univariate distributions. For example, normal_lcdf(y | mu, sigma)
is defined by \[ \log \left( \int_{-\infty}^y \text{Normal}(y \, | \,
\mu, \sigma) \ \text{d}y \right) \] and normal_lccdf(y | mu, sigma)
is defined by \[ \log \left( 1 - \int_{-\infty}^y
\text{Normal}(y \, | \, \mu, \sigma) \ \text{d}y \right). \]