Struct statrs::distribution::StudentsT

source ·
pub struct StudentsT { /* private fields */ }
Expand description

Implements the Student’s T distribution

§Examples

use statrs::distribution::{StudentsT, Continuous};
use statrs::statistics::Distribution;
use statrs::prec;

let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
assert_eq!(n.mean().unwrap(), 0.0);
assert!(prec::almost_eq(n.pdf(0.0), 0.353553390593274, 1e-15));

Implementations§

source§

impl StudentsT

source

pub fn new(location: f64, scale: f64, freedom: f64) -> Result<StudentsT>

Constructs a new student’s t-distribution with location location, scale scale, and freedom freedom.

§Errors

Returns an error if any of location, scale, or freedom are NaN. Returns an error if scale <= 0.0 or freedom <= 0.0

§Examples
use statrs::distribution::StudentsT;

let mut result = StudentsT::new(0.0, 1.0, 2.0);
assert!(result.is_ok());

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

pub fn location(&self) -> f64

Returns the location of the student’s t-distribution

§Examples
use statrs::distribution::StudentsT;

let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
assert_eq!(n.location(), 0.0);
source

pub fn scale(&self) -> f64

Returns the scale of the student’s t-distribution

§Examples
use statrs::distribution::StudentsT;

let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
assert_eq!(n.scale(), 1.0);
source

pub fn freedom(&self) -> f64

Returns the freedom of the student’s t-distribution

§Examples
use statrs::distribution::StudentsT;

let n = StudentsT::new(0.0, 1.0, 2.0).unwrap();
assert_eq!(n.freedom(), 2.0);

Trait Implementations§

source§

impl Clone for StudentsT

source§

fn clone(&self) -> StudentsT

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Continuous<f64, f64> for StudentsT

source§

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

Calculates the probability density function for the student’s t-distribution at x

§Formula
Γ((v + 1) / 2) / (sqrt(vπ) * Γ(v / 2) * σ) * (1 + k^2 / v)^(-1 / 2 * (v
+ 1))

where k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and Γ is the gamma function

source§

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

Calculates the log probability density function for the student’s t-distribution at x

§Formula
ln(Γ((v + 1) / 2) / (sqrt(vπ) * Γ(v / 2) * σ) * (1 + k^2 / v)^(-1 / 2 *
(v + 1)))

where k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and Γ is the gamma function

source§

impl ContinuousCDF<f64, f64> for StudentsT

source§

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

Calculates the cumulative distribution function for the student’s t-distribution at x

§Formula
if x < μ {
    (1 / 2) * I(t, v / 2, 1 / 2)
} else {
    1 - (1 / 2) * I(t, v / 2, 1 / 2)
}

where t = v / (v + k^2), k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and I is the regularized incomplete beta function

source§

fn sf(&self, x: f64) -> f64

Calculates the cumulative distribution function for the student’s t-distribution at x

§Formula
if x < μ {
    1 - (1 / 2) * I(t, v / 2, 1 / 2)
} else {
    (1 / 2) * I(t, v / 2, 1 / 2)
}

where t = v / (v + k^2), k = (x - μ) / σ, μ is the location, σ is the scale, v is the freedom, and I is the regularized incomplete beta function

source§

fn inverse_cdf(&self, x: f64) -> f64

Calculates the inverse cumulative distribution function for the Student’s T-distribution at x

source§

impl Debug for StudentsT

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Distribution<f64> for StudentsT

source§

fn sample<R: Rng + ?Sized>(&self, r: &mut R) -> f64

Generate a random value of T, using rng as the source of randomness.
source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
source§

impl Distribution<f64> for StudentsT

source§

fn mean(&self) -> Option<f64>

Returns the mean of the student’s t-distribution

§None

If freedom <= 1.0

§Formula
μ

where μ is the location

source§

fn variance(&self) -> Option<f64>

Returns the variance of the student’s t-distribution

§None

If freedom <= 2.0

§Formula
if v == f64::INFINITY {
    Some(σ^2)
} else if freedom > 2.0 {
    Some(v * σ^2 / (v - 2))
} else {
    None
}

where σ is the scale and v is the freedom

source§

fn entropy(&self) -> Option<f64>

Returns the entropy for the student’s t-distribution

§Formula
- ln(σ) + (v + 1) / 2 * (ψ((v + 1) / 2) - ψ(v / 2)) + ln(sqrt(v) * B(v / 2, 1 /
2))

where σ is the scale, v is the freedom, ψ is the digamma function, and B is the beta function

source§

fn skewness(&self) -> Option<f64>

Returns the skewness of the student’s t-distribution

§None

If x <= 3.0

§Formula
0
source§

fn std_dev(&self) -> Option<T>

Returns the standard deviation, if it exists. Read more
source§

impl Max<f64> for StudentsT

source§

fn max(&self) -> f64

Returns the maximum value in the domain of the student’s t-distribution representable by a double precision float

§Formula
f64::INFINITY
source§

impl Median<f64> for StudentsT

source§

fn median(&self) -> f64

Returns the median of the student’s t-distribution

§Formula
μ

where μ is the location

source§

impl Min<f64> for StudentsT

source§

fn min(&self) -> f64

Returns the minimum value in the domain of the student’s t-distribution representable by a double precision float

§Formula
f64::NEG_INFINITY
source§

impl Mode<Option<f64>> for StudentsT

source§

fn mode(&self) -> Option<f64>

Returns the mode of the student’s t-distribution

§Formula
μ

where μ is the location

source§

impl PartialEq for StudentsT

source§

fn eq(&self, other: &StudentsT) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for StudentsT

source§

impl StructuralPartialEq for StudentsT

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,