How to use the simple-statistics/src/quantile.default 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.

TerriaJS / terriajs / lib / Models / LegendHelper.js View on Github
``````var method = tableColumnStyle.colorBinMethod.toLowerCase();
if (method === "auto") {
if (numericalValues.length &gt; 1000) {
// The quantile method is simpler and less accurate, but faster for large datasets.
method = "quantile";
} else {
method = "ckmeans";
}
}

if (method === "quantile") {
// One issue is we don't check to see if any values actually lie within a given quantile, so it's bad for small datasets.
for (i = 0; i &lt; binCount; i++) {
binColors.push({
upperBound: quantile(numericalValues, (i + 1) / binCount),
i / (binCount - 1)
)
});
}
} else if (method === "ckmeans") {
var clusters = ckmeans(numericalValues, binCount);
// Convert the ckmeans format [ [5, 20], [65, 80] ] into our format.
for (i = 0; i &lt; clusters.length; i++) {
if (
i &gt; 0 &amp;&amp;
clusters[i].length === 1 &amp;&amp;
clusters[i][0] === clusters[i - 1][clusters[i - 1].length - 1]
) {
// When there are few unique values, we can end up with clusters like [1], [2],[2],[2],[3]. Let's avoid that.``````

simple-statistics

Simple Statistics

ISC