Documentation

Logarithmic Regression

@statili/stats ·v0.0.2-beta.0 ·1 export

signatures
logarithmic(arg1: Partial<RegressionOptions>): (args_0: DataPoint[]) => RegressionResult
logarithmic(suppliedOptions: Partial<RegressionOptions>, data: DataPoint[]): RegressionResult
Performs logarithmic regression to model the relationship y = a + b · ln(x).

The model captures scenarios where Y grows (or decays) rapidly at first then progressively levels off as X increases — the classic diminishing-returns pattern.

Domain constraint: x must be strictly positive (> 0). Points with x ≤ 0 are silently excluded because ln(x) is undefined for non-positive values.

Parameters

NameTypeDescription
suppliedOptions Partial<RegressionOptions> Optional { precision } overrides.
data DataPoint[] Array of [x, y] tuples (requires x > 0).

Returns

RegressionResult

Discriminant union:

  • ok: true — includes slope (b — coefficient of ln x), intercept (a), r2, rmse, n, equation, predict.
  • ok: false — includes errorType and message.
insight
  • Growth directionslope (b): positive → Y grows and levels off; negative → Y decays and levels off.
  • Rate of change at X = 1 — equals slope / 1 = slope (derivative of the model at x = 1).
  • Diminishing returns signal — when slope > 0, each subsequent unit increase in X produces a smaller gain in Y (classic law of diminishing returns).
  • Goodness of fitr2 and rmse.
  • Baselineintercept (a) is the predicted Y when x = 1.

Examples

// Diminishing-returns growth: y ≈ 5·ln(x)
const data: DataPoint[] = [[1,0],[2,3.5],[4,6.9],[8,10.4],[16,13.9],[32,17.3]];
const result = logarithmic({}, data);
if (result.ok) {
  console.log(result.equation);       // "y = 0 + 5·ln(x)"
  console.log(result.slope);          // ≈ 5    (b — rate of log growth)
  console.log(result.intercept);      // ≈ 0    (a — y when x = 1)
  console.log(result.predict(64)[1]); // ≈ 20.7
}
// Curried / partial application (data-last)
const fitLog = logarithmic({ precision: 3 });
const result = fitLog(data);