[][src]Struct statrs::distribution::StudentsT

pub struct StudentsT { /* fields omitted */ }

Implements the Student's T distribution

Examples

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

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

Methods

impl StudentsT[src]

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

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

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

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

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

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

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

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

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

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

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

Formula

This example is not tested
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

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

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

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

Formula

This example is not tested
Γ((v + 1) / 2) / (sqrt() * Γ(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

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

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

Formula

This example is not tested
ln(Γ((v + 1) / 2) / (sqrt() * Γ(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

impl Min<f64> for StudentsT[src]

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

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

Formula

This example is not tested
-INF

impl Max<f64> for StudentsT[src]

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

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

Formula

This example is not tested
INF

impl Mean<f64> for StudentsT[src]

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

Returns the mean of the student's t-distribution

Panics

If freedom <= 1.0

Formula

This example is not tested
μ

where μ is the location

impl CheckedMean<f64> for StudentsT[src]

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

Returns the mean of the student's t-distribution

Errors

If freedom <= 1.0

Formula

This example is not tested
μ

where μ is the location

impl Variance<f64> for StudentsT[src]

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

Returns the variance of the student's t-distribution

Panics

If freedom <= 1.0

Formula

This example is not tested
if v == INF {
    σ^2
} else if freedom > 2.0 {
    v * σ^2 / (v - 2)
} else {
    INF
}

where σ is the scale and v is the freedom

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

Returns the standard deviation of the student's t-distribution

Panics

If freedom <= 1.0

Formula

This example is not tested
let variance = if v == INF {
    σ^2
} else if freedom > 2.0 {
    v * σ^2 / (v - 2)
} else {
    INF
}
sqrt(variance)

where σ is the scale and v is the freedom

impl CheckedVariance<f64> for StudentsT[src]

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

Returns the variance of the student's t-distribution

Errors

If freedom <= 1.0

Formula

This example is not tested
if v == INF {
    σ^2
} else if freedom > 2.0 {
    v * σ^2 / (v - 2)
} else {
    INF
}

where σ is the scale and v is the freedom

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

Returns the standard deviation of the student's t-distribution

Errors

If freedom <= 1.0

Formula

This example is not tested
let variance = if v == INF {
    σ^2
} else if freedom > 2.0 {
    v * σ^2 / (v - 2)
} else {
    INF
}
sqrt(variance)

where σ is the scale and v is the freedom

impl Entropy<f64> for StudentsT[src]

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

Returns the entropy for the student's t-distribution

Panics

If location != 0.0 && scale != 1.0

Formula

This example is not tested
(v + 1) / 2 * (ψ((v + 1) / 2) - ψ(v / 2)) + ln(sqrt(v) * B(v / 2, 1 /
2))

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

impl CheckedEntropy<f64> for StudentsT[src]

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

Returns the entropy for the student's t-distribution

Errors

If location != 0.0 && scale != 1.0

Formula

This example is not tested
(v + 1) / 2 * (ψ((v + 1) / 2) - ψ(v / 2)) + ln(sqrt(v) * B(v / 2, 1 /
2))

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

impl Skewness<f64> for StudentsT[src]

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

Returns the skewness of the student's t-distribution

Panics

If x <= 3.0

Formula

This example is not tested
0

impl CheckedSkewness<f64> for StudentsT[src]

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

Returns the skewness of the student's t-distribution

Errors

If x <= 3.0

Formula

This example is not tested
0

impl Median<f64> for StudentsT[src]

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

Returns the median of the student's t-distribution

Formula

This example is not tested
μ

where μ is the location

impl Mode<f64> for StudentsT[src]

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

Returns the mode of the student's t-distribution

Formula

This example is not tested
μ

where μ is the location

impl Clone for StudentsT[src]

impl PartialEq<StudentsT> for StudentsT[src]

impl Copy for StudentsT[src]

impl Debug for StudentsT[src]

impl Distribution<f64> for StudentsT[src]

Auto Trait Implementations

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>,