Statistical Distributions

numerics4c++ provides the means to compute the cumulative distribution function (CDF) probabilities for common distributions. Along with CDF computations, numerics4c++ provides for the evaluation of inverse CDF values. Additionally, numerics4c++ provided the means to compute the probability mass function (PMF) probabilities for discrete deistributions.

To use a distribution, simply create a new distribution object with the desired parameters. With the distribution object, call the cdf function to compute CDF probabilities, the inverse_cdf function to compute inverse CDF values and, the pmf function to compute PMF probabilities:

// create a distribution with the desired parameters
normal_distribution z(0.0, 1.0);

double p = z.cdf(1.96);          // p = P(z <= 1.96)
double x = z.inverse_cdf(0.975); // P(z <= x) = 0.975

// create a discrete distribution
binomial_distribution b(10, 0.5);

p = b.pmf(4);          // p = P(b = 4)

The following distribution are supplied by numerics4c++:

Beta beta_distribution
Binomial binomial_distribution
number of trials
probability of success
Cauchy cauchy_distribution
Chi-Squared chi_squared_distribution degrees of freedom
Exponential exponential_distribution mean
F f_distribution
numerator degrees of freedom
denominator degrees of freedom
Gamma gamma_distribution
Geometric geometric_distribution probability of success
Hypergeometric hypergeometric_distribution
population number of successes
population number of failures
sample size
Laplace laplace_distribution
Logistic logistic_distribution
Log Normal log_normal_distribution
standard deviation
Negative Binomial negative_binomial_distribution
number of successes
probability of success
Normal normal_distribution
standard deviation
Poisson poisson_distribution mean
Rayleigh rayleigh_distribution scale
t t_distribution degrees of freedom
Uniform uniform_distribution
lower bound
upper bound

Inverse CDF's for Discrete Distributions

Special care is given to computing the inverse CDF for discrete distributions. This is because of the inexactness of the mapping from cumulative probabilities to quantiles. As such, the return value, x, of the inverse_cdf method satifies the following to criteria:

For the distribution X and target probability p:
x is the largest integer such that P(X <= x) <= p and
x is the smallest integer such that P(X >= x) >= 1 - p
For example, for a Binomial(10, 0.375) distribution:
num::binomial_distribution b(10, 0.375);
double p = 0.75;
double x = b.inverse_cdf(p);
// assert: b.cdf(x) <= 0.75
// assert: b.cdf(x + 1) >= 0.75
// assert: 1.0 - b.cdf(x) >= 0.25
// assert: 1.0 - b.cdf(x + 1) <= 0.25