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

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));

Methods

impl 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());

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);

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);

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

Formats the value using the given formatter.

impl Copy for ChiSquared
[src]

impl Clone for ChiSquared
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for ChiSquared
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Sample<f64> for ChiSquared
[src]

Generate a random sample from a chi-squared distribution using r as the source of randomness. Refer here for implementation details

impl IndependentSample<f64> for ChiSquared
[src]

Generate a random independent sample from a Chi distribution using r as the source of randomness. Refer here for implementation details

impl Distribution<f64> for ChiSquared
[src]

Generate a random sample from the chi-squared distribution using r as the source of randomness

Examples

use rand::StdRng;
use statrs::distribution::{ChiSquared, Distribution};

let mut r = rand::StdRng::new().unwrap();
let n = ChiSquared::new(3.0).unwrap();
print!("{}", n.sample::<StdRng>(&mut r));

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

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

Panics

If x < 0.0

Formula

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

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

Formula

0

impl Max<f64> for ChiSquared
[src]

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

Formula

INF

impl Mean<f64> for ChiSquared
[src]

Returns the mean of the chi-squared distribution

Formula

k

where k is the degrees of freedom

impl Variance<f64> for ChiSquared
[src]

Returns the variance of the chi-squared distribution

Formula

2k

where k is the degrees of freedom

Returns the standard deviation of the chi-squared distribution

Formula

sqrt(2k)

where k is the degrees of freedom

impl Entropy<f64> for ChiSquared
[src]

Returns the entropy of the chi-squared distribution

Formula

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

Returns the skewness of the chi-squared distribution

Formula

sqrt(8 / k)

where k is the degrees of freedom

impl Median<f64> for ChiSquared
[src]

Returns the median of the chi-squared distribution

Formula

k * (1 - (2 / 9k))^3

impl Mode<f64> for ChiSquared
[src]

Returns the mode of the chi-squared distribution

Formula

k - 2

where k is the degrees of freedom

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

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

Panics

If x < 0.0

Formula

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

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

Panics

If x < 0.0

Formula

ln(1 / (2^(k / 2) * Γ(k / 2)) * x^((k / 2) - 1) * e^(-x / 2))