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".

Stats

Descriptive statistics over a Float[]. Each function returns NaN when the array is Nil, too short for the statistic, or holds a NaN or infinity.

Operations

Covariance # function

Sample covariance of two arrays of the same length.

function : Covariance(x:Float[], y:Float[]) ~ Float

Parameters

NameTypeDescription
xFloatfirst values, at least 2
yFloatsecond values, same length as x

Return

TypeDescription
Floatcovariance, NaN for mismatched or bad input

Mean # function

Arithmetic mean.

function : Mean(x:Float[]) ~ Float

Parameters

NameTypeDescription
xFloatvalues

Return

TypeDescription
Floatmean, NaN for Nil, empty or non-finite input

Median # function

Median: the middle value, or the mean of the two middle values.

function : Median(x:Float[]) ~ Float

Parameters

NameTypeDescription
xFloatvalues

Return

TypeDescription
Floatmedian, NaN for Nil, empty or non-finite input

PopulationVariance # function

Population variance (divides by n).

function : PopulationVariance(x:Float[]) ~ Float

Parameters

NameTypeDescription
xFloatvalues, at least 1

Return

TypeDescription
Floatvariance, NaN for Nil, empty or non-finite input

StdDev # function

Sample standard deviation (divides by n - 1).

function : StdDev(x:Float[]) ~ Float

Parameters

NameTypeDescription
xFloatvalues, at least 2

Return

TypeDescription
Floatstandard deviation, NaN for bad input

StdError # function

Standard error of the mean: the sample standard deviation over the square root of n.

function : StdError(x:Float[]) ~ Float

Parameters

NameTypeDescription
xFloatvalues, at least 2

Return

TypeDescription
Floatstandard error, NaN for bad input

Sum # function

Sum of the values.

function : Sum(x:Float[]) ~ Float

Parameters

NameTypeDescription
xFloatvalues

Return

TypeDescription
Floatsum, NaN for Nil, empty or non-finite input

Variance # function

Sample variance (divides by n - 1).

function : Variance(x:Float[]) ~ Float

Parameters

NameTypeDescription
xFloatvalues, at least 2

Return

TypeDescription
Floatvariance, NaN for fewer than 2 values, Nil or non-finite input