regression-js Compatibility
npm install @statili/compat-regression
Drop-in replacement for regression (regression-js), which has been unchanged since December 2017.
Same five methods, same result shape, same equation strings — with four defects fixed and a way to find out when a fit failed.
Install
npm install @statili/compat-regression
Usage
- import regression from "regression";
+ import regression from "@statili/compat-regression";
const result = regression.linear([[0, 1], [32, 67], [12, 79]]);
result.equation; // [gradient, intercept]
result.string; // "y = 1.79x + 22.75"
result.r2; // 0.48
result.predict(5); // [5, 31.7]
linear, exponential, logarithmic, power, polynomial and _round all keep their signatures. ESM and UMD are both published, so require() works as before.
What changed
Two additive fields tell you when a fit could not be produced — something the original API has no room to express, which is why it answers a vertical line with a confident horizontal one:
const result = regression.linear([[1, 1], [1, 2], [1, 3]]);
result.ok; // false
result.error.type; // "DegenerateInput"
result.error.message; // "Cannot perform linear regression: all x-values are identical…"
Existing code ignores unknown properties and keeps working.
It also fixes a null-row bug that silently corrupted logarithmic and power — a single gap row moved a fitted exponent by 55%.
Writing new code?
Use @statili/stats directly. It has a discriminated-union result, named coefficients, significance testing, confidence intervals, and models the original never had.
License
MIT