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
- GetAdjustedRSquared
- GetBIC
- GetCoefficients
- GetConfInt
- GetCovariance
- GetDfModel
- GetDfResid
- GetError
- GetFPValue
- GetFStat
- GetFitted
- GetLogLikelihood
- GetNObs
- GetNParams
- GetNames
- GetPValues
- GetRSquared
- GetResidualStdError
- GetResiduals
- GetSSR
- GetStdErrors
- GetTStats
- HasIntercept
- IsValid
- Predict
- ToString
GetAIC #
Akaike information criterion.
method : public : GetAIC() ~ FloatReturn
| Type | Description |
|---|---|
| Float | AIC |
GetAdjustedRSquared #
Adjusted R-squared.
method : public : GetAdjustedRSquared() ~ FloatReturn
| Type | Description |
|---|---|
| Float | adjusted R-squared |
GetBIC #
Bayesian information criterion.
method : public : GetBIC() ~ FloatReturn
| Type | Description |
|---|---|
| Float | BIC |
GetCoefficients #
Coefficients, in column order.
method : public : GetCoefficients() ~ Float[]Return
| Type | Description |
|---|---|
| Float | coefficients, Nil when invalid |
GetConfInt #
Confidence intervals of the coefficients.
method : public : GetConfInt(level:Float) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| level | Float | confidence level, strictly between 0 and 1 |
Return
| Type | Description |
|---|---|
| Float | matrix 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
| Type | Description |
|---|---|
| Float | matrix, Nil when invalid |
GetDfModel #
Model degrees of freedom: k, less 1 with an intercept.
method : public : GetDfModel() ~ FloatReturn
| Type | Description |
|---|---|
| Float | degrees of freedom |
GetDfResid #
Residual degrees of freedom, n - k.
method : public : GetDfResid() ~ FloatReturn
| Type | Description |
|---|---|
| Float | degrees of freedom |
GetError #
Why the fit failed, or an empty string.
method : public : GetError() ~ StringReturn
| Type | Description |
|---|---|
| String | reason |
GetFPValue #
p-value of the F statistic.
method : public : GetFPValue() ~ FloatReturn
| Type | Description |
|---|---|
| Float | p, NaN when F is NaN |
GetFStat #
F statistic of the whole model against the intercept-only (or empty) model.
method : public : GetFStat() ~ FloatReturn
| Type | Description |
|---|---|
| Float | F, NaN when the model has no predictors or the fit is exact |
GetFitted #
Fitted values.
method : public : GetFitted() ~ Float[]Return
| Type | Description |
|---|---|
| Float | fitted values, Nil when invalid |
GetLogLikelihood #
Gaussian log-likelihood.
method : public : GetLogLikelihood() ~ FloatReturn
| Type | Description |
|---|---|
| Float | log-likelihood |
GetNObs #
Number of observations.
method : public : GetNObs() ~ IntReturn
| Type | Description |
|---|---|
| Int | n, 0 when invalid |
GetNParams #
Number of coefficients, the intercept included.
method : public : GetNParams() ~ IntReturn
| Type | Description |
|---|---|
| Int | count |
GetNames #
Column names, in coefficient order (the intercept is "const").
method : public : GetNames() ~ String[]Return
| Type | Description |
|---|---|
| String | names, 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
| Type | Description |
|---|---|
| Float | p-values, Nil when invalid |
GetRSquared #
R-squared.
method : public : GetRSquared() ~ FloatReturn
| Type | Description |
|---|---|
| Float | R-squared, NaN when y does not vary |
GetResidualStdError #
Residual standard error: sqrt(SSR / (n - k)).
method : public : GetResidualStdError() ~ FloatReturn
| Type | Description |
|---|---|
| Float | residual standard error |
GetResiduals #
Residuals, y minus the fitted values.
method : public : GetResiduals() ~ Float[]Return
| Type | Description |
|---|---|
| Float | residuals, Nil when invalid |
GetSSR #
Residual sum of squares.
method : public : GetSSR() ~ FloatReturn
| Type | Description |
|---|---|
| Float | sum of squared residuals |
GetStdErrors #
Standard errors of the coefficients.
method : public : GetStdErrors() ~ Float[]Return
| Type | Description |
|---|---|
| Float | standard errors, Nil when invalid |
GetTStats #
t statistics of the coefficients (coefficient / standard error).
method : public : GetTStats() ~ Float[]Return
| Type | Description |
|---|---|
| Float | t statistics, Nil when invalid |
HasIntercept #
Whether the fit has an intercept.
method : public : HasIntercept() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if the first column is the intercept |
IsValid #
Whether the fit succeeded.
method : public : IsValid() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true 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
| Name | Type | Description |
|---|---|---|
| X | Float | feature rows |
Return
| Type | Description |
|---|---|
| Float | predictions, Nil when invalid, X is Nil or the column count is wrong |