[][src]Trait statrs::statistics::Variance

pub trait Variance<T>: Mean<T> {
    fn variance(&self) -> T;
fn std_dev(&self) -> T; }

The Variance trait specifies that an object has a closed form solution for its variance(s). Requires Mean since a closed form solution to variance by definition requires a closed form mean.

Required methods

fn variance(&self) -> T

Returns the variance. May panic depending on the implementor.

Examples

use statrs::statistics::Variance;
use statrs::distribution::Uniform;

let n = Uniform::new(0.0, 1.0).unwrap();
assert_eq!(1.0 / 12.0, n.variance());

fn std_dev(&self) -> T

Returns the standard deviation. May panic depending on the implementor.

Examples

use statrs::statistics::Variance;
use statrs::distribution::Uniform;

let n = Uniform::new(0.0, 1.0).unwrap();
assert_eq!((1f64 / 12f64).sqrt(), n.std_dev());
Loading content...

Implementations on Foreign Types

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

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

Estimates the unbiased population variance from the provided samples

Remarks

On a dataset of size N, N-1 is used as a normalizer (Bessel's correction).

Returns f64::NAN if data has less than two entries or if any entry is f64::NAN

Examples

use std::f64;
use statrs::statistics::Variance;

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

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

let z = [0.0, 3.0, -2.0];
assert_eq!(z.variance(), 19.0 / 3.0);

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

Estimates the unbiased population standard deviation from the provided samples

Remarks

On a dataset of size N, N-1 is used as a normalizer (Bessel's correction).

Returns f64::NAN if data has less than two entries or if any entry is f64::NAN

Examples

use std::f64;
use statrs::statistics::Variance;

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

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

let z = [0.0, 3.0, -2.0];
assert_eq!(z.std_dev(), (19f64 / 3.0).sqrt());
Loading content...

Implementors

impl Variance<f64> for Bernoulli[src]

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

Returns the variance of the bernoulli distribution

Formula

This example is not tested
p * (1 - p)

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

Returns the standard deviation of the bernoulli distribution

Formula

This example is not tested
sqrt(p * (1 - p))

impl Variance<f64> for Beta[src]

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

Returns the variance of the beta distribution

Remarks

Returns f64::NAN if either shape_a or shape_b are positive infinity

Formula

This example is not tested
(α * β) / ((α + β)^2 * (α + β + 1))

where α is shapeA and β is shapeB

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

Returns the standard deviation of the beta distribution

Remarks

Returns f64::NAN if either shape_a or shape_b are positive infinity

Formula

This example is not tested
sqrt((α * β) / ((α + β)^2 * (α + β + 1)))

where α is shapeA and β is shapeB

impl Variance<f64> for Binomial[src]

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

Returns the variance of the binomial distribution

Formula

This example is not tested
n * p * (1 - p)

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

Returns the standard deviation of the binomial distribution

Formula

This example is not tested
sqrt(n * p * (1 - p))

impl Variance<f64> for Categorical[src]

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

Returns the variance of the categorical distribution

Formula

This example is not tested
Σ(p_j * (j - μ)^2)

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

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

Returns the standard deviation of the categorical distribution

Formula

This example is not tested
sqrt(Σ(p_j * (j - μ)^2))

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

impl Variance<f64> for Chi[src]

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

Returns the variance of the chi distribution

Remarks

Returns NaN if freedom is INF

Formula

This example is not tested
k - μ^2

where k is degrees of freedom and μ is the mean of the distribution

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

Returns the standard deviation of the chi distribution

Remarks

Returns NaN if freedom is INF

Formula

This example is not tested
sqrt(k - μ^2)

where k is degrees of freedom and μ is the mean of the distribution

impl Variance<f64> for ChiSquared[src]

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

Returns the variance of the chi-squared distribution

Formula

This example is not tested
2k

where k is the degrees of freedom

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

Returns the standard deviation of the chi-squared distribution

Formula

This example is not tested
sqrt(2k)

where k is the degrees of freedom

impl Variance<f64> for DiscreteUniform[src]

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

Returns the variance of the discrete uniform distribution

Formula

This example is not tested
((max - min + 1)^2 - 1) / 12

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

Returns the standard deviation of the discrete uniform distribution

Formula

This example is not tested
sqrt(((max - min + 1)^2 - 1) / 12)

impl Variance<f64> for Erlang[src]

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

Returns the variance of the erlang distribution

Formula

This example is not tested
k / λ^2

where α is the shape and λ is the rate

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

Returns the standard deviation of the erlang distribution

Formula

This example is not tested
sqrt(k) / λ

where k is the shape and λ is the rate

impl Variance<f64> for Exponential[src]

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

Returns the variance of the exponential distribution

Formula

This example is not tested
1 / λ^2

where λ is the rate

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

Returns the standard deviation of the exponential distribution

Formula

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

where λ is the rate

impl Variance<f64> for FisherSnedecor[src]

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

Returns the variance of the fisher-snedecor distribution

Panics

If freedom_2 <= 4.0

Remarks

Returns NaN if freedom_1 or freedom_2 is INF

Formula

This example is not tested
(2 * d2^2 * (d1 + d2 - 2)) / (d1 * (d2 - 2)^2 * (d2 - 4))

where d1 is the first degree of freedom and d2 is the second degree of freedom

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

Returns the standard deviation of the fisher-snedecor distribution

Panics

If freedom_2 <= 4.0

Remarks

Returns NaN if freedom_1 or freedom_2 is INF

Formula

This example is not tested
sqrt((2 * d2^2 * (d1 + d2 - 2)) / (d1 * (d2 - 2)^2 * (d2 - 4)))

where d1 is the first degree of freedom and d2 is the second degree of freedom

impl Variance<f64> for Gamma[src]

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

Returns the variance of the gamma distribution

Formula

This example is not tested
α / β^2

where α is the shape and β is the rate

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

Returns the standard deviation of the gamma distribution

Formula

This example is not tested
sqrt(α) / β

where α is the shape and β is the rate

impl Variance<f64> for Geometric[src]

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

Returns the standard deviation of the geometric distribution

Formula

This example is not tested
(1 - p) / p^2

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

Returns the standard deviation of the geometric distribution

Remarks

Returns NAN if p is 1

Formula

This example is not tested
sqrt(1 - p) / p

impl Variance<f64> for Hypergeometric[src]

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

Returns the variance of the hypergeometric distribution

Panics

If N <= 1

Formula

This example is not tested
n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1))

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

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

Returns the standard deviation of the hypergeometric distribution

Panics

If N <= 1

Formula

This example is not tested
sqrt(n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1)))

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

impl Variance<f64> for InverseGamma[src]

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

Returns the variance of the inverse gamma distribution

Panics

If shape <= 2.0

Formula

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

where α is the shape and β is the rate

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

Returns the standard deviation of the inverse gamma distribution

Panics

If shape <= 2.0

Formula

This example is not tested
sqrt(β^2 / ((α - 1)^2 * (α - 2)))

where α is the shape and β is the rate

impl Variance<f64> for LogNormal[src]

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

Returns the variance of the log-normal distribution

Formula

This example is not tested
(e^(σ^2) - 1) * e^( + σ^2)

where μ is the location and σ is the scale

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

Returns the standard deviation of the log-normal distribution

Formula

This example is not tested
sqrt((e^(σ^2) - 1) * e^( + σ^2))

where μ is the location and σ is the scale

impl Variance<f64> for Normal[src]

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

Returns the variance of the normal distribution

Formula

This example is not tested
σ^2

where σ is the standard deviation

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

Returns the standard deviation of the normal distribution

Remarks

This is the same standard deviation used to construct the distribution

impl Variance<f64> for Pareto[src]

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

Returns the variance of the Pareto distribution

Formula

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

where x_m is the scale and α is the shape

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

Returns the standard deviation of the Pareto distribution

Formula

This example is not tested
let variance = if α <= 2 {
    INF
} else {
    (x_m/(α - 1))^2 * (α/(α - 2))
};
sqrt(variance)

where x_m is the scale and α is the shape

impl Variance<f64> for Poisson[src]

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

Returns the variance of the poisson distribution

Formula

This example is not tested
λ

where λ is the rate

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

Returns the standard deviation of the poisson distribution

Formula

This example is not tested
sqrt(λ)

where λ is the rate

impl Variance<f64> for StudentsT[src]

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

Returns the variance of the student's t-distribution

Panics

If freedom <= 1.0

Formula

This example is not tested
if v == INF {
    σ^2
} else if freedom > 2.0 {
    v * σ^2 / (v - 2)
} else {
    INF
}

where σ is the scale and v is the freedom

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

Returns the standard deviation of the student's t-distribution

Panics

If freedom <= 1.0

Formula

This example is not tested
let variance = if v == INF {
    σ^2
} else if freedom > 2.0 {
    v * σ^2 / (v - 2)
} else {
    INF
}
sqrt(variance)

where σ is the scale and v is the freedom

impl Variance<f64> for Triangular[src]

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

Returns the variance of the triangular distribution

Formula

This example is not tested
(min^2 + max^2 + mode^2 - min * max - min * mode - max * mode) / 18

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

Returns the standard deviation of the triangular distribution

Formula

This example is not tested
sqrt((min^2 + max^2 + mode^2 - min * max - min * mode - max * mode) /
18)

impl Variance<f64> for Uniform[src]

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

Returns the variance for the continuous uniform distribution

Formula

This example is not tested
(max - min)^2 / 12

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

Returns the standard deviation for the continuous uniform distribution

Formula

This example is not tested
sqrt((max - min)^2 / 12)

impl Variance<f64> for Weibull[src]

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

Returns the variance of the weibull distribution

Formula

This example is not tested
λ^2 * (Γ(1 + 2 / k) - Γ(1 + 1 / k)^2)

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

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

Returns the standard deviation of the weibull distribution

Formula

This example is not tested
sqrt(λ^2 * (Γ(1 + 2 / k) - Γ(1 + 1 / k)^2))

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

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

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

Returns the variances of the dirichlet distribution

Formula

This example is not tested
(α_i * (α_0 - α_i)) / (α_0^2 * (α_0 + 1))

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

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

Returns the standard deviation of the dirichlet distribution

Formula

This example is not tested
sqrt((α_i * (α_0 - α_i)) / (α_0^2 * (α_0 + 1)))

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

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

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

Returns the variance of the multinomial distribution

Formula

This example is not tested
n * p_i * (1 - p_1) 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

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

Returns the standard deviation of the multinomial distribution

Formula

This example is not tested
sqrt(n * p_i * (1 - p_1)) 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...