Struct statrs::distribution::ChiSquared
[−]
[src]
pub struct ChiSquared { /* fields omitted */ }
Implements the Chi-squared distribution which is a special case of the Gamma distribution (referenced Here)
Examples
use statrs::distribution::{ChiSquared, Continuous}; use statrs::statistics::Mean; use statrs::prec; let n = ChiSquared::new(3.0).unwrap(); assert_eq!(n.mean(), 3.0); assert!(prec::almost_eq(n.pdf(4.0), 0.107981933026376103901, 1e-15));
Methods
impl ChiSquared
[src]
fn new(freedom: f64) -> Result<ChiSquared>
Constructs a new chi-squared distribution with freedom
degrees of freedom. This is equivalent to a Gamma distribution
with a shape of freedom / 2.0
and a rate of 0.5
.
Errors
Returns an error if freedom
is NaN
or less than
or equal to 0.0
Examples
use statrs::distribution::ChiSquared; let mut result = ChiSquared::new(3.0); assert!(result.is_ok()); result = ChiSquared::new(0.0); assert!(result.is_err());
fn freedom(&self) -> f64
Returns the degrees of freedom of the chi-squared distribution
Examples
use statrs::distribution::ChiSquared; let n = ChiSquared::new(3.0).unwrap(); assert_eq!(n.freedom(), 3.0);
fn shape(&self) -> f64
Returns the shape of the underlying Gamma distribution
Examples
use statrs::distribution::ChiSquared; let n = ChiSquared::new(3.0).unwrap(); assert_eq!(n.shape(), 3.0 / 2.0);
fn rate(&self) -> f64
Returns the rate of the underlying Gamma distribution
Examples
use statrs::distribution::ChiSquared; let n = ChiSquared::new(3.0).unwrap(); assert_eq!(n.rate(), 0.5);
Trait Implementations
impl Debug for ChiSquared
[src]
impl Copy for ChiSquared
[src]
impl Clone for ChiSquared
[src]
fn clone(&self) -> ChiSquared
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl PartialEq for ChiSquared
[src]
fn eq(&self, __arg_0: &ChiSquared) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &ChiSquared) -> bool
This method tests for !=
.
impl Sample<f64> for ChiSquared
[src]
fn sample<R: Rng>(&mut self, r: &mut R) -> f64
Generate a random sample from a chi-squared
distribution using r
as the source of randomness.
Refer here for implementation details
impl IndependentSample<f64> for ChiSquared
[src]
fn ind_sample<R: Rng>(&self, r: &mut R) -> f64
Generate a random independent sample from a Chi
distribution using r
as the source of randomness.
Refer here for implementation details
impl Distribution<f64> for ChiSquared
[src]
fn sample<R: Rng>(&self, r: &mut R) -> f64
Generate a random sample from the chi-squared distribution
using r
as the source of randomness
Examples
use rand::StdRng; use statrs::distribution::{ChiSquared, Distribution}; let mut r = rand::StdRng::new().unwrap(); let n = ChiSquared::new(3.0).unwrap(); print!("{}", n.sample::<StdRng>(&mut r));
impl Univariate<f64, f64> for ChiSquared
[src]
impl Min<f64> for ChiSquared
[src]
fn min(&self) -> f64
Returns the minimum value in the domain of the chi-squared distribution representable by a double precision float
Formula
0
impl Max<f64> for ChiSquared
[src]
fn max(&self) -> f64
Returns the maximum value in the domain of the chi-squared distribution representable by a double precision float
Formula
INF
impl Mean<f64> for ChiSquared
[src]
impl Variance<f64> for ChiSquared
[src]
fn variance(&self) -> f64
fn std_dev(&self) -> f64
Returns the standard deviation of the chi-squared distribution
Formula
sqrt(2k)
where k
is the degrees of freedom
impl Entropy<f64> for ChiSquared
[src]
fn entropy(&self) -> f64
Returns the entropy of the chi-squared distribution
Formula
(k / 2) + ln(2 * Γ(k / 2)) + (1 - (k / 2)) * ψ(k / 2)
where k
is the degrees of freedom, Γ
is the gamma function,
and ψ
is the digamma function
impl Skewness<f64> for ChiSquared
[src]
fn skewness(&self) -> f64
Returns the skewness of the chi-squared distribution
Formula
sqrt(8 / k)
where k
is the degrees of freedom