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
- ChiSquareCdf
- ChiSquareSf
- Div
- FCdf
- FSf
- GammaInc
- HedgesJ
- LogGamma
- NormalCdf
- NormalQuantile
- NormalTwoSidedP
- StudentCdf
- StudentQuantile
- StudentTwoSidedP
BetaInc # function
The regularized incomplete beta function I_x(a, b).
function : BetaInc(x:Float, a:Float, b:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | between 0 and 1 |
| a | Float | shape, above 0 |
| b | Float | shape, above 0 |
Return
| Type | Description |
|---|---|
| Float | value between 0 and 1, NaN outside the domain |
ChiSquareCdf # function
Cumulative distribution function of the chi-square distribution.
function : ChiSquareCdf(x:Float, df:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | the value, 0 or more |
| df | Float | degrees of freedom, above 0 |
Return
| Type | Description |
|---|---|
| Float | P(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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | the statistic, 0 or more |
| df | Float | degrees of freedom, above 0 |
Return
| Type | Description |
|---|---|
| Float | probability, 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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| a | Float | dividend |
| b | Float | divisor |
Return
| Type | Description |
|---|---|
| Float | the quotient |
FCdf # function
Cumulative distribution function of the F distribution.
function : FCdf(f:Float, df1:Float, df2:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| f | Float | the value, 0 or more |
| df1 | Float | numerator degrees of freedom, above 0 |
| df2 | Float | denominator degrees of freedom, above 0 |
Return
| Type | Description |
|---|---|
| Float | P(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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| f | Float | the statistic, 0 or more |
| df1 | Float | numerator degrees of freedom, above 0 |
| df2 | Float | denominator degrees of freedom, above 0 |
Return
| Type | Description |
|---|---|
| Float | probability, NaN outside the domain |
GammaInc # function
The regularized lower incomplete gamma function P(a, x).
function : GammaInc(a:Float, x:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| a | Float | shape, above 0 |
| x | Float | argument, 0 or more |
Return
| Type | Description |
|---|---|
| Float | value 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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| df | Float | degrees of freedom, 1 or more |
Return
| Type | Description |
|---|---|
| Float | the 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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | argument, above 0 |
Return
| Type | Description |
|---|---|
| Float | log(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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| x | Float | the value |
Return
| Type | Description |
|---|---|
| Float | P(Z <= x), NaN when x is NaN |
NormalQuantile # function
Quantile (inverse CDF) of the standard normal distribution.
function : NormalQuantile(p:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| p | Float | probability, strictly between 0 and 1 |
Return
| Type | Description |
|---|---|
| Float | z 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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| z | Float | the statistic |
Return
| Type | Description |
|---|---|
| Float | probability, NaN when z is NaN |
StudentCdf # function
Cumulative distribution function of the Student t distribution.
function : StudentCdf(t:Float, df:Float) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| t | Float | the statistic |
| df | Float | degrees of freedom, above 0 |
Return
| Type | Description |
|---|---|
| Float | P(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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| p | Float | probability, strictly between 0 and 1 |
| df | Float | degrees of freedom, above 0 |
Return
| Type | Description |
|---|---|
| Float | t with P(T <= t) = p, NaN outside the domain |