# PROB Probability Density Functions

PROB, a C library which handles various discrete and continuous probability density functions (PDF's).

For a discrete variable X, PDF(X) is the probability that the value X will occur; for a continuous variable, PDF(X) is the probability density of X, that is, the probability of a value between X and X+dX is PDF(X) * dX.

The corresponding cumulative density functions or "CDF"'s are also handled. For a discrete or continuous variable, CDF(X) is the probability that the variable takes on a value less than or equal to X.

In some cases, the inverse of the CDF can easily be computed. If

```
X = CDF_INV ( P )
```
then we are asserting that the value X has a cumulative probability density function of P, in other words, the probability that the variable is less than or equal to X is P. If the CDF cannot be analytically inverted, there are simple ways to try to estimate the inverse. Depending on the PDF, these methods may be rapid and accurate, or not.

For most distributions, the mean or "average value" or "expected value" is also available. For a discrete variable, MEAN is simply the sum of the products X * PDF(X); for a continuous variable, MEAN is the integral of X * PDF(X) over the range. For the distributions covered here, the means are known beforehand, and no summation or integration is required.

For most distributions, the variance is available. For a discrete variable, the variance is the sum of the products ( X - MEAN )^2 * PDF(X); for a continuous variable, the variance is the integral of ( X - MEAN )^2 * PDF(X) over the range. The square root of the variance is known as the standard deviation. For the distributions covered here, the variances are often known beforehand, and no summation or integration is required.

For many of the distributions, it is possible to repeatedly request "samples", that is, a pseudorandom sequence of realizations of the PDF. These samples are always associated with an integer seed, which controls the calculation. Using the same seed as input will guarantee the same sample value on output. Ultimately, a random number generator must be invoked internally. In most cases, the current code will call a routine called R8_RANDOM or I4_RANDOM, each of which in turn calls a routine called R8_UNIFORM_01. You may prefer a different random number generator for this purpose.

### Languages:

PROB is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

### Related Data and Programs:

ASA152, a C library which evaluates point and cumulative probabilities associated with the hypergeometric distribution; this is Applied Statistics Algorithm 152;

ASA226, a C library which evaluates the CDF of the noncentral Beta distribution.

ASA241, a C library which evaluates the percentage points of the normal distribution.

ASA243, a C library which evaluates the CDF of the noncentral T distribution.

ASA310, a C library which computes the CDF of the noncentral Beta distribution.

BETA_NC, a C library which evaluates the CDF of the noncentral Beta distribution.

CDFLIB, a C library which evaluates the cumulative density function (CDF), inverse CDF, and certain other inverse functions, for distributions including beta, binomial, chi-square, noncentral chi-square, F, noncentral F, gamma, negative binomial, normal, Poisson, and students T, by Barry Brown, James Lovato, Kathy Russell.

DISCRETE_PDF_SAMPLE_2D, a C program which demonstrates how to construct a Probability Density Function (PDF) from a table of sample data, and then to use that PDF to create new samples.

LOG_NORMAL, a C library which returns quantities associated with the log normal Probability Distribution Function (PDF).

LOG_NORMAL_TRUNCATED_AB, a C library which returns quantities associated with the log normal Probability Distribution Function (PDF) truncated to the interval [A,B].

NORMAL, a C library which samples the normal distribution.

TRUNCATED_NORMAL, a C library which works with the truncated normal distribution over [A,B], or [A,+oo) or (-oo,B], returning the probability density function (PDF), the cumulative density function (CDF), the inverse CDF, the mean, the variance, and sample values.

UNIFORM, a C library which samples the uniform distribution.

ZIGGURAT, a C program which generates points from a uniform, normal or exponential distribution, using the ziggurat method.

### Reference:

1. Milton Abramowitz, Irene Stegun,
Handbook of Mathematical Functions,
National Bureau of Standards, 1964,
ISBN: 0-486-61272-4,
LC: QA47.A34.
2. Jerry Banks, editor,
Handbook of Simulation,
Wiley, 1998,
ISBN: 0471134031,
LC: T57.62.H37.
3. Paul Bratley, Bennett Fox, Linus Schrage,
A Guide to Simulation,
Second Edition,
Springer, 1987,
ISBN: 0387964673.
4. Luc Devroye,
Non-Uniform Random Variate Generation,
Springer, 1986,
ISBN: 0387963057,
LC: QA274.D48
5. Norman Johnson, Samuel Kotz, Narayanaswamy Balakrishnan,
Continuous Univariate Distributions,
Second edition,
Wiley, 1994,
ISBN: 0471584940,
LC: QA273.6.J6
6. Norman Johnson, Samuel Kotz, Adrienne Kemp,
Univariate Discrete Distributions,
Third edition,
Wiley, 2005,
ISBN: 0471272469,
LC: QA273.6.J64

### Source Code:

Last revised on 28 July 2019.