regression-js

Regression-js is a javascript module containing a collection of linear least-squares fitting methods for simple data analysis. It can be found on github.

Installation

This module works on node and in the browser. It is available as the regression package on npm. It is also available on a CDN.

npm

npm install --save regression

Usage


  import regression from 'regression';
  const result regression.linear([[0, 1], [32, 67], [12, 79]]);
  const gradient = result.equation[0];
  const yIntercept = result.equation[1];
      

Data is passed into the model as an array. A second parameter can be used to configure the model. The configuration parameter is optional. `null` values are ignored. The precision option will set the number of significant figures the output is rounded to.

Configuration options

Below are the default values for the configuration parameter.


{
  order: 2,
  precision: 2,
}
      

Properties

API

Linear

equation: [gradient, y-intercept] in the form y = mx + c

Exponential

equation: [a, b] in the form y = aebx

Logarithmic

equation: [a, b] in the form y = a + b ln x

Power law

equation: [a, b] in the form y = axb

Polynomial

equation: [ai, .... , a0] in the form aixj ... + a0x0


        var data = [[0,1],[32, 67] .... [12, 79]];
        var result = regression.polynomial(data, { order: 3 });