Skip to content

bjoern-hempel/js-regression-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Javascript regression framework

This is a javascript regression analysis framework.

0. Introduction

Regression analysis is a statistical analysis technique that aims to model relationships between a dependent variable and one or more independent variables.

1. Linear regression (2D)

Linear regression, which is a special case of the general concept of regression analysis, is a statistical technique that attempts to explain an observed dependent variable by one or more independent variables.

1.1 Preliminary considerations

1.1.1 Calculation of the slope m

m = \frac{\sum_{i=1}^n(x_i-\overline{x})(y_i-\overline{y})}{\sum_{i=1}^n(x_i-\overline{x})^2}

1.1.2 Calculation of the intercept b

b = \overline{y}-m \cdot \overline{x}

1.1.3 Calculation of the scope R2

R^2 = 1 - \frac{\sum_{i=1}^n(y_i-\hat{y}_i)^2}{\sum_{i=1}^n(y_i-\overline{y})^2}

1.2 Usage

Linear regression in 2-dimensional space, which is a special case of the general concept of regression analysis, is a statistical method that attempts to explain an observed dependent variable by one or more independent variables.

var regression = Regression.linear();

regression.addRecord(20,  0);
regression.addRecord(16,  3);
regression.addRecord(15,  7);
regression.addRecord(16,  4);
regression.addRecord(13,  6);
regression.addRecord(10, 10);

var mn = regression.calculate();

console.log(String('y(x) = %s * x + %s').replace(/%s/, mn.m).replace(/%s/, mn.n));

It returns:

y(x) = -0.9821428571428571 * x + 19.732142857142854

A. Authors

B. Licence

This tutorial is licensed under the MIT License - see the LICENSE.md file for details

C. Closing words

Have fun! :)