Trait rv::traits::InverseCdf

source ·
pub trait InverseCdf<X>: Rv<X> + Support<X> {
    // Required method
    fn invcdf(&self, p: f64) -> X;

    // Provided methods
    fn quantile(&self, p: f64) -> X { ... }
    fn interval(&self, p: f64) -> (X, X) { ... }
}
Expand description

Has an inverse-CDF / quantile function

Required Methods§

source

fn invcdf(&self, p: f64) -> X

The value of the x at the given probability in the CDF

§Example

The CDF identity: p = CDF(x) => x = CDF-1(p)

use rv::dist::Gaussian;
use rv::traits::Cdf;
use rv::traits::InverseCdf;

let g = Gaussian::standard();

let x: f64 = 1.2;
let p: f64 = g.cdf(&x);
let y: f64 = g.invcdf(p);

// x and y should be about the same
assert!((x - y).abs() < 1E-12);

Provided Methods§

source

fn quantile(&self, p: f64) -> X

Alias for invcdf

source

fn interval(&self, p: f64) -> (X, X)

Interval containing p proportion for the probability

§Example

Confidence interval

use rv::dist::Gaussian;
use rv::traits::InverseCdf;

let g = Gaussian::new(100.0, 15.0).unwrap();
let ci: (f64, f64) = g.interval(0.68268949213708585);  // one stddev
assert!( (ci.0 - 85.0).abs() < 1E-12);
assert!( (ci.1 - 115.0).abs() < 1E-12);

Object Safety§

This trait is not object safe.

Implementors§