ChiSquaredDistribution

Represents the chi-squared distribution, a continuous probability distribution defined on the interval [0, +infinity).

The chi-squared distribution describes the distribution of a sum of squared standard normal random variables. It is one of the most widely used distributions in statistical inference, appearing in chi-squared goodness-of-fit tests, tests of independence in contingency tables, and confidence intervals for population variance. The single parameter degreesOfFreedom determines the shape: higher values shift the distribution to the right and make it more symmetric.

Internally, this distribution is implemented as a special case of the Gamma distribution with shape equal to half the degrees of freedom and rate equal to 0.5. The CDF, quantile, and sampling methods all delegate to this underlying Gamma parameterization.

Example:

val dist = ChiSquaredDistribution(degreesOfFreedom = 5.0)
dist.mean // 5.0 (equal to the degrees of freedom)
dist.variance // 10.0 (twice the degrees of freedom)
dist.pdf(3.0) // 0.1542... (density at x = 3)
dist.cdf(11.07) // 0.95 (approximately)

// Quantile for a chi-squared test critical value
dist.quantile(0.95) // 11.07... (95th percentile with 5 df)

See also

Constructors

Link copied to clipboard
constructor(degreesOfFreedom: Double)

Properties

Link copied to clipboard

the number of degrees of freedom. Must be positive.

Link copied to clipboard
open override val entropy: Double

The differential entropy of this distribution.

Link copied to clipboard
open override val kurtosis: Double

The excess kurtosis of this distribution, which decreases as degrees of freedom increases.

Link copied to clipboard
open override val mean: Double

The mean of this distribution, equal to the degrees of freedom.

Link copied to clipboard
open override val skewness: Double

The skewness of this distribution, which decreases as degrees of freedom increases.

Link copied to clipboard
open override val variance: Double

The variance of this distribution, equal to twice the degrees of freedom.

Functions

Link copied to clipboard
open override fun cdf(x: Double): Double

Computes the cumulative distribution function at x.

Link copied to clipboard
open override fun logPdf(x: Double): Double

Computes the natural logarithm of the probability density at x.

Link copied to clipboard
open override fun pdf(x: Double): Double

Computes the probability density at x.

Link copied to clipboard
open override fun quantile(p: Double): Double

Computes the quantile (inverse CDF) for the given probability p.

Link copied to clipboard
open override fun sample(random: Random): Double

Draws a single random value from this chi-squared distribution.

Link copied to clipboard
open override fun sf(x: Double): Double

Computes the survival function (one minus the CDF) at x.