The Probability Functions module provides cumulative distribution, density/mass, and quantile functions for a wide range of probability distributions.
Unless otherwise documented, all of these functions are wrappers around functionality provided by the boost C++ library [1, “Statistical Distributions and Functions”].
For convenience, all cumulative distribution and density/mass functions (CDFs and PDF/PMFs in short) are defined over the range of all floating-point numbers including infinity. Inputs that are NULL or NaN (not a number) will always produce a NULL or NaN result, respectively. Inputs that are plus or minus infinity will return the respective limits.
A quantile function for a probability distrution with CDF
takes a probability argument
and returns the value
so that
, provided such an
exists and it is unique. If it does not, the result will be
(interpreted as 0 if the supremum is over an empty set) if
, and
if
. Here
denotes the domain of the distribution, which is the set of reals
for continuous and the set of nonnegative integers
for discrete distributions.
Intuitively, the formulas in the previous paragraph deal with the following special cases. The 0-quantile will always be the “left end” of the support, and the 1-quantile will be the “right end” of the support of the distribution. For discrete distributions, most values of
do not admit an
with
. Instead, there is an
so that
. The above formulas mean that the value returned as
-quantile is
if
, and it is
if
. (As a special case, in order to ensure that quantiles are always within the support, the
-quantile will be 0 if
).
The rationale for choosing this behavior is that
-quantiles for
are typically requested when interested in the value
such that with confidence level at least
a random variable will be
(or equivalently, with probability at most
, it will be
). Likewise,
-quantiles for
are typically requested when interested in the value
such that with confidence level at least
a random variable will be
. See also [1, “Understanding Quantiles of Discrete Distributions”].
Cumulative distribution functions:
distribution_cdf(random variate[, parameter1 [, parameter2 [, parameter3] ] ])
Probability density/mass functions:
distribution_{pdf|pmf}(random variate[, parameter1 [, parameter2 [, parameter3] ] ])Quantile functions:
distribution_quantile(probability[, parameter1 [, parameter2 [, parameter3] ] ])
For concrete function signatures, see prob.sql_in.
SELECT madlib.normal_cdf(0);
Result:
normal_cdf
-----------
0.5
SELECT madlib.normal_quantile(0.5, 0, 1);
Result:
normal_quantile
----------------
0
(1 row)
[1] John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno Lalande, Johan Råde, Gautam Sewani and Thijs van den Berg: Boost Math Toolkit, Version 1.49, available at: http://www.boost.org/doc/libs/1_49_0/libs/math/doc/sf_and_dist/html/index.html