[][src]Struct statrs::distribution::Beta

pub struct Beta { /* fields omitted */ }

Implements the Beta distribution

Examples

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

let n = Beta::new(2.0, 2.0).unwrap();
assert_eq!(n.mean(), 0.5);
assert!(prec::almost_eq(n.pdf(0.5), 1.5, 1e-14));

Methods

impl Beta[src]

pub fn new(shape_a: f64, shape_b: f64) -> Result<Beta>[src]

Constructs a new beta distribution with shapeA (α) of shape_a and shapeB (β) of shape_b

Errors

Returns an error if shape_a or shape_b are NaN. Also returns an error if shape_a <= 0.0 or shape_b <= 0.0

Examples

use statrs::distribution::Beta;

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

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

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

Returns the shapeA (α) of the beta distribution

Examples

use statrs::distribution::Beta;

let n = Beta::new(2.0, 2.0).unwrap();
assert_eq!(n.shape_a(), 2.0);

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

Returns the shapeB (β) of the beta distributionβ

Examples

use statrs::distribution::Beta;

let n = Beta::new(2.0, 2.0).unwrap();
assert_eq!(n.shape_b(), 2.0);

Trait Implementations

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

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

Calculates the cumulative distribution function for the beta distribution at x

Formula

This example is not tested
I_x(α, β)

where α is shapeA, β is shapeB, and I_x is the regularized lower incomplete beta function

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

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

Calculates the probability density function for the beta distribution at x.

Formula

This example is not tested
let B(α, β) = Γ(α)Γ(β)/Γ(α + β)

x^(α - 1) * (1 - x)^(β - 1) / B(α, β)

where α is shapeA, β is shapeB, and Γ is the gamma function

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

Calculates the log probability density function for the beta distribution at x.

Formula

This example is not tested
let B(α, β) = Γ(α)Γ(β)/Γ(α + β)

ln(x^(α - 1) * (1 - x)^(β - 1) / B(α, β))

where α is shapeA, β is shapeB, and Γ is the gamma function

impl Min<f64> for Beta[src]

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

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

Formula

This example is not tested
0

impl Max<f64> for Beta[src]

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

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

Formula

This example is not tested
1

impl Mean<f64> for Beta[src]

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

Returns the mean of the beta distribution

Formula

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

where α is shapeA and β is shapeB

impl Variance<f64> for Beta[src]

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

Returns the variance of the beta distribution

Remarks

Returns f64::NAN if either shape_a or shape_b are positive infinity

Formula

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

where α is shapeA and β is shapeB

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

Returns the standard deviation of the beta distribution

Remarks

Returns f64::NAN if either shape_a or shape_b are positive infinity

Formula

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

where α is shapeA and β is shapeB

impl Entropy<f64> for Beta[src]

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

Returns the entropy of the beta distribution

Formula

This example is not tested
ln(B(α, β)) - (α - 1)ψ(α) - (β - 1)ψ(β) + (α + β - 2)ψ(α + β)

where α is shapeA, β is shapeB and ψ is the digamma function

impl Skewness<f64> for Beta[src]

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

Returns the skewness of the Beta distribution

Formula

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

where α is shapeA and β is shapeB

impl Mode<f64> for Beta[src]

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

Returns the mode of the Beta distribution.

Remarks

Since the mode is technically only calculate for α > 1, β > 1, those are the only values we allow. We may consider relaxing this constraint in the future.

Panics

If α <= 1 or β <= 1

Formula

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

where α is shapeA and β is shapeB

impl CheckedMode<f64> for Beta[src]

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

Returns the mode of the Beta distribution.

Remarks

Since the mode is technically only calculate for α > 1, β > 1, those are the only values we allow. We may consider relaxing this constraint in the future.

Errors

If α <= 1 or β <= 1

Formula

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

where α is shapeA and β is shapeB

impl Clone for Beta[src]

impl PartialEq<Beta> for Beta[src]

impl Copy for Beta[src]

impl Debug for Beta[src]

impl Distribution<f64> for Beta[src]

Auto Trait Implementations

impl Send for Beta

impl Unpin for Beta

impl Sync for Beta

impl UnwindSafe for Beta

impl RefUnwindSafe for Beta

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]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,