# [−][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));```

## Methods

### `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 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

`(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 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

`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

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

### `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

`0`

### `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

`INF`

### `impl Mean<f64> for ChiSquared`[src]

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

Returns the mean of the chi-squared distribution

# Formula

`k`

where `k` is the degrees of freedom

### `impl Variance<f64> for ChiSquared`[src]

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

Returns the variance of the chi-squared distribution

# Formula

`2k`

where `k` is the degrees of freedom

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

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]

#### `fn entropy(&self) -> f64`[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]

#### `fn skewness(&self) -> f64`[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]

#### `fn median(&self) -> f64`[src]

Returns the median of the chi-squared distribution

# Formula

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

### `impl Mode<f64> for ChiSquared`[src]

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

Returns the mode of the chi-squared distribution

# Formula

`k - 2`

where `k` is the degrees of freedom

### `impl Clone for ChiSquared`[src]

#### `fn clone_from(&mut self, source: &Self)`1.0.0[src]

Performs copy-assignment from `source`. Read more

### `impl Distribution<f64> for ChiSquared`[src]

#### `fn sample_iter<R>(&'a self, rng: &'a mut R) -> DistIter<'a, Self, R, T> where    R: Rng, `[src]

Create an iterator that generates random values of `T`, using `rng` as the source of randomness. Read more

## Blanket Implementations

### `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.