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

OLSResult

An ordinary least squares fit with its summary statistics. A failed fit (IsValid() false) has Nil arrays and NaN numbers, and GetError() says why.

With an intercept, R-squared uses the centred total sum of squares and the F test is against the intercept-only model; without one they use the uncentred sum of squares, as statsmodels does. AIC and BIC come from the Gaussian log-likelihood and count one parameter per coefficient, as statsmodels does.

Operations

GetAIC #

Akaike information criterion.

method : public : GetAIC() ~ Float

Return

TypeDescription
FloatAIC

GetAdjustedRSquared #

Adjusted R-squared.

method : public : GetAdjustedRSquared() ~ Float

Return

TypeDescription
Floatadjusted R-squared

GetBIC #

Bayesian information criterion.

method : public : GetBIC() ~ Float

Return

TypeDescription
FloatBIC

GetCoefficients #

Coefficients, in column order.

method : public : GetCoefficients() ~ Float[]

Return

TypeDescription
Floatcoefficients, Nil when invalid

GetConfInt #

Confidence intervals of the coefficients.

method : public : GetConfInt(level:Float) ~ Float[,]

Parameters

NameTypeDescription
levelFloatconfidence level, strictly between 0 and 1

Return

TypeDescription
Floatmatrix with one row per coefficient: lower bound, upper bound; Nil when invalid or the level is out of range

GetCovariance #

Covariance matrix of the coefficients: sigma^2 (X'X)^-1.

method : public : GetCovariance() ~ Float[,]

Return

TypeDescription
Floatmatrix, Nil when invalid

GetDfModel #

Model degrees of freedom: k, less 1 with an intercept.

method : public : GetDfModel() ~ Float

Return

TypeDescription
Floatdegrees of freedom

GetDfResid #

Residual degrees of freedom, n - k.

method : public : GetDfResid() ~ Float

Return

TypeDescription
Floatdegrees of freedom

GetError #

Why the fit failed, or an empty string.

method : public : GetError() ~ String

Return

TypeDescription
Stringreason

GetFPValue #

p-value of the F statistic.

method : public : GetFPValue() ~ Float

Return

TypeDescription
Floatp, NaN when F is NaN

GetFStat #

F statistic of the whole model against the intercept-only (or empty) model.

method : public : GetFStat() ~ Float

Return

TypeDescription
FloatF, NaN when the model has no predictors or the fit is exact

GetFitted #

Fitted values.

method : public : GetFitted() ~ Float[]

Return

TypeDescription
Floatfitted values, Nil when invalid

GetLogLikelihood #

Gaussian log-likelihood.

method : public : GetLogLikelihood() ~ Float

Return

TypeDescription
Floatlog-likelihood

GetNObs #

Number of observations.

method : public : GetNObs() ~ Int

Return

TypeDescription
Intn, 0 when invalid

GetNParams #

Number of coefficients, the intercept included.

method : public : GetNParams() ~ Int

Return

TypeDescription
Intcount

GetNames #

Column names, in coefficient order (the intercept is "const").

method : public : GetNames() ~ String[]

Return

TypeDescription
Stringnames, Nil when invalid

GetPValues #

Two-sided p-values of the coefficients, from the t distribution with GetDfResid() degrees of freedom.

method : public : GetPValues() ~ Float[]

Return

TypeDescription
Floatp-values, Nil when invalid

GetRSquared #

R-squared.

method : public : GetRSquared() ~ Float

Return

TypeDescription
FloatR-squared, NaN when y does not vary

GetResidualStdError #

Residual standard error: sqrt(SSR / (n - k)).

method : public : GetResidualStdError() ~ Float

Return

TypeDescription
Floatresidual standard error

GetResiduals #

Residuals, y minus the fitted values.

method : public : GetResiduals() ~ Float[]

Return

TypeDescription
Floatresiduals, Nil when invalid

GetSSR #

Residual sum of squares.

method : public : GetSSR() ~ Float

Return

TypeDescription
Floatsum of squared residuals

GetStdErrors #

Standard errors of the coefficients.

method : public : GetStdErrors() ~ Float[]

Return

TypeDescription
Floatstandard errors, Nil when invalid

GetTStats #

t statistics of the coefficients (coefficient / standard error).

method : public : GetTStats() ~ Float[]

Return

TypeDescription
Floatt statistics, Nil when invalid

HasIntercept #

Whether the fit has an intercept.

method : public : HasIntercept() ~ Bool

Return

TypeDescription
Booltrue if the first column is the intercept

IsValid #

Whether the fit succeeded.

method : public : IsValid() ~ Bool

Return

TypeDescription
Booltrue if every number is meaningful

Predict #

Predicts from new rows. Give the same columns the fit was given: an intercept column is added here when the fit added one.

method : public : Predict(X:Float[,]) ~ Float[]

Parameters

NameTypeDescription
XFloatfeature rows

Return

TypeDescription
Floatpredictions, Nil when invalid, X is Nil or the column count is wrong

ToString #

A statsmodels-style summary: the fit statistics, then one row per coefficient with its standard error, t, p and 95% interval.

method : public : ToString() ~ String

Return

TypeDescription
Stringthe table