Exponential
# exponential function
packages/stats/src/regression/exponential.ts:49exponential(arg1: Partial<RegressionOptions>): (args_0: DataPoint[]) => RegressionResult
exponential(suppliedOptions: Partial<RegressionOptions>, data: DataPoint[]): RegressionResultPerforms 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
| Name | Type | Description |
|---|---|---|
| suppliedOptions | Partial<RegressionOptions> | Optional { precision } overrides. |
| data | DataPoint[] | Array of [x, y] tuples (requires y > 0). |
Returns
RegressionResultDiscriminant union:
ok: true— includesslope(growth rate b),intercept(initial value a),r2,rmse,n,equation,predict.ok: false— includeserrorTypeandmessage.
insight
- Growth or decay —
slope(b) positive means growth, negative means decay. - Doubling / halving time —
ln(2) / bis the X interval over which Y doubles (or, for negative b, halves). - Per-step multiplier — Y is multiplied by
e^bfor each unit increase in X. - Starting value —
intercept(a) is the predicted Y at x = 0. - Goodness of fit —
r2andrmse.
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);