pub struct ChiSquared { /* private fields */ }Expand description
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::Distribution;
use approx::assert_abs_diff_eq;
let n = ChiSquared::new(3.0).unwrap();
assert_eq!(n.mean().unwrap(), 3.0);
assert_abs_diff_eq!(n.pdf(4.0), 0.107981933026376103901, epsilon = 1e-15);Implementations§
Source§impl ChiSquared
impl ChiSquared
Sourcepub fn new(freedom: f64) -> Result<ChiSquared, GammaError>
pub fn new(freedom: f64) -> Result<ChiSquared, GammaError>
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());Sourcepub fn freedom(&self) -> f64
pub 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);Trait Implementations§
Source§impl Clone for ChiSquared
impl Clone for ChiSquared
Source§fn clone(&self) -> ChiSquared
fn clone(&self) -> ChiSquared
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Continuous<f64, f64> for ChiSquared
impl Continuous<f64, f64> for ChiSquared
Source§fn pdf(&self, x: f64) -> f64
fn pdf(&self, x: f64) -> f64
Calculates the probability density function for the chi-squared
distribution at x
At x = 0, returns positive infinity for freedom < 2, 0.5 for
freedom = 2, and 0 for freedom > 2.
§Formula
1 / (2^(k / 2) * Γ(k / 2)) * x^((k / 2) - 1) * e^(-x / 2)where k is the degrees of freedom and Γ is the gamma function
Source§fn ln_pdf(&self, x: f64) -> f64
fn ln_pdf(&self, x: f64) -> f64
Calculates the log probability density function for the chi-squared
distribution at x
At x = 0, returns positive infinity for freedom < 2, ln(0.5) for
freedom = 2, and negative infinity for freedom > 2.
§Formula
ln(1 / (2^(k / 2) * Γ(k / 2)) * x^((k / 2) - 1) * e^(-x / 2))Source§impl ContinuousCDF<f64, f64> for ChiSquared
impl ContinuousCDF<f64, f64> for ChiSquared
Source§fn cdf(&self, x: f64) -> f64
fn cdf(&self, x: f64) -> f64
Calculates the cumulative distribution function for the
chi-squared distribution at x
§Formula
(1 / Γ(k / 2)) * γ(k / 2, x / 2)where k is the degrees of freedom, Γ is the gamma function,
and γ is the lower incomplete gamma function
Source§fn sf(&self, x: f64) -> f64
fn sf(&self, x: f64) -> f64
Calculates the cumulative distribution function for the
chi-squared distribution at x
§Formula
(1 / Γ(k / 2)) * γ(k / 2, x / 2)where k is the degrees of freedom, Γ is the gamma function,
and γ is the upper incomplete gamma function
Source§fn inverse_cdf(&self, p: f64) -> f64
fn inverse_cdf(&self, p: f64) -> f64
Calculates the inverse cumulative distribution function for the
chi-squared distribution at x
§Formula
γ^{-1}(k / 2, x * Γ(k / 2) / 2)where k is the degrees of freedom, Γ is the gamma function,
and γ is the lower incomplete gamma function
Source§fn try_inverse_cdf(&self, p: T) -> Result<K, InverseCdfError>
fn try_inverse_cdf(&self, p: T) -> Result<K, InverseCdfError>
cdf to obtain an approximation
of F^-1(p) := inf { x | F(x) >= p }. Needless to say, performance may
may be lacking.impl Copy for ChiSquared
Source§impl Debug for ChiSquared
impl Debug for ChiSquared
Source§impl Display for ChiSquared
impl Display for ChiSquared
Source§impl Distribution<f64> for ChiSquared
Available on crate feature rand only.
impl Distribution<f64> for ChiSquared
rand only.Source§impl Distribution<f64> for ChiSquared
impl Distribution<f64> for ChiSquared
Source§fn entropy(&self) -> Option<f64>
fn entropy(&self) -> Option<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
Source§impl Max<f64> for ChiSquared
impl Max<f64> for ChiSquared
Source§impl Median<f64> for ChiSquared
impl Median<f64> for ChiSquared
Source§impl Min<f64> for ChiSquared
impl Min<f64> for ChiSquared
Source§impl PartialEq for ChiSquared
impl PartialEq for ChiSquared
impl StructuralPartialEq for ChiSquared
Auto Trait Implementations§
impl Freeze for ChiSquared
impl RefUnwindSafe for ChiSquared
impl Send for ChiSquared
impl Sync for ChiSquared
impl Unpin for ChiSquared
impl UnsafeUnpin for ChiSquared
impl UnwindSafe for ChiSquared
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.