Documentation

Power Regression

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

signatures
power(arg1: Partial<RegressionOptions>): (args_0: DataPoint[]) => RegressionResult
power(suppliedOptions: Partial<RegressionOptions>, data: DataPoint[]): RegressionResult
Performs 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

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

Returns

RegressionResult

Discriminant union:

  • ok: true — includes slope (exponent b), intercept (scale a), r2, rmse, n, equation, predict.
  • ok: false — includes errorType and message.
insight
  • Growth regimeslope (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 fitr2 and rmse.
  • Scaleintercept (a) is the predicted Y when X = 1.

Examples

Square-root growth: y ≈ 4√x
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);