Struct statrs::distribution::Gamma[][src]

pub struct Gamma { /* fields omitted */ }

Implements the Gamma distribution

Examples

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

let n = Gamma::new(3.0, 1.0).unwrap();
assert_eq!(n.mean(), 3.0);
assert!(prec::almost_eq(n.pdf(2.0), 0.270670566473225383788, 1e-15));

Implementations

impl Gamma[src]

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

Constructs a new 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 <= 0.0 or rate <= 0.0

Examples

use statrs::distribution::Gamma;

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

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

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

Returns the shape (α) of the gamma distribution

Examples

use statrs::distribution::Gamma;

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

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

Returns the rate (β) of the gamma distribution

Examples

use statrs::distribution::Gamma;

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

Trait Implementations

impl Clone for Gamma[src]

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

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

Calculates the probability density function for the gamma distribution at x

Remarks

Returns NAN if any of shape or rate are INF or if x is INF

Formula

(β^α / Γ(α)) * 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 log probability density function for the gamma distribution at x

Remarks

Returns NAN if any of shape or rate are INF or if x is INF

Formula

ln((β^α / Γ(α)) * x^(α - 1) * e ^(-β * x))

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

impl Copy for Gamma[src]

impl Debug for Gamma[src]

impl Distribution<f64> for Gamma[src]

impl Entropy<f64> for Gamma[src]

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

Returns the entropy of the gamma distribution

Formula

α - ln(β) + ln(Γ(α)) + (1 - α) * ψ(α)

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

impl Max<f64> for Gamma[src]

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

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

Formula

INF

impl Mean<f64> for Gamma[src]

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

Returns the mean of the gamma distribution

Remarks

Returns shape if rate == f64::INFINITY. This behavior is borrowed from the Math.NET implementation

Formula

α / β

where α is the shape and β is the rate

impl Min<f64> for Gamma[src]

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

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

Formula

0

impl Mode<f64> for Gamma[src]

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

Returns the mode for the gamma distribution

Remarks

Returns shape if rate ==f64::INFINITY. This behavior is borrowed from the Math.NET implementation

Formula

(α - 1) / β

where α is the shape and β is the rate

impl PartialEq<Gamma> for Gamma[src]

impl Skewness<f64> for Gamma[src]

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

Returns the skewness of the gamma distribution

Formula

2 / sqrt(α)

where α is the shape

impl StructuralPartialEq for Gamma[src]

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

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

Calculates the cumulative distribution function for the gamma distribution at x

Formula

(1 / Γ(α)) * γ(α, β * x)

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

impl Variance<f64> for Gamma[src]

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

Returns the variance of the gamma distribution

Formula

α / β^2

where α is the shape and β is the rate

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

Returns the standard deviation of the gamma distribution

Formula

sqrt(α) / β

where α is the shape and β is the rate

Auto Trait Implementations

impl RefUnwindSafe for Gamma

impl Send for Gamma

impl Sync for Gamma

impl Unpin for Gamma

impl UnwindSafe for Gamma

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> 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>, 
[src]