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

OLS

Ordinary least squares by Householder QR (no normal equations, so near-collinear columns lose half as many digits).

Failures (IsValid() false on the result): Nil input, X and y with different row counts, no columns, fewer rows than columns plus one, NaN or infinity in the data, and rank-deficient columns (a constant column beside an intercept, a column that repeats another, or all the dummy columns of a variable beside an intercept).

Example

X := [[1.0], [2.0], [3.0], [4.0], [5.0]];
y := [2.1, 3.9, 6.2, 7.8, 10.1];
fit := OLS->Fit(X, y, true);
fit->ToString()->PrintLine();
fit->GetPValues()[1]->PrintLine();

Operations

Fit # function

Fits y on the columns of X, with names x1, x2, ...

function : Fit(X:Float[,], y:Float[], add_intercept:Bool) ~ OLSResult

Parameters

NameTypeDescription
XFloatpredictor matrix (rows = samples)
yFloatresponse, one value per row
add_interceptBooltrue to add a leading column of ones, named "const"

Return

TypeDescription
OLSResultthe fit

Fit # function

Fits y on the columns of X with named columns.

function : Fit(X:Float[,], y:Float[], add_intercept:Bool, names:String[]) ~ OLSResult

Parameters

NameTypeDescription
XFloatpredictor matrix (rows = samples)
yFloatresponse, one value per row
add_interceptBooltrue to add a leading column of ones, named "const"
namesStringone name per column of X (not for the intercept); Nil for x1, x2, ...

Return

TypeDescription
OLSResultthe fit