pub trait Median<T> {
fn median(&self) -> T;
}
Expand description
The Median
trait returns the median of the distribution.
Expand description
Returns the median.
use statrs::statistics::Median;
use statrs::distribution::Uniform;
let n = Uniform::new(0.0, 1.0).unwrap();
assert_eq!(0.5, n.median());
Returns the median of the bernoulli
distribution
if p < 0.5 { 0 }
else if p > 0.5 { 1 }
else { 0.5 }
Returns the median of the binomial distribution
Returns the median of the categorical distribution
Returns the median of the cauchy distribution
where x_0
is the location
Returns the median of the chi-squared distribution
Returns the median of the dirac distribution
where v
is the point of the dirac distribution
Returns the median of the discrete uniform distribution
Returns the median of the exponential distribution
where λ
is the rate
Returns the median of the geometric distribution
Returns the median of the laplace distribution
where μ
is the location
Returns the median of the log-normal distribution
where μ
is the location
Returns the median of the normal distribution
where μ
is the mean
Returns the median of the Pareto distribution
where x_m
is the scale and α
is the shape
Returns the median of the poisson distribution
floor(λ + 1 / 3 - 0.02 / λ)
where λ
is the rate
Returns the median of the student’s t-distribution
where μ
is the location
Returns the median of the triangular distribution
if mode >= (min + max) / 2 {
min + sqrt((max - min) * (mode - min) / 2)
} else {
max - sqrt((max - min) * (max - mode) / 2)
}
Returns the median for the continuous uniform distribution
Returns the median of the weibull distribution
where k
is the shape and λ
is the scale
Returns the median value from the data
Returns f64::NAN
if data is empty
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);