Trait statrs::statistics::Median[][src]

pub trait Median<T> {
    fn median(&self) -> T;
}
Expand description

The Median trait returns the median of the distribution.

Required methods

fn median(&self) -> T[src]

Expand description

Returns the median.

Examples

use statrs::statistics::Median;
use statrs::distribution::Uniform;

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

Implementors

impl Median<f64> for Bernoulli[src]

fn median(&self) -> f64[src]

Returns the median of the bernoulli distribution

Formula

if p < 0.5 { 0 }
else if p > 0.5 { 1 }
else { 0.5 }

impl Median<f64> for Binomial[src]

fn median(&self) -> f64[src]

Returns the median of the binomial distribution

Formula

floor(n * p)

impl Median<f64> for Categorical[src]

fn median(&self) -> f64[src]

Returns the median of the categorical distribution

Formula

CDF^-1(0.5)

impl Median<f64> for Cauchy[src]

fn median(&self) -> f64[src]

Returns the median of the cauchy distribution

Formula

x_0

where x_0 is the location

impl Median<f64> for ChiSquared[src]

fn median(&self) -> f64[src]

Returns the median of the chi-squared distribution

Formula

k * (1 - (2 / 9k))^3

impl Median<f64> for Dirac[src]

fn median(&self) -> f64[src]

Returns the median of the dirac distribution

Formula

v

where v is the point of the dirac distribution

impl Median<f64> for DiscreteUniform[src]

fn median(&self) -> f64[src]

Returns the median of the discrete uniform distribution

Formula

(max + min) / 2

impl Median<f64> for Exp[src]

fn median(&self) -> f64[src]

Returns the median of the exponential distribution

Formula

(1 / λ) * ln2

where λ is the rate

impl Median<f64> for Geometric[src]

fn median(&self) -> f64[src]

Returns the median of the geometric distribution

Remarks

Formula

ceil(-1 / log_2(1 - p))

impl Median<f64> for Laplace[src]

fn median(&self) -> f64[src]

Returns the median of the laplace distribution

Formula

μ

where μ is the location

impl Median<f64> for LogNormal[src]

fn median(&self) -> f64[src]

Returns the median of the log-normal distribution

Formula

e^μ

where μ is the location

impl Median<f64> for Normal[src]

fn median(&self) -> f64[src]

Returns the median of the normal distribution

Formula

μ

where μ is the mean

impl Median<f64> for Pareto[src]

fn median(&self) -> f64[src]

Returns the median of the Pareto distribution

Formula

x_m*2^(1/α)

where x_m is the scale and α is the shape

impl Median<f64> for Poisson[src]

fn median(&self) -> f64[src]

Returns the median of the poisson distribution

Formula

floor(λ + 1 / 3 - 0.02 / λ)

where λ is the rate

impl Median<f64> for StudentsT[src]

fn median(&self) -> f64[src]

Returns the median of the student’s t-distribution

Formula

μ

where μ is the location

impl Median<f64> for Triangular[src]

fn median(&self) -> f64[src]

Returns the median of the triangular distribution

Formula

if mode >= (min + max) / 2 {
    min + sqrt((max - min) * (mode - min) / 2)
} else {
    max - sqrt((max - min) * (max - mode) / 2)
}

impl Median<f64> for Uniform[src]

fn median(&self) -> f64[src]

Returns the median for the continuous uniform distribution

Formula

(min + max) / 2

impl Median<f64> for Weibull[src]

fn median(&self) -> f64[src]

Returns the median of the weibull distribution

Formula

λ(ln(2))^(1 / k)

where k is the shape and λ is the scale

impl<D: AsMut<[f64]> + AsRef<[f64]> + Clone> Median<f64> for Data<D>[src]

fn median(&self) -> f64[src]

Returns the median value from the data

Remarks

Returns f64::NAN if data is empty

Examples

use statrs::statistics::Median;
use statrs::statistics::Data;

let x = [];
let x = Data::new(x);
assert!(x.median().is_nan());

let y = [0.0, 3.0, -2.0];
let y = Data::new(y);
assert_eq!(y.median(), 0.0);