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

Methods

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

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

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

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

Formats the value using the given formatter.

impl Copy for Gamma
[src]

impl Clone for Gamma
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Gamma
[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 Gamma
[src]

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

impl IndependentSample<f64> for Gamma
[src]

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

impl Distribution<f64> for Gamma
[src]

Generate a random sample from a gamma distribution using r as the source of randomness. The implementation is based on:

"A Simple Method for Generating Gamma Variables" - Marsaglia & Tsang
ACM Transactions on Mathematical Software, Vol. 26, No. 3, September 2000, Pages 363-372

Examples

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

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

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

Calculates the cumulative distribution function for the gamma distribution at x

Panics

If x <= 0.0

Formula

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

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

impl Min<f64> for Gamma
[src]

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

Formula

0

impl Max<f64> for Gamma
[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]

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 Variance<f64> for Gamma
[src]

Returns the variance of the gamma distribution

Formula

α / β^2

where α is the shape and β is the rate

Returns the standard deviation of the gamma distribution

Formula

sqrt(α) / β

where α is the shape and β is the rate

impl Entropy<f64> for Gamma
[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 Skewness<f64> for Gamma
[src]

Returns the skewness of the gamma distribution

Formula

2 / sqrt(α)

where α is the shape

impl Mode<f64> for Gamma
[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 Continuous<f64, f64> for Gamma
[src]

Calculates the probability density function for the gamma distribution at x

Panics

If x <= 0.0

Remarks

Returns f64::INFINITY if x == shape && rate == f64::INFINITY Otherwise returns 0.0 if rate == f64::INFINITY

Formula

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

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

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

Panics

If x <= 0.0

Remarks

Returns f64::INFINITY if x == shape && rate == f64::INFINITY Otherwise returns f64::NEG_INFINITY if rate == f64::INFINITY

Formula

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

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