How to use the simple-statistics.addToMean 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 bitrinjani / r2 / plugins / SimpleSpreadStatHandler.js View on Github external
async handle(spreadStat) {
    const newData = spreadStat.bestCase.profitPercentAgainstNotional;
    // add new data to mean
    this.profitPercentMean = ss.addToMean(this.profitPercentMean, this.sampleSize, newData);
    // add new data to variance
    this.profitPercentVariance = ss.combineVariances(
      this.profitPercentVariance,
      this.profitPercentMean,
      this.sampleSize,
      0,
      newData,
      1
    );

    this.sampleSize++;

    // set μ + σ to minTargetProfitPercent
    const n = this.sampleSize;
    const mean = this.profitPercentMean;
    const standardDeviation = Math.sqrt(this.profitPercentVariance * n/(n-1));
github projectriff / node-function-invoker / samples / streaming-mean / mean.js View on Github external
const meanStream = miss.through.obj((newValue, _, callback) => {
        mean = stats.addToMean(mean, n++, newValue);
        callback(null, mean);
    });
    inputs.$order[0].pipe(meanStream).pipe(outputs.$order[0]);
github codeformunich / radlquartier / datatool / preprocess / index-qhs.js View on Github external
for (var k = 0; k < 7; k++) {
                if (data.weekDays[k].length === 0) {
                    districtData.meanWeekDays[k] = 0;
                }
                else if (data.weekDays[k].length === 1) {
                    districtData.meanWeekDays[k] = data.weekDays[k][0];
                }
                else {
                    districtData.meanWeekDays[k] = ss.mean(data.weekDays[k]);
                }

                if (output.districts.length === 0) {
                    output.meanWeekDays[k] = districtData.meanWeekDays[k];
                }
                else {
                    output.meanWeekDays[k]  = ss.addToMean(output.meanWeekDays[k],
                        output.districts.length,
                        districtData.meanWeekDays[k]);
                }
            }

            districtData.meanDays = ss.mean(data.days);


            output.districts.push(districtData);
            callback();
        }
    );