[][src]Struct statrs::distribution::InverseGamma

pub struct InverseGamma { /* fields omitted */ }

Implements the Inverse Gamma distribution

Examples

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

let n = InverseGamma::new(1.1, 0.1).unwrap();
assert!(prec::almost_eq(n.mean(), 1.0, 1e-14));
assert_eq!(n.pdf(1.0), 0.07554920138253064);

Methods

impl InverseGamma[src]

pub fn new(shape: f64, rate: f64) -> Result<InverseGamma>[src]

Constructs a new inverse gamma distribution with a shape (α) of shape and a rate (β) of rate

Errors

Returns an error if shape or rate are NaN. Also returns an error if shape or rate are not in (0, +inf)

Examples

use statrs::distribution::InverseGamma;

let mut result = InverseGamma::new(3.0, 1.0);
assert!(result.is_ok());

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

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

Returns the shape (α) of the inverse gamma distribution

Examples

use statrs::distribution::InverseGamma;

let n = InverseGamma::new(3.0, 1.0).unwrap();
assert_eq!(n.shape(), 3.0);

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

Returns the rate (β) of the inverse gamma distribution

Examples

use statrs::distribution::InverseGamma;

let n = InverseGamma::new(3.0, 1.0).unwrap();
assert_eq!(n.rate(), 1.0);

Trait Implementations

impl Distribution<f64> for InverseGamma[src]

fn sample<R: Rng>(&self, r: &mut R) -> f64[src]

Generate a random sample from an inverse gamma distribution using r as the source of randomness.

Examples

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

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

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

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

Calculates the cumulative distribution function for the inverse gamma distribution at x

Formula

This example is not tested
Γ(α, β / x) / Γ(α)

where the numerator is the upper incomplete gamma function, the denominator is the gamma function, α is the shape, and β is the rate

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

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

Calculates the probability density function for the inverse gamma distribution at x

Formula

This example is not tested
(β^α / Γ(α)) * x^(-α - 1) * e^(-β / x)

where α is the shape, β is the rate, and Γ is the gamma function

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

Calculates the probability density function for the inverse gamma distribution at x

Formula

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

where α is the shape, β is the rate, and Γ is the gamma function

impl Min<f64> for InverseGamma[src]

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

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

Formula

This example is not tested
0

impl Max<f64> for InverseGamma[src]

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

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

Formula

This example is not tested
INF

impl Mean<f64> for InverseGamma[src]

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

Returns the mean of the inverse distribution

Panics

If shape <= 1.0

Formula

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

where α is the shape and β is the rate

impl CheckedMean<f64> for InverseGamma[src]

fn checked_mean(&self) -> Result<f64>[src]

Returns the mean of the inverse distribution

Errors

If shape <= 1.0

Formula

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

where α is the shape and β is the rate

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 CheckedVariance<f64> for InverseGamma[src]

fn checked_variance(&self) -> Result<f64>[src]

Returns the variance of the inverse gamma distribution

Errors

If shape <= 2.0

Formula

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

where α is the shape and β is the rate

fn checked_std_dev(&self) -> Result<f64>[src]

Returns the standard deviation of the inverse gamma distribution

Errors

If shape <= 2.0

Formula

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

where α is the shape and β is the rate

impl Entropy<f64> for InverseGamma[src]

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

Returns the entropy of the inverse gamma distribution

Formula

This example is not tested
α + ln(β * Γ(α)) - (1 + α) * ψ(α)

where α is the shape, β is the rate, Γ is the gamma function, and ψ is the digamma function

impl Skewness<f64> for InverseGamma[src]

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

Returns the skewness of the inverse gamma distribution

Panics

If shape <= 3

Formula

This example is not tested
4 * sqrt(α - 2) / (α - 3)

where α is the shape

impl CheckedSkewness<f64> for InverseGamma[src]

fn checked_skewness(&self) -> Result<f64>[src]

Returns the skewness of the inverse gamma distribution

Errors

If shape <= 3

Formula

This example is not tested
4 * sqrt(α - 2) / (α - 3)

where α is the shape

impl Mode<f64> for InverseGamma[src]

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

Returns the mode of the inverse gamma distribution

Formula

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

/// where α is the shape and β is the rate

impl Copy for InverseGamma[src]

impl Clone for InverseGamma[src]

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

Performs copy-assignment from source. Read more

impl PartialEq<InverseGamma> for InverseGamma[src]

impl Debug for InverseGamma[src]

impl IndependentSample<f64> for InverseGamma[src]

fn ind_sample<R: Rng>(&self, r: &mut R) -> f64[src]

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

impl Sample<f64> for InverseGamma[src]

fn sample<R: Rng>(&mut self, r: &mut R) -> f64[src]

Generate a random sample from an inverse gamma distribution using r as the source of randomness. Refer here for implementation details

Auto Trait Implementations

impl Send for InverseGamma

impl Unpin for InverseGamma

impl Sync for InverseGamma

impl UnwindSafe for InverseGamma

impl RefUnwindSafe for InverseGamma

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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