Module Algostream_pairs.Ols

Small-dim ordinary least squares via Gram matrix + Cholesky.

Designed for p ≤ 5 regressors — the ADF and AR(1) half-life fits used by this library. A Tikhonov ridge of 1e-12 · I is added before factorization so a singular Gram matrix becomes a clean `Singular error rather than a NaN cascade. Regressors are NOT auto-centred; callers that include an intercept column must hand it a column of ones.

type fit = {
  1. beta : float array;
  2. se : float array;
    (*

    standard errors of beta

    *)
  3. rss : float;
  4. tss : float;
  5. n : int;
  6. p : int;
}
type error = [
  1. | `Singular
  2. | `Underdetermined of int * int
    (*

    n, p

    *)
]
val solve : x:float array array -> y:float array -> p:int -> (fit, error) Stdlib.result

Solve A · β = y in the least-squares sense, returning β and per-coefficient SE. x is row-major: x.(i).(j) is the j-th regressor for the i-th observation.

val regress2 : x:float array -> y:float array -> (float * float * float, error) Stdlib.result

Convenience: simple intercept-plus-slope regression. Returns (intercept, slope, r_squared).