Documentation

Exponential

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

signatures
exponential(arg1: Partial<RegressionOptions>): (args_0: DataPoint[]) => RegressionResult
exponential(suppliedOptions: Partial<RegressionOptions>, data: DataPoint[]): RegressionResult
Performs exponential regression to model the relationship y = a · e^(bx).

Captures constant proportional growth or decay — compound interest, viral spread, radioactive decay, unchecked adoption. The defining property is that Y multiplies by a fixed factor for each equal step in X, rather than adding a fixed amount as in linear regression.

Domain constraint: y must be strictly positive (> 0). Points with y ≤ 0 are excluded, because ln(y) is undefined there.

Parameters

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

Returns

RegressionResult

Discriminant union:

  • ok: true — includes slope (growth rate b), intercept (initial value a), r2, rmse, n, equation, predict.
  • ok: false — includes errorType and message.
insight
  • Growth or decayslope (b) positive means growth, negative means decay.
  • Doubling / halving timeln(2) / b is the X interval over which Y doubles (or, for negative b, halves).
  • Per-step multiplier — Y is multiplied by e^b for each unit increase in X.
  • Starting valueintercept (a) is the predicted Y at x = 0.
  • Goodness of fitr2 and rmse.

Examples

// Compound growth: y ≈ 2·e^(0.5x)
const data: DataPoint[] = [[1, 3.3], [2, 5.4], [3, 9], [4, 14.8], [5, 24.4]];
const result = exponential({}, data);
if (result.ok) {
  console.log(result.equation);        // "y = 2e^(0.5x)"
  console.log(result.slope);           // ≈ 0.5  (b — growth rate)
  console.log(result.intercept);       // ≈ 2    (a — value at x = 0)
  console.log(result.predict(6)[1]);   // ≈ 40.2
}
// Curried / partial application (data-last)
const fitExponential = exponential({ precision: 4 });
const result = fitExponential(data);