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

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]

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

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

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

Formats the value using the given formatter.

impl Copy for Beta
[src]

impl Clone for Beta
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

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

impl IndependentSample<f64> for Beta
[src]

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

impl Distribution<f64> for Beta
[src]

Generate a random sample from a beta distribution using r as the source of randomness. Generated by sampling two gamma distributions and normalizing.

Examples

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

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

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

Calculates the cumulative distribution function for the beta distribution at x

Panics

If x < 0.0 or x > 1.0

Formula

I_x(α, β)

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

impl Min<f64> for Beta
[src]

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

Formula

0

impl Max<f64> for Beta
[src]

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

Formula

1

impl Mean<f64> for Beta
[src]

Returns the mean of the beta distribution

Formula

α / (α + β)

where α is shapeA and β is shapeB

impl Variance<f64> for Beta
[src]

Returns the variance of the beta distribution

Remarks

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

Formula

(α * β) / ((α + β)^2 * (α + β + 1))

where α is shapeA and β is shapeB

Returns the standard deviation of the beta distribution

Remarks

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

Formula

sqrt((α * β) / ((α + β)^2 * (α + β + 1)))

where α is shapeA and β is shapeB

impl Entropy<f64> for Beta
[src]

Returns the entropy of the beta distribution

Formula

ln(B(α, β)) - (α - 1)ψ(α) - (β - 1)ψ(β) + (α + β - 2)ψ(α + β)

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

impl Skewness<f64> for Beta
[src]

Returns the skewness of the Beta distribution

Formula

2(β - α) * sqrt(α + β + 1) / ((α + β + 2) * sqrt(αβ))

where α is shapeA and β is shapeB

impl Mode<f64> for Beta
[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

(α - 1) / (α + β - 2)

where α is shapeA and β is shapeB

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

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

Panics

If x < 0.0 or x > 1.0

Formula

let B(α, β) = Γ(α)Γ(β)/Γ(α + β)

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

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

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

Panics

If x < 0.0 or x > 1.0

Formula

let B(α, β) = Γ(α)Γ(β)/Γ(α + β)

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

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