# How to use the simple-statistics.standardDeviation 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.

tes / seguir / benchmark / index.js View on Github
``````}, function (err, result) {
process.stdout.write(' DONE!\n\n');
if (err) {
console.log(err);
process.exit(1);
}

console.log('Response Times:');
console.log('Min: ' + Math.floor(ss.min(result)) + 'ms');
console.log('Max: ' + Math.floor(ss.max(result)) + 'ms');
console.log('95th: ' + Math.floor(ss.quantile(result, 0.95)) + 'ms');
console.log('Std Dev: ' + Math.floor(ss.standardDeviation(result)) + 'ms');

console.log('\nRedis Cache:');
redisStats(api);

console.log('\nUser Cache:');
userStats(api);

process.exit(0); // TODO shutdown cleanly

api.client._client.shutdown();
});
}``````
koopjs / winnow / src / generateBreaks / utils.js View on Github
``````function calculateStdDevIntervals (values, classification) {
if (!classification.stddev_intv) throw new Error('must supply a standard deviation interval')
const intv = classification.stddev_intv
if (intv !== 0.25 &amp;&amp; intv !== 0.33 &amp;&amp; intv !== 0.5 &amp;&amp; intv !== 1) throw new Error('Unacceptable interval value: ' + intv)

const mean = ss.mean(values)
const stddev = ss.standardDeviation(values)
const breakCount = classification.breakCount
const intervals = []

// create interval around mean
const minMeanInt = Number((mean - (0.5 * stddev)).toFixed(6))
const maxMeanInt = Number((mean + (0.5 * stddev)).toFixed(6))
intervals.unshift(minMeanInt)
intervals.push(maxMeanInt)

// create positive &amp; negative stddev intervals
let maxPosStd, minNegStd
for (let i = 1; i &lt;= breakCount; i++) {
minNegStd = Number((minMeanInt - (i * stddev)).toFixed(6))
maxPosStd = Number((maxMeanInt + (i * stddev)).toFixed(6))
intervals.unshift(minNegStd)
intervals.push(maxPosStd)``````
antvis / data-set / test / unit / api / statistics-spec.ts View on Github
``````callback(row) {
row.year = parseInt(row.year, 10);
return row;
},
});
const years = dv.getColumn('year');
expect(dv.max('year')).to.equal(max(years));
expect(dv.min('year')).to.equal(min(years));
expect(dv.mean('year')).to.equal(mean(years));
expect(dv.average('year')).to.equal(mean(years));
expect(dv.median('year')).to.equal(median(years));
expect(dv.mode('year')).to.equal(mode(years));
expect(dv.quantile('year', 0.5)).to.equal(quantile(years, 0.5));
expect(dv.quantiles('year', [0, 0.1, 0.5])).to.eql(map([0, 0.1, 0.5], (p) => quantile(years, p)));
expect(dv.quantilesByFraction('year', 4)).to.eql(map([0, 0.25, 0.5, 0.75, 1], (p) => quantile(years, p)));
expect(dv.standardDeviation('year')).to.equal(standardDeviation(years));
expect(dv.sum('year')).to.equal(sum(years));
expect(dv.variance('year')).to.equal(variance(years));
expect(dv.range('year')).to.eql([min(years), max(years)]);
});``````
antvis / data-set / test / unit / api / statistics-spec.ts View on Github
``````data.push({
a: [i, i + 10, [-i, i * i, [-i * i, 1 / i]]],
});
}
const dv = new DataSet.View().source(data);
const values = flattenDeep(dv.getColumn('a'));
expect(dv.max('a')).to.equal(max(values));
expect(dv.min('a')).to.equal(min(values));
expect(dv.mean('a')).to.equal(mean(values));
expect(dv.average('a')).to.equal(mean(values));
expect(dv.median('a')).to.equal(median(values));
expect(dv.mode('a')).to.equal(mode(values));
expect(dv.quantile('a', 0.5)).to.equal(quantile(values, 0.5));
expect(dv.quantiles('a', [0, 0.1, 0.5])).to.eql(map([0, 0.1, 0.5], (p) => quantile(values, p)));
expect(dv.quantilesByFraction('a', 4)).to.eql(map([0, 0.25, 0.5, 0.75, 1], (p) => quantile(values, p)));
expect(dv.standardDeviation('a')).to.equal(standardDeviation(values));
expect(dv.sum('a')).to.equal(sum(values));
expect(dv.variance('a')).to.equal(variance(values));
expect(dv.range('a')).to.eql([min(values), max(values)]);
});
});``````
RequestNetwork / requestNetwork / packages / prototype-estimator / src / calculateLatency.ts View on Github
```````\${getChannelsByTopicCount +
getTransactionsByChannelIdCount +
persistTransactionCount} requests`,
);
console.log(`\${getChannelsByTopicCount} getChannelsByTopic requests`);
console.log(`\${getTransactionsByChannelIdCount} getTransactionsByChannelId requests`);
console.log(`\${persistTransactionCount} persistTransaction requests`);

if (getChannelsByTopicCount > 0) {
console.log(`\ngetChannelsByTopic statistics`);
console.log(`average: \${simpleStatistics.mean(getChannelsByTopicTimes)}`);
console.log(`median: \${simpleStatistics.median(getChannelsByTopicTimes)}`);
console.log(`min: \${simpleStatistics.min(getChannelsByTopicTimes)}`);
console.log(`max: \${simpleStatistics.max(getChannelsByTopicTimes)}`);
console.log(
`standard deviation: \${simpleStatistics.standardDeviation(getChannelsByTopicTimes)}`,
);
}
if (getTransactionsByChannelIdCount > 0) {
console.log(`\ngetTransactionsByChannelId statistics`);
console.log(`average: \${simpleStatistics.mean(getTransactionsByChannelIdTimes)}`);
console.log(`median: \${simpleStatistics.median(getTransactionsByChannelIdTimes)}`);
console.log(`min: \${simpleStatistics.min(getTransactionsByChannelIdTimes)}`);
console.log(`max: \${simpleStatistics.max(getTransactionsByChannelIdTimes)}`);
console.log(
`standard deviation: \${simpleStatistics.standardDeviation(getTransactionsByChannelIdTimes)}`,
);
}
if (persistTransactionCount > 0) {
console.log(`\npersistTransaction statistics`);
console.log(`average: \${simpleStatistics.mean(persistTransactionTimes)}`);
console.log(`median: \${simpleStatistics.median(persistTransactionTimes)}`);``````
RequestNetwork / requestNetwork / packages / prototype-estimator / src / calculateLatency.ts View on Github
``````console.log(`average: \${simpleStatistics.mean(getTransactionsByChannelIdTimes)}`);
console.log(`median: \${simpleStatistics.median(getTransactionsByChannelIdTimes)}`);
console.log(`min: \${simpleStatistics.min(getTransactionsByChannelIdTimes)}`);
console.log(`max: \${simpleStatistics.max(getTransactionsByChannelIdTimes)}`);
console.log(
`standard deviation: \${simpleStatistics.standardDeviation(getTransactionsByChannelIdTimes)}`,
);
}
if (persistTransactionCount > 0) {
console.log(`\npersistTransaction statistics`);
console.log(`average: \${simpleStatistics.mean(persistTransactionTimes)}`);
console.log(`median: \${simpleStatistics.median(persistTransactionTimes)}`);
console.log(`min: \${simpleStatistics.min(persistTransactionTimes)}`);
console.log(`max: \${simpleStatistics.max(persistTransactionTimes)}`);
console.log(
`standard deviation: \${simpleStatistics.standardDeviation(persistTransactionTimes)}`,
);
}
});``````
mozilla-frontend-infra / firefox-health-dashboard / src / crashes.js View on Github
``````releases.forEach((release) => {
release.hours = sumBy(release.builds, 'hours');
const rates = release.builds
.map(({ rate }) => rate)
.filter(rate => rate > 0);
const contentRates = release.builds
.map(({ contentRate }) => contentRate)
.filter(contentRate => contentRate > 0);
if (rates.length > 0) {
release.rate = geometricMean(rates) || 0;
release.contentRate = geometricMean(contentRates) || 0;
release.variance = standardDeviation(rates) || 0;
}
});
ctx.body = releases;``````
JeffRMoore / async-benchmark-runner / src / report / statistics.js View on Github
``````export function marginOfError(samples: Array): number {
const toPercent = 100;
const confidenceLevel = 0.95;
const sampleMean = mean(samples);
const standardError = standardDeviation(samples) / Math.sqrt(samples.length);
const degreesOfFreedom = samples.length - 1;
const interval = confidenceIntervalForT(
sampleMean,
standardError,
degreesOfFreedom,
confidenceLevel
);
return (((interval[1] - sampleMean) / sampleMean) * toPercent) || 0;
}``````
antvis / data-set / src / util / bandwidth.js View on Github
``````nrd(x) {
let s = standardDeviation(x);
const iqr = interquartileRange(x);
if (typeof iqr === 'number') {
s = Math.min(s, iqr / 1.34);
}
return 1.06 * s * Math.pow(x.length, -0.2);
}
};``````

## simple-statistics

Simple Statistics

ISC