statdist

package
v1.0.0-alpha.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package statdist holds the distribution primitives shared by the statistical operators: the Student-t tail, CDF, quantile and two-sided critical value, and the regularized incomplete beta they rest on.

It is a LEAF (stdlib only today; gonum is allowed) so both internal/processing (TEST_* operators, overlays) and internal/processing/regression (REG_* coefficient p-values, Bayes credible intervals) import one implementation without a cycle. TestStatdistImportBoundary enforces the ceiling.

Every primitive is checked against R to a relative 1e-10 by reference_oracle_test.go (goldens under internal/processing/testdata/reference/, regenerated with `make reference`).

Bit-identity note: the helpers keep their function boundaries (studentTBetaArgs, regularizedIncompleteBetaLog, logBeta, LgammaCorrection, betacf, newtonBracketed) on purpose. Go may fuse a*b+c into an FMA differently on arm64 once an operand is folded in across a boundary, so restructuring them can move results by an ulp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LgammaCorrection

func LgammaCorrection(x float64) float64

LgammaCorrection returns the Stirling remainder

δ(x) = lgamma(x) − ((x − ½)·log x − x + log √(2π))

for x ≥ 10 via its asymptotic series Σ B₂ₙ / (2n(2n−1) x^{2n−1}). Eight terms leave a truncation error below 1e-15 at x = 10. Exported for processing's incomplete-gamma prefactor (chi-square).

func RegularizedIncompleteBetaXY

func RegularizedIncompleteBetaXY(a, b, x, y float64) float64

RegularizedIncompleteBetaXY returns I_x(a, b) given x and y = 1 - x computed independently by the caller. Uses the continued-fraction expansion from Numerical Recipes (3rd ed.) Section 6.4, with the prefactor x^a y^b / B(a, b) assembled in log space from logBeta (Stirling-corrected, so no lgamma cancellation at large a or b).

func StudentTCDF

func StudentTCDF(t, df float64) float64

StudentTCDF returns P(T ≤ t) for T ~ t(df). Built on the same incomplete-beta identity as StudentTTwoSidedP — symmetry around zero pins the t < 0 branch.

func StudentTInverseTwoSided

func StudentTInverseTwoSided(alpha, df float64) float64

StudentTInverseTwoSided returns the q > 0 with P(|T| ≥ q) = alpha for df degrees of freedom — the two-sided critical value used for confidence-interval bounds.

Solved on log(p) by a bracketed Newton iteration (bisection fallback) on StudentTTwoSidedP, so the root is as accurate as the p-value itself in every tail — including df = 1, where q ≈ 2/(π·alpha) is far past any fixed search bracket. Returns NaN on degenerate inputs (df ≤ 0, alpha outside (0, 1), NaN).

func StudentTQuantile

func StudentTQuantile(p, df float64) float64

StudentTQuantile returns the inverse Student-t CDF at probability p: the t* with P(T ≤ t*) = p for T ~ t(df). By symmetry t* is ∓ the two-sided critical value at alpha = 2·min(p, 1−p) (1−p is exact for p ≥ ½).

Degenerate inputs: NaN p or df, or df ≤ 0 → NaN; p ≤ 0 → −Inf; p ≥ 1 → +Inf; p = 0.5 → 0 exactly.

func StudentTTwoSidedP

func StudentTTwoSidedP(t, df float64) float64

StudentTTwoSidedP returns the two-sided p-value of a Student's t statistic with df degrees of freedom: P(|T| ≥ |t|).

Derivation: the survival function of |T| equals the regularized incomplete beta I_x(df/2, 1/2) evaluated at x = df / (df + t²). Both x and its complement y = t² / (df + t²) are formed directly (never y = 1 - x), so a tiny t at large df keeps full precision.

Returns NaN for df ≤ 0 or a NaN input, 0 for |t| = ∞ and 1 for t = 0.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL