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