Documentation

Types

@statili/stats ·v0.0.2-beta.0 ·14 exports

signature
interface Interval {
  /** The fitted value at x — the centre of the range. */
  fit: number;
  lower: number;
  upper: number;
}
A fitted value with an uncertainty range around it.

# LogisticRegressionOptions interface

packages/stats/src/regression/types.ts:141
signature
interface LogisticRegressionOptions {
  /** Gradient descent learning rate. @default 0.1 */
  learningRate: number;
  /** Number of gradient descent iterations. @default 1000 */
  iterations: number;
  /** Decimal places for rounding. @default 4 */
  precision: number;
}

# MultiRegressionError interface

packages/stats/src/regression/types.ts:132
signature
interface MultiRegressionError {
  ok: false;
  method?: "multilinear" | "logistic";
  errorType: RegressionErrorType;
  message: string;
}

# MultiRegressionSuccess interface

packages/stats/src/regression/types.ts:114
signature
interface MultiRegressionSuccess {
  ok: true;
  method: "multilinear" | "logistic";
  /** [intercept, b1, b2, ..., bk] */
  coefficients: number[];
  numFeatures: number;
  /** R2 for multilinear; McFadden pseudo-R2 for logistic. */
  r2: number;
  /** RMSE on training set. NaN for logistic. */
  rmse: number;
  n: number;
  points: PredictedMultiPoint[];
  predict: (x: number[]) => PredictedMultiPoint;
  equation: string;
  /** Training accuracy at 0.5 threshold (logistic only). */
  accuracy?: number;
}

# RegressionError interface

packages/stats/src/regression/types.ts:81
signature
interface RegressionError {
  ok: false;
  method?: "linear" | "logarithmic" | "exponential" | "power" | "polynomial";
  errorType: RegressionErrorType;
  message: string;
}

# RegressionOptions interface

packages/stats/src/regression/types.ts:98
signature
interface RegressionOptions {
  /** Decimal places for rounding. @default 2 */
  precision: number;
  /**
   * Confidence level for intervals, in `(0, 1)`. @default 0.95
   */
  confidenceLevel?: number;
  /** Polynomial degree (polynomial() only). @default 2 */
  order?: number;
}

# RegressionSuccess interface

packages/stats/src/regression/types.ts:11
signature
interface RegressionSuccess {
  ok: true;
  /** Primary slope / rate-of-change coefficient.
   * linear: slope m | polynomial: c1 | power: exponent b | logarithmic: ln-coeff b */
  slope: number;
  /** Y-intercept or constant term.
   * linear: y-int | polynomial: c0 | power: scale a | logarithmic: constant a */
  intercept: number;
  /** Coefficient of determination R2 in [0,1]. */
  r2: number;
  /** Root Mean Squared Error in the same units as Y. */
  rmse: number;
  /** Number of valid data points used. */
  n: number;
  method: "linear" | "logarithmic" | "exponential" | "power" | "polynomial";
  points: PredictedPoint[];
  predict: (x: number) => PredictedPoint;
  /** Full coefficient vector [c0,c1,...,cn] for polynomial. */
  coefficients?: number[];
  /** Polynomial degree. */
  degree?: number;
  /** Human-readable equation string. */
  equation?: string;
  // ── Inference on the slope ──────────────────────────────────────────────
  // Populated by `linear()` only. Left `undefined` by every other method —
  // polynomial needs the full coefficient covariance matrix, and the
  // log-linearised fits (power, logarithmic) would report significance in
  // transformed space, which is not what a caller would expect.
  //
  // All four are `null` when there are too few points to estimate them
  // (`n < 3`, i.e. `df < 1`), and `tM`/`pValueM` are additionally `null` for a
  /
// …truncated

Type shortened for readability — see the source for the full definition.

signature
type DataPoint = [number, number];
signature
type MultiDataPoint = { x: number[]; y: number | null };

# MultiRegressionResult type

packages/stats/src/regression/types.ts:139
signature
type MultiRegressionResult = MultiRegressionSuccess | MultiRegressionError;
signature
type PredictedMultiPoint = { x: number[]; y: number };
signature
type PredictedPoint = [number, number];

# RegressionErrorType type

packages/stats/src/regression/types.ts:4
signature
type RegressionErrorType =
  | "InsufficientData"
  | "DegenerateInput"
  | "MathError"
  | "InvalidInput"
  | "NumericalStability";
signature
type RegressionResult = RegressionSuccess | RegressionError;