v2026.11.2
All Bundles
Bundle

Classical statistics for small analyses: descriptive statistics, the Student t, normal, chi-square and F distributions, t-tests with confidence intervals and effect sizes, Pearson correlation with a p-value, and an ordinary least squares fit with the full summary table (standard errors, t statistics, p values, confidence intervals, F test, R-squared, AIC and BIC). Compile with -lib stats,gen_collect; it needs nothing from System.ML.

No call here ends the program on bad input. A function that returns a Float returns NaN, and a function that returns a result object returns one whose IsValid() is false and whose GetError() says why. Design and verification notes: docs/AI.md, "Statistics".

Dist

Special functions and probability distributions. Every function takes plain Floats and returns NaN for arguments outside its domain, so a bad value shows up as NaN and never ends the program.

Operations

BetaInc # function

The regularized incomplete beta function I_x(a, b).

function : BetaInc(x:Float, a:Float, b:Float) ~ Float

Parameters

NameTypeDescription
xFloatbetween 0 and 1
aFloatshape, above 0
bFloatshape, above 0

Return

TypeDescription
Floatvalue between 0 and 1, NaN outside the domain

ChiSquareCdf # function

Cumulative distribution function of the chi-square distribution.

function : ChiSquareCdf(x:Float, df:Float) ~ Float

Parameters

NameTypeDescription
xFloatthe value, 0 or more
dfFloatdegrees of freedom, above 0

Return

TypeDescription
FloatP(X <= x), NaN outside the domain

ChiSquareSf # function

Upper tail of the chi-square distribution, P(X >= x); the p-value of a chi-square statistic.

function : ChiSquareSf(x:Float, df:Float) ~ Float

Parameters

NameTypeDescription
xFloatthe statistic, 0 or more
dfFloatdegrees of freedom, above 0

Return

TypeDescription
Floatprobability, NaN outside the domain

Div # function

Division that does not stop the program when the divisor is 0: a / 0 is +Inf or -Inf, and 0 / 0 is NaN.

function : Div(a:Float, b:Float) ~ Float

Parameters

NameTypeDescription
aFloatdividend
bFloatdivisor

Return

TypeDescription
Floatthe quotient

FCdf # function

Cumulative distribution function of the F distribution.

function : FCdf(f:Float, df1:Float, df2:Float) ~ Float

Parameters

NameTypeDescription
fFloatthe value, 0 or more
df1Floatnumerator degrees of freedom, above 0
df2Floatdenominator degrees of freedom, above 0

Return

TypeDescription
FloatP(F <= f), NaN outside the domain

FSf # function

Upper tail of the F distribution, P(F >= f); the p-value of an F statistic.

function : FSf(f:Float, df1:Float, df2:Float) ~ Float

Parameters

NameTypeDescription
fFloatthe statistic, 0 or more
df1Floatnumerator degrees of freedom, above 0
df2Floatdenominator degrees of freedom, above 0

Return

TypeDescription
Floatprobability, NaN outside the domain

GammaInc # function

The regularized lower incomplete gamma function P(a, x).

function : GammaInc(a:Float, x:Float) ~ Float

Parameters

NameTypeDescription
aFloatshape, above 0
xFloatargument, 0 or more

Return

TypeDescription
Floatvalue between 0 and 1, NaN outside the domain

HedgesJ # function

Hedges' small-sample correction factor for Cohen's d, exactly: Gamma(df/2) / (sqrt(df/2) * Gamma((df-1)/2)). It is 0 at df = 1 (the limit), and close to 1 - 3 / (4 df - 1).

function : HedgesJ(df:Float) ~ Float

Parameters

NameTypeDescription
dfFloatdegrees of freedom, 1 or more

Return

TypeDescription
Floatthe factor, NaN below 1

LogGamma # function

Natural log of the gamma function, for x above 0 (Lanczos approximation, about 15 digits).

function : LogGamma(x:Float) ~ Float

Parameters

NameTypeDescription
xFloatargument, above 0

Return

TypeDescription
Floatlog(gamma(x)), NaN when x is not above 0 or not finite

NormalCdf # function

Cumulative distribution function of the standard normal distribution.

function : NormalCdf(x:Float) ~ Float

Parameters

NameTypeDescription
xFloatthe value

Return

TypeDescription
FloatP(Z <= x), NaN when x is NaN

NormalQuantile # function

Quantile (inverse CDF) of the standard normal distribution.

function : NormalQuantile(p:Float) ~ Float

Parameters

NameTypeDescription
pFloatprobability, strictly between 0 and 1

Return

TypeDescription
Floatz with P(Z <= z) = p, NaN outside the domain

NormalTwoSidedP # function

Two-sided p-value of a standard normal statistic: P(|Z| >= |z|).

function : NormalTwoSidedP(z:Float) ~ Float

Parameters

NameTypeDescription
zFloatthe statistic

Return

TypeDescription
Floatprobability, NaN when z is NaN

StudentCdf # function

Cumulative distribution function of the Student t distribution.

function : StudentCdf(t:Float, df:Float) ~ Float

Parameters

NameTypeDescription
tFloatthe statistic
dfFloatdegrees of freedom, above 0

Return

TypeDescription
FloatP(T <= t), NaN outside the domain

StudentQuantile # function

Quantile (inverse CDF) of the Student t distribution, found by bisection to full double precision.

function : StudentQuantile(p:Float, df:Float) ~ Float

Parameters

NameTypeDescription
pFloatprobability, strictly between 0 and 1
dfFloatdegrees of freedom, above 0

Return

TypeDescription
Floatt with P(T <= t) = p, NaN outside the domain

StudentTwoSidedP # function

Two-sided p-value of a Student t statistic: P(|T| >= |t|).

function : StudentTwoSidedP(t:Float, df:Float) ~ Float

Parameters

NameTypeDescription
tFloatthe statistic
dfFloatdegrees of freedom, above 0

Return

TypeDescription
Floatprobability, NaN when t is NaN or df is not above 0