fix(stats): hold the Student-t tails past t-squared overflow

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-27 17:03:36 +02:00
parent 2f9358c512
commit 275de79123
6 changed files with 113 additions and 10 deletions
+6 -4
View File
@@ -335,14 +335,16 @@ func LinearRegression(x, y *core.Array) (*LinearRegressionResult, error) {
// freedom, by the closed-form tail I_z(df/2, 1/2) with z = df/(df+t²).
// The identity is used rather than 2·(1 − T_cdf(t)): near t = 0 the
// subtraction cancels catastrophically, while the incomplete beta
// stays accurate into the far tail where p values matter most.
// stays accurate into the far tail where p values matter most. The
// upper-tail helper carries it, so the asymptotic forms that hold the
// df ≤ 2 tails past t²'s overflow serve here too: the bare closed form
// answers a silent 0 there while the true tail is still representable.
func twoSidedT(t float64, df int) (float64, error) {
z := float64(df) / (float64(df) + t*t)
p, err := BetaIncomplete(z, float64(df)/2, 0.5)
upper, err := studentTUpperTail(math.Abs(t), df)
if err != nil {
return 0, err
}
return p, nil
return 2 * upper, nil
}
// hasConstantColumn reports whether an (n, p) design holds a column of