# [−][src]Struct statrs::distribution::Chi

`pub struct Chi { /* fields omitted */ }`

Implements the Chi distribution

# Examples

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

let n = Chi::new(2.0).unwrap();
assert!(prec::almost_eq(n.mean(), 1.25331413731550025121, 1e-14));
assert!(prec::almost_eq(n.pdf(1.0), 0.60653065971263342360, 1e-15));```

## Methods

### `impl Chi`[src]

#### `pub fn new(freedom: f64) -> Result<Chi>`[src]

Constructs a new chi distribution with `freedom` degrees of freedom

# Errors

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

# Examples

```use statrs::distribution::Chi;

let mut result = Chi::new(2.0);
assert!(result.is_ok());

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

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

Returns the degrees of freedom of the chi distribution.

# Examples

```use statrs::distribution::Chi;

let n = Chi::new(2.0).unwrap();
assert_eq!(n.freedom(), 2.0);```

## Trait Implementations

### `impl Univariate<f64, f64> for Chi`[src]

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

Calculates the cumulative distribution function for the chi distribution at `x`.

# Formula

`P(k / 2, x^2 / 2)`

where `k` is the degrees of freedom and `P` is the regularized Gamma function

### `impl Continuous<f64, f64> for Chi`[src]

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

Calculates the probability density function for the chi distribution at `x`

# Formula

`(2^(1 - (k / 2)) * x^(k - 1) * e^(-x^2 / 2)) / Γ(k / 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 distribution at `x`

# Formula

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

### `impl Min<f64> for Chi`[src]

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

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

# Formula

`0`

### `impl Max<f64> for Chi`[src]

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

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

# Formula

`INF`

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

`sqrt2 * Γ((k + 1) / 2) / Γ(k / 2)`

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

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

`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

`sqrt(k - μ^2)`

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

### `impl Entropy<f64> for Chi`[src]

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

Returns the entropy of the chi distribution

# Remarks

Returns `NaN` if `freedom` is `INF`

# Formula

`ln(Γ(k / 2)) + 0.5 * (k - ln2 - (k - 1) * ψ(k / 2))`

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

### `impl Skewness<f64> for Chi`[src]

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

Returns the skewness of the chi distribution

# Remarks

Returns `NaN` if `freedom` is `INF`

# Formula

`(μ / σ^3) * (1 - 2σ^2)`

where `μ` is the mean and `σ` the standard deviation of the distribution

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

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

Returns the mode for the chi distribution

# Panics

If `freedom < 1.0`

# Formula

`sqrt(k - 1)`

where `k` is the degrees of freedom

### `impl CheckedMode<f64> for Chi`[src]

#### `fn checked_mode(&self) -> Result<f64>`[src]

Returns the mode for the chi distribution

# Errors

If `freedom < 1.0`

# Formula

`sqrt(k - 1)`

where `k` is the degrees of freedom

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

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

Performs copy-assignment from `source`. Read more

### `impl Distribution<f64> for Chi`[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.