Class TDistribution.StudentsTDistribution
java.lang.Object
org.apache.commons.statistics.distribution.AbstractContinuousDistribution
org.apache.commons.statistics.distribution.TDistribution
org.apache.commons.statistics.distribution.TDistribution.StudentsTDistribution
- All Implemented Interfaces:
ContinuousDistribution
- Enclosing class:
TDistribution
Implementation of Student's T-distribution.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.commons.statistics.distribution.ContinuousDistribution
ContinuousDistribution.Sampler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
The threshold for the density function where the power function base minus 1 is close to zero.private final double
Density normalisation factor, sqrt(v) * beta(1/2, v/2), where v = degrees of freedom.private final double
Log density normalisation term, 0.5 * log(v) + log(beta(1/2, v/2)), where v = degrees of freedom.private final double
Cached value for inverse probability function.private final double
-(v + 1) / 2, where v = degrees of freedom.private static final double
2.private final double
Cached value for inverse probability function.Fields inherited from class org.apache.commons.statistics.distribution.TDistribution
STANDARD_NORMAL
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static double
computeVariance
(double degreesOfFreedom) createSampler
(org.apache.commons.rng.UniformRandomProvider rng) Creates a sampler.double
cumulativeProbability
(double x) For a random variableX
whose values are distributed according to this distribution, this method returnsP(X <= x)
.double
density
(double x) Returns the probability density function (PDF) of this distribution evaluated at the specified pointx
.double
getMean()
Gets the mean of this distribution.(package private) double
Gets the median.double
Gets the variance of this distribution.double
logDensity
(double x) Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified pointx
.Methods inherited from class org.apache.commons.statistics.distribution.TDistribution
getDegreesOfFreedom, getSupportLowerBound, getSupportUpperBound, inverseSurvivalProbability, of, survivalProbability
Methods inherited from class org.apache.commons.statistics.distribution.AbstractContinuousDistribution
inverseCumulativeProbability, isSupportConnected, probability
-
Field Details
-
TWO
private static final double TWO2.- See Also:
-
CLOSE_TO_ZERO
private static final double CLOSE_TO_ZEROThe threshold for the density function where the power function base minus 1 is close to zero.- See Also:
-
mvp1Over2
private final double mvp1Over2-(v + 1) / 2, where v = degrees of freedom. -
densityNormalisation
private final double densityNormalisationDensity normalisation factor, sqrt(v) * beta(1/2, v/2), where v = degrees of freedom. -
logDensityNormalisation
private final double logDensityNormalisationLog density normalisation term, 0.5 * log(v) + log(beta(1/2, v/2)), where v = degrees of freedom. -
mean
private final double meanCached value for inverse probability function. -
variance
private final double varianceCached value for inverse probability function.
-
-
Constructor Details
-
StudentsTDistribution
StudentsTDistribution(double degreesOfFreedom, double variance) - Parameters:
degreesOfFreedom
- Degrees of freedom.variance
- Precomputed variance
-
-
Method Details
-
computeVariance
static double computeVariance(double degreesOfFreedom) - Parameters:
degreesOfFreedom
- Degrees of freedom.- Returns:
- the variance
-
density
public double density(double x) Description copied from interface:ContinuousDistribution
Returns the probability density function (PDF) of this distribution evaluated at the specified pointx
. In general, the PDF is the derivative of theCDF
. If the derivative does not exist atx
, then an appropriate replacement should be returned, e.g.Double.POSITIVE_INFINITY
,Double.NaN
, or the limit inferior or limit superior of the difference quotient.- Parameters:
x
- Point at which the PDF is evaluated.- Returns:
- the value of the probability density function at
x
.
-
logDensity
public double logDensity(double x) Description copied from interface:ContinuousDistribution
Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified pointx
.- Parameters:
x
- Point at which the PDF is evaluated.- Returns:
- the logarithm of the value of the probability density function
at
x
.
-
cumulativeProbability
public double cumulativeProbability(double x) Description copied from interface:ContinuousDistribution
For a random variableX
whose values are distributed according to this distribution, this method returnsP(X <= x)
. In other words, this method represents the (cumulative) distribution function (CDF) for this distribution.- Parameters:
x
- Point at which the CDF is evaluated.- Returns:
- the probability that a random variable with this
distribution takes a value less than or equal to
x
.
-
getMean
public double getMean()Description copied from class:TDistribution
Gets the mean of this distribution.For degrees of freedom parameter \( v \), the mean is:
\[ \mathbb{E}[X] = \begin{cases} 0 & \text{for } v \gt 1 \\ \text{undefined} & \text{otherwise} \end{cases} \]
- Specified by:
getMean
in interfaceContinuousDistribution
- Specified by:
getMean
in classTDistribution
- Returns:
- the mean, or
NaN
if it is not defined.
-
getVariance
public double getVariance()Description copied from class:TDistribution
Gets the variance of this distribution.For degrees of freedom parameter \( v \), the variance is:
\[ \operatorname{var}[X] = \begin{cases} \frac{v}{v - 2} & \text{for } v \gt 2 \\ \infty & \text{for } 1 \lt v \le 2 \\ \text{undefined} & \text{otherwise} \end{cases} \]
- Specified by:
getVariance
in interfaceContinuousDistribution
- Specified by:
getVariance
in classTDistribution
- Returns:
- the variance, or
NaN
if it is not defined.
-
getMedian
double getMedian()Description copied from class:AbstractContinuousDistribution
Gets the median. This is used to determine if the arguments to theAbstractContinuousDistribution.probability(double, double)
function are in the upper or lower domain.The default implementation calls
AbstractContinuousDistribution.inverseCumulativeProbability(double)
with a value of 0.5.- Overrides:
getMedian
in classAbstractContinuousDistribution
- Returns:
- the median
-
createSampler
public ContinuousDistribution.Sampler createSampler(org.apache.commons.rng.UniformRandomProvider rng) Description copied from class:AbstractContinuousDistribution
Creates a sampler.- Specified by:
createSampler
in interfaceContinuousDistribution
- Overrides:
createSampler
in classAbstractContinuousDistribution
- Parameters:
rng
- Generator of uniformly distributed numbers.- Returns:
- a sampler that produces random numbers according this distribution.
-