[][src]Struct statrs::distribution::ChiSquared

pub struct ChiSquared { /* fields omitted */ }

Implements the Chi-squared distribution which is a special case of the Gamma distribution (referenced Here)

Examples

use statrs::distribution::{ChiSquared, Continuous};
use statrs::statistics::Mean;
use statrs::prec;

let n = ChiSquared::new(3.0).unwrap();
assert_eq!(n.mean(), 3.0);
assert!(prec::almost_eq(n.pdf(4.0), 0.107981933026376103901, 1e-15));

Implementations

impl ChiSquared[src]

pub fn new(freedom: f64) -> Result<ChiSquared>[src]

Constructs a new chi-squared distribution with freedom degrees of freedom. This is equivalent to a Gamma distribution with a shape of freedom / 2.0 and a rate of 0.5.

Errors

Returns an error if freedom is NaN or less than or equal to 0.0

Examples

use statrs::distribution::ChiSquared;

let mut result = ChiSquared::new(3.0);
assert!(result.is_ok());

result = ChiSquared::new(0.0);
assert!(result.is_err());

pub fn freedom(&self) -> f64[src]

Returns the degrees of freedom of the chi-squared distribution

Examples

use statrs::distribution::ChiSquared;

let n = ChiSquared::new(3.0).unwrap();
assert_eq!(n.freedom(), 3.0);

pub fn shape(&self) -> f64[src]

Returns the shape of the underlying Gamma distribution

Examples

use statrs::distribution::ChiSquared;

let n = ChiSquared::new(3.0).unwrap();
assert_eq!(n.shape(), 3.0 / 2.0);

pub fn rate(&self) -> f64[src]

Returns the rate of the underlying Gamma distribution

Examples

use statrs::distribution::ChiSquared;

let n = ChiSquared::new(3.0).unwrap();
assert_eq!(n.rate(), 0.5);

Trait Implementations

impl Clone for ChiSquared[src]

impl Continuous<f64, f64> for ChiSquared[src]

fn pdf(&self, x: f64) -> f64[src]

Calculates the probability density function for the chi-squared distribution at x

Formula

This example is not tested
1 / (2^(k / 2) * Γ(k / 2)) * x^((k / 2) - 1) * e^(-x / 2)

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

fn ln_pdf(&self, x: f64) -> f64[src]

Calculates the log probability density function for the chi-squared distribution at x

Formula

This example is not tested
ln(1 / (2^(k / 2) * Γ(k / 2)) * x^((k / 2) - 1) * e^(-x / 2))

impl Copy for ChiSquared[src]

impl Debug for ChiSquared[src]

impl Distribution<f64> for ChiSquared[src]

impl Entropy<f64> for ChiSquared[src]

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

Returns the entropy of the chi-squared distribution

Formula

This example is not tested
(k / 2) + ln(2 * Γ(k / 2)) + (1 - (k / 2)) * ψ(k / 2)

where k is the degrees of freedom, Γ is the gamma function, and ψ is the digamma function

impl Max<f64> for ChiSquared[src]

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

Returns the maximum value in the domain of the chi-squared distribution representable by a double precision float

Formula

This example is not tested
INF

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 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 Min<f64> for ChiSquared[src]

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

Returns the minimum value in the domain of the chi-squared distribution representable by a double precision float

Formula

This example is not tested
0

impl Mode<f64> for ChiSquared[src]

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

Returns the mode of the chi-squared distribution

Formula

This example is not tested
k - 2

where k is the degrees of freedom

impl PartialEq<ChiSquared> for ChiSquared[src]

impl Skewness<f64> for ChiSquared[src]

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

Returns the skewness of the chi-squared distribution

Formula

This example is not tested
sqrt(8 / k)

where k is the degrees of freedom

impl StructuralPartialEq for ChiSquared[src]

impl Univariate<f64, f64> for ChiSquared[src]

fn cdf(&self, x: f64) -> f64[src]

Calculates the cumulative distribution function for the chi-squared distribution at x

Formula

This example is not tested
(1 / Γ(k / 2)) * γ(k / 2, x / 2)

where k is the degrees of freedom, Γ is the gamma function, and γ is the lower incomplete gamma function

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

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Scalar for T where
    T: PartialEq<T> + Copy + Any + Debug
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,