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

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

The Median trait specifies than an object has a closed form solution for its median

Required methods

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

Returns the median. May panic depending on the implementor.

Examples

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

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

Implementations on Foreign Types

impl Median<f64> for [f64][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;

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

let y = [0.0, 3.0, -2.0];
assert_eq!(y.median(), 0.0);
Loading content...

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 DiscreteUniform[src]

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

Returns the median of the discrete uniform distribution

Formula

(max + min) / 2

impl Median<f64> for Exponential[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

Returns 1 if p is 1

Formula

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

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

Loading content...