lfirek/regression-trend · linear.js
javascript logo
function generate(data) {
    let equation, n, sumX, sumY, sumXY, sumPowX, aveY, aveX, pointsArray;

    pointsArray = [];
    
    equation = {
        a: 0,
        b: 0
    };

    n = sumX = sumY = sumXY = sumPowX = aveY = aveX = 0;
    let i;

    for (i = 0; i < data.length; i++) {

        if (data[i].y !== null) {
            n++;
            sumX += data[i].x;
            sumY += data[i].y;
            sumXY += data[i].x * data[i].y;
            sumPowX += Math.pow(data[i].x,2);
        }
    }
    aveY = sumY / n;
    aveX = sumX / n;
    equation.b = (n * sumXY - sumX * sumY) / (n * sumPowX - sumX * sumX);
    equation.a = aveY - equation.b * aveX;

    for (i = 0; i < data.length; i++) {
        pointsArray.push(
            {
                x: data[i].x,
                y: trend(equation, data[i].y)
            }
        );
    }

    return {
        equation: equation,
        points: pointsArray,
        pattern: "y = " + equation.a + " + " + equation.b + " * x"
    };
}
Similar code snippets
1.
crokita/functionite · example6.js
Match rating: 65.01% · See similar code snippets
javascript logo
function (callback) {
	var sum = 0;
	for (let i = 0; i < 10; i++) {
		sum += i;
	}
	store.sum = sum;
	callback();
}
2.
Tom-Alexander/regression-js · regression.min.js
Match rating: 64.55% · See similar code snippets
javascript logo
function exponential(data,options){var sum=[0,0,0,0,0,0];for(var n=0;n<data.length;n++){if(data[n][1]!==null){sum[0]+=data[n][0];sum[1]+=data[n][1];sum[2]+=data[n][0]*data[n][0]*data[n][1];sum[3]+=data[n][1]*Math.log(data[n][1]);sum[4]+=data[n][0]*data[n][1]*Math.log(data[n][1]);sum[5]+=data[n][0]*data[n][1]}}var denominator=sum[1]*sum[2]-sum[5]*sum[5];var a=Math.exp((sum[2]*sum[3]-sum[5]*sum[4])/denominator);var b=(sum[1]*sum[4]-sum[5]*sum[3])/denominator;var coeffA=round(a,options.precision);var coeffB=round(b,options.precision);var predict=function predict(x){return[round(x,options.precision),round(coeffA*Math.exp(coeffB*x),options.precision)]};var points=data.map(function(point){return predict(point[0])});return{points:points,predict:predict,equation:[coeffA,coeffB],string:"y = "+coeffA+"e^("+coeffB+"x)",r2:round(determinationCoefficient(data,points),options.precision)}}
3.
ccc-js/j6 · statistics.js
Match rating: 63.91% · See similar code snippets
javascript logo
function (a) {
    var sum = j6.T.sum(a)
    return a.map(function (x) { return x / sum })
  }
4.
gammasoft/utils · mathUtils.js
Match rating: 63.29% · See similar code snippets
javascript logo
function(samples) {
    var length = samples.length,
        sumOfX = 0,
        sumOfY = 0,
        sumOfXY = 0,
        sumOfXX = 0;

    samples.forEach(function(sample) {
        sumOfX += sample.x;
        sumOfY += sample.y;
        sumOfXY += sample.x * sample.y;
        sumOfXX += sample.x * sample.x;
    });

    var divisor = ((length * sumOfXX) - (sumOfX * sumOfX)),
        a = ((sumOfXX * sumOfY) - (sumOfXY * sumOfX)) / divisor,
        b = ((length * sumOfXY) - (sumOfX * sumOfY)) / divisor;

    return {
        a: a,
        b: b,
        fn: function(x) {
            return a + (b * x);
        }
    };
}
5.
NaturalNode/natural · Distribution.js
Match rating: 59.85% · See similar code snippets
javascript logo
function() {
  var sum = 0;
  var that = this;
  this.sample.elements.forEach(function(x) {
      sum += that.calculateAPriori(x);
  });
  //console.log("Distribution.checkSum is " + sum);
  return sum;
}
6.
PaulAvery/node-tdir · scan.js
Match rating: 57.38% · See similar code snippets
javascript logo
function(sum, name) {
			sum[name] = readAny(path.join(pth, name), regex, encoding);
			return sum;
		}
7.
rajgoel/reveal.js-plugins · ruleJS.all.full.js
Match rating: 56.56% · See similar code snippets
javascript logo
function cdf(x, l) {
    var sumarr = [],
    k = 0;
    if (x < 0) return 0;
    for (; k <= x; k++) {
      sumarr.push(jStat.poisson.pdf(k, l));
    }
    return jStat.sum(sumarr);
  }
8.
ifct2017/compositions · build.js
Match rating: 55.98% · See similar code snippets
javascript logo
function sumAll(d) {
  for(var [k, exp] of sums) {
    var sumk = exp.replace(/\s/g, '').split('+'); d[k] = [];
    for(var i=0; i<di; i++)
      d[k][i] = round(sumColumns(d, i, sumk));
  }
}
9.
filerjs/filer · simple_statistics.js
Match rating: 55.36% · See similar code snippets
javascript logo
function r_squared(data, f) {
        if (data.length < 2) return 1;

        // Compute the average y value for the actual
        // data set in order to compute the
        // _total sum of squares_
        var sum = 0, average;
        for (var i = 0; i < data.length; i++) {
            sum += data[i][1];
        }
        average = sum / data.length;

        // Compute the total sum of squares - the
        // squared difference between each point
        // and the average of all points.
        var sum_of_squares = 0;
        for (var j = 0; j < data.length; j++) {
            sum_of_squares += Math.pow(average - data[j][1], 2);
        }

        // Finally estimate the error: the squared
        // difference between the estimate and the actual data
        // value at each point.
        var err = 0;
        for (var k = 0; k < data.length; k++) {
            err += Math.pow(data[k][1] - f(data[k][0]), 2);
        }

        // As the error grows larger, its ratio to the
        // sum of squares increases and the r squared
        // value grows lower.
        return 1 - (err / sum_of_squares);
    }
10.
muaz-khan/FileBufferReader · PeerUI.js
Match rating: 54.41% · See similar code snippets
javascript logo
function calculateAverage(arr) {
        var sum = 0;
        for (var i = 0; i < arr.length; i++) {
            sum += parseInt(arr[i], 10); //don't forget to add the base
        }

        var avg = sum / arr.length;
        return avg.toFixed(1);
    }