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.

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

  var data = [];

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

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

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

  var gradient = ss.linear_regression()
      .data(data)
      .m()
  //winston.info('stijgings percentage: ' + (line(data.length-1)-line(0))/ line(0)) / data.length * 100;
  //winston.info('gradient: ' + gradient * 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;
github selfhub / selfhub / client / js / components / chart.jsx View on Github external
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, ...]
github gcgibson / NTM / copyTaskAbstractor.js View on Github external
function shiftRegression(shiftingArray){
	//construct input output pairs for regression based on shifting array
	var localIOPairs = [];
	
	for(var i =0; i < shiftingArray.length; i+=2){
		var tmp = [];
		for (var j =0; j
github gcgibson / NTM / copyTaskAbstractor.js View on Github external
function linearRegression(ipoppw){
	var linear_regression_line = ss.linear_regression()
    .data(ipoppw).line();
			
    return linear_regression_line;
}
github gcgibson / NTM / copyTaskAbstractor.js View on Github external
function linearRegressionOverVectors(inputOututPairs){
	var finalResultVector= [];

	for (var k =0; k < 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;
}
github gcgibson / NTM / copyTaskAbstractor.js View on Github external
function lengthRegression(inputOututPairs){
	
	var lengthRegressionInput = [[]];
	for(var  i=0; i < 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){