[][src]Trait statrs::statistics::Mean

pub trait Mean<T> {
    fn mean(&self) -> T;
}

The Mean trait specifies that an object has a closed form solution for its mean(s)

Required methods

fn mean(&self) -> T

Returns the mean. May panic depending on the implementor.

Examples

use statrs::statistics::Mean;
use statrs::distribution::Uniform;

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

Implementations on Foreign Types

impl Mean<f64> for [f64][src]

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

Evaluates the sample mean, an estimate of the population mean.

Remarks

Returns f64::NAN if data is empty or an entry is f64::NAN

Examples

#[macro_use]
extern crate statrs;

use std::f64;
use statrs::statistics::Mean;

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

let y = [0.0, f64::NAN, 3.0, -2.0];
assert!(y.mean().is_nan());

let z = [0.0, 3.0, -2.0];
assert_almost_eq!(z.mean(), 1.0 / 3.0, 1e-15);
Loading content...

Implementors

impl Mean<f64> for Bernoulli[src]

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

Returns the mean of the bernoulli distribution

Formula

This example is not tested
p

impl Mean<f64> for Beta[src]

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

Returns the mean of the beta distribution

Formula

This example is not tested
α / (α + β)

where α is shapeA and β is shapeB

impl Mean<f64> for Binomial[src]

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

Returns the mean of the binomial distribution

Formula

This example is not tested
p * n

impl Mean<f64> for Categorical[src]

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

Returns the mean of the categorical distribution

Formula

This example is not tested
Σ(j * p_j)

where p_j is the jth probability mass, Σ is the sum from 0 to k - 1, and k is the number of categories

impl Mean<f64> for Chi[src]

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

Returns the mean of the chi distribution

Remarks

Returns NaN if freedom is INF

Formula

This example is not tested
sqrt2 * Γ((k + 1) / 2) / Γ(k / 2)

where k is degrees of freedom and Γ is the gamma function

impl Mean<f64> for ChiSquared[src]

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

Returns the mean of the chi-squared distribution

Formula

This example is not tested
k

where k is the degrees of freedom

impl Mean<f64> for DiscreteUniform[src]

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

Returns the mean of the discrete uniform distribution

Formula

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

impl Mean<f64> for Erlang[src]

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

Returns the mean of the erlang distribution

Remarks

Returns shape if rate == f64::INFINITY. This behavior is borrowed from the Math.NET implementation

Formula

This example is not tested
k / λ

where k is the shape and λ is the rate

impl Mean<f64> for Exponential[src]

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

Returns the mean of the exponential distribution

Formula

This example is not tested
1 / λ

where λ is the rate

impl Mean<f64> for FisherSnedecor[src]

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

Returns the mean of the fisher-snedecor distribution

Panics

If freedom_2 <= 2.0

Remarks

Returns NaN if freedom_2 is INF

Formula

This example is not tested
d2 / (d2 - 2)

where d2 is the second degree of freedom

impl Mean<f64> for Gamma[src]

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

Returns the mean of the gamma distribution

Remarks

Returns shape if rate == f64::INFINITY. This behavior is borrowed from the Math.NET implementation

Formula

This example is not tested
α / β

where α is the shape and β is the rate

impl Mean<f64> for Geometric[src]

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

Returns the mean of the geometric distribution

Formula

This example is not tested
1 / p

impl Mean<f64> for Hypergeometric[src]

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

Returns the mean of the hypergeometric distribution

Panics

If N is 0

Formula

This example is not tested
K * n / N

where N is population, K is successes, and n is draws

impl Mean<f64> for InverseGamma[src]

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

Returns the mean of the inverse distribution

Panics

If shape <= 1.0

Formula

This example is not tested
β / (α - 1)

where α is the shape and β is the rate

impl Mean<f64> for LogNormal[src]

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

Returns the mean of the log-normal distribution

Formula

This example is not tested
e^(μ + σ^2 / 2)

where μ is the location and σ is the scale

impl Mean<f64> for Normal[src]

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

Returns the mean of the normal distribution

Remarks

This is the same mean used to construct the distribution

impl Mean<f64> for Pareto[src]

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

Returns the mean of the Pareto distribution

Formula

This example is not tested
if α <= 1 {
    INF
} else {
    (α * x_m)/(α - 1)
}

where x_m is the scale and α is the shape

impl Mean<f64> for Poisson[src]

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

Returns the mean of the poisson distribution

Formula

This example is not tested
λ

where λ is the rate

impl Mean<f64> for StudentsT[src]

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

Returns the mean of the student's t-distribution

Panics

If freedom <= 1.0

Formula

This example is not tested
μ

where μ is the location

impl Mean<f64> for Triangular[src]

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

Returns the mean of the triangular distribution

Formula

This example is not tested
(min + max + mode) / 3

impl Mean<f64> for Uniform[src]

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

Returns the mean for the continuous uniform distribution

Formula

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

impl Mean<f64> for Weibull[src]

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

Returns the mean of the weibull distribution

Formula

This example is not tested
λΓ(1 + 1 / k)

where k is the shape, λ is the scale, and Γ is the gamma function

impl Mean<Vec<f64>> for Dirichlet[src]

fn mean(&self) -> Vec<f64>[src]

Returns the means of the dirichlet distribution

Formula

This example is not tested
α_i / α_0

for the ith element where α_i is the ith concentration parameter and α_0 is the sum of all concentration parameters

impl Mean<Vec<f64>> for Multinomial[src]

fn mean(&self) -> Vec<f64>[src]

Returns the mean of the multinomial distribution

Formula

This example is not tested
n * p_i for i in 1...k

where n is the number of trials, p_i is the ith probability, and k is the total number of probabilities

Loading content...