# How to use the simple-statistics.linear_regression function in simple-statistics

## To help you get started, weâ€™ve selected a few simple-statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

dmoll1974 / targets-io / app / controllers / testruns.server.controller.js View on Github
``````function calculateLinearFit(datapoints){

var data = [];

for(var j=0;j&lt; datapoints.length;j++){

if(datapoints[j][0] !== null) {
data.push([j, datapoints[j][0]]);
}
}

var line = ss.linear_regression()
.data(data)
.line()

.data(data)
.m()
//winston.info('stijgings percentage: ' + (line(data.length-1)-line(0))/ line(0)) / data.length * 100;
//winston.info('line(0): ' + line(0));
//winston.info('line(data.length-1): ' + line(data.length-1));

/* if no valid number is calculated, return null*/

var result = !isNaN(Math.round(((((line(data.length-1)-line(0))/ line(0)) / data.length) * 100 * 100)* 100) / 100) ? Math.round(((((line(data.length-1)-line(0))/ line(0)) / data.length) * 100 * 100)* 100) / 100 : null;

return result;``````
selfhub / selfhub / client / js / components / chart.jsx View on Github
``````tplot[0].shift();
tplot[1].shift();

var graphPoints = _.zip(tplot[0], tplot[1]);
var xs = {};

var regressionDataLabel = "regression";
xs[schemaName] = schemaName + "_x";
xs[regressionDataLabel] = regressionDataLabel + "_x";

var scatterPlotArray = transformCSVtoScatterPlot(csvData, schemaName, xIndex, yIndex);

var min = Math.min.apply(null, tplot[0]);
var max = Math.max.apply(null, tplot[0]);
/* jshint ignore:start */
var regressionEquation = stats.linear_regression().data(graphPoints).line();

var minRegressionY = regressionEquation(min);
var maxRegressionY = regressionEquation(max);

scatterPlotArray.push([regressionDataLabel, minRegressionY, maxRegressionY],
[regressionDataLabel + "_x", min, max]);
/* jshint ignore:end */
var types = {};
types[regressionDataLabel] = "line";

var chart = c3.generate({
bindto: ".visualization-view",
data: {
xs: xs,
// Data Format:
// y row ['dataname', num, num, ...]``````
gcgibson / NTM / copyTaskAbstractor.js View on Github
``````function shiftRegression(shiftingArray){
//construct input output pairs for regression based on shifting array
var localIOPairs = [];

for(var i =0; i &lt; shiftingArray.length; i+=2){
var tmp = [];
for (var j =0; j``````
gcgibson / NTM / copyTaskAbstractor.js View on Github
``````function linearRegression(ipoppw){
var linear_regression_line = ss.linear_regression()
.data(ipoppw).line();

return linear_regression_line;
}``````
gcgibson / NTM / copyTaskAbstractor.js View on Github
``````function linearRegressionOverVectors(inputOututPairs){
var finalResultVector= [];

for (var k =0; k &lt; inputOututPairs.length-1; k++){
var pwDataResult = constructPairWiseData(inputOututPairs[k],inputOututPairs[k+1]);
var linear_regression = ss.linear_regression()
.data(pwDataResult);
finalResultVector.push(linear_regression.m());
}
return finalResultVector;
}``````
gcgibson / NTM / copyTaskAbstractor.js View on Github
``````function lengthRegression(inputOututPairs){

var lengthRegressionInput = [[]];
for(var  i=0; i &lt; inputOututPairs.length-1; i+=2){
lengthRegressionInput.push([inputOututPairs[i].length,inputOututPairs[i+1].length]);
}
lengthRegressionInput.shift();

var linear_length_regression = ss.linear_regression()
.data(lengthRegressionInput);
return linear_length_regression;
}
function linearRegressionOverVectors(inputOututPairs){``````

## simple-statistics

Simple Statistics

ISC

67 / 100