Trait rv::traits::InverseCdf
source · pub trait InverseCdf<X>: HasDensity<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§
sourcefn invcdf(&self, p: f64) -> X
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§
sourcefn interval(&self, p: f64) -> (X, X)
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);