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

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

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

This example is not tested
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

This example is not tested
floor(n * p)

impl Median<f64> for Categorical[src]

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

Returns the median of the categorical distribution

Formula

This example is not tested
CDF^-1(0.5)

impl Median<f64> for Cauchy[src]

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

Returns the median of the cauchy distribution

Formula

This example is not tested
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

This example is not tested
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

This example is not tested
(max + min) / 2

impl Median<f64> for Exponential[src]

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

Returns the median of the exponential distribution

Formula

This example is not tested
(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

This example is not tested
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

This example is not tested
e^μ

where μ is the location

impl Median<f64> for Normal[src]

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

Returns the median of the normal distribution

Formula

This example is not tested
μ

where μ is the mean

impl Median<f64> for Pareto[src]

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

Returns the median of the Pareto distribution

Formula

This example is not tested
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

This example is not tested
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

This example is not tested
μ

where μ is the location

impl Median<f64> for Triangular[src]

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

Returns the median of the triangular distribution

Formula

This example is not tested
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

This example is not tested
(min + max) / 2

impl Median<f64> for Weibull[src]

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

Returns the median of the weibull distribution

Formula

This example is not tested
λ(ln(2))^(1 / k)

where k is the shape and λ is the scale

Loading content...