Power Regression
# power function
packages/stats/src/regression/power.ts:50power(arg1: Partial<RegressionOptions>): (args_0: DataPoint[]) => RegressionResult
power(suppliedOptions: Partial<RegressionOptions>, data: DataPoint[]): RegressionResultPerforms power law regression to model the relationship y = a · xᵇ.
The model is linearised by taking logarithms of both sides:
ln(y) = ln(a) + b·ln(x), which becomes a simple linear regression in
log-log space. The result is then transformed back to the original scale.
Domain constraints: both x and y must be strictly positive (> 0).
Points violating this constraint are silently excluded from the fit.
Parameters
| Name | Type | Description |
|---|---|---|
| suppliedOptions | Partial<RegressionOptions> | Optional { precision } overrides. |
| data | DataPoint[] | Array of [x, y] tuples (requires x > 0, y > 0). |
Returns
RegressionResultDiscriminant union:
ok: true— includesslope(exponent b),intercept(scale a),r2,rmse,n,equation,predict.ok: false— includeserrorTypeandmessage.
insight
- Growth regime —
slope(exponent b) controls the growth pattern:b > 1: super-linear / accelerating (economies of scale, network effects).0 < b < 1: sub-linear / diminishing returns (square-root laws).b ≈ 1: approximately proportional to X (linear relationship).b < 0: inverse — Y decreases as X increases.
- Doubling effect — when X doubles, Y is multiplied by
2^b. - Goodness of fit —
r2andrmse. - Scale —
intercept(a) is the predicted Y when X = 1.
Examples
const data: DataPoint[] = [[1,4],[4,8],[9,12],[16,16],[25,20]];
const result = power({}, data);
if (result.ok) {
console.log(result.equation); // "y = 4x^0.5"
console.log(result.slope); // ≈ 0.5 (exponent b)
console.log(result.intercept); // ≈ 4 (scale a)
console.log(result.predict(36)[1]); // ≈ 24
}// Curried / partial application (data-last)
const fitPower = power({ precision: 4 });
const result = fitPower(data);