Trait statrs::distribution::DiscreteCDF[][src]

pub trait DiscreteCDF<K: Bounded + Clone + Num, T: Float>: Min<K> + Max<K> {
    fn cdf(&self, x: K) -> T;

    fn inverse_cdf(&self, p: T) -> K { ... }
}
Expand description

The DiscreteCDF trait is used to specify an interface for univariate discrete distributions.

Required methods

fn cdf(&self, x: K) -> T[src]

Expand description

Returns the cumulative distribution function calculated at x for a given distribution. May panic depending on the implementor.

Examples

use statrs::distribution::{ContinuousCDF, Uniform};

let n = Uniform::new(0.0, 1.0).unwrap();
assert_eq!(0.5, n.cdf(0.5));

Provided methods

fn inverse_cdf(&self, p: T) -> K[src]

Expand description

Due to issues with rounding and floating-point accuracy the default implementation may be ill-behaved Specialized inverse cdfs should be used whenever possible.

Implementors

impl DiscreteCDF<i64, f64> for DiscreteUniform[src]

fn cdf(&self, x: i64) -> f64[src]

Calculates the cumulative distribution function for the discrete uniform distribution at x

Formula

(floor(x) - min + 1) / (max - min + 1)

impl DiscreteCDF<u64, f64> for Bernoulli[src]

fn cdf(&self, x: u64) -> f64[src]

Calculates the cumulative distribution function for the bernoulli distribution at x.

Formula

if x < 0 { 0 }
else if x >= 1 { 1 }
else { 1 - p }

impl DiscreteCDF<u64, f64> for Binomial[src]

fn cdf(&self, x: u64) -> f64[src]

Calculates the cumulative distribution function for the binomial distribution at x

Formula

I_(1 - p)(n - x, 1 + x)

where I_(x)(a, b) is the regularized incomplete beta function

impl DiscreteCDF<u64, f64> for Categorical[src]

fn cdf(&self, x: u64) -> f64[src]

Calculates the cumulative distribution function for the categorical distribution at x

Formula

sum(p_j) from 0..x

where p_j is the probability mass for the jth category

fn inverse_cdf(&self, x: f64) -> u64[src]

Calculates the inverse cumulative distribution function for the categorical distribution at x

Panics

If x <= 0.0 or x >= 1.0

Formula

i

where i is the first index such that x < f(i) and f(x) is defined as p_x + f(x - 1) and f(0) = p_0 where p_x is the xth probability mass

impl DiscreteCDF<u64, f64> for Geometric[src]

fn cdf(&self, x: u64) -> f64[src]

Calculates the cumulative distribution function for the geometric distribution at x

Formula

1 - (1 - p) ^ (x + 1)

impl DiscreteCDF<u64, f64> for Hypergeometric[src]

fn cdf(&self, x: u64) -> f64[src]

Calculates the cumulative distribution function for the hypergeometric distribution at x

Formula

1 - ((n choose k+1) * (N-n choose K-k-1)) / (N choose K) * 3_F_2(1,
k+1-K, k+1-n; k+2, N+k+2-K-n; 1)

where N is population, K is successes, n is draws, and p_F_q is the [generalized hypergeometric function](https://en.wikipedia. org/wiki/Generalized_hypergeometric_function)

impl DiscreteCDF<u64, f64> for NegativeBinomial[src]

fn cdf(&self, x: u64) -> f64[src]

Calculates the cumulative distribution function for the negative binomial distribution at x

Note that due to extending the distribution to the reals (allowing positive real values for r), while still technically a discrete distribution the CDF behaves more like that of a continuous distribution rather than a discrete distribution (i.e. a smooth graph rather than a step-ladder)

Formula

1 - I_(1 - p)(x + 1, r)

where I_(x)(a, b) is the regularized incomplete beta function

impl DiscreteCDF<u64, f64> for Poisson[src]

fn cdf(&self, x: u64) -> f64[src]

Calculates the cumulative distribution function for the poisson distribution at x

Formula

1 - P(x + 1, λ)

where λ is the rate and P is the lower regularized gamma function