0.0.3 • Published 5 years ago

@ethersage/quantile v0.0.3

Weekly downloads
34
License
ISC
Repository
github
Last release
5 years ago

quantile

CircleCI

This is currently under active development, but stable

Calculates quantiles and the corresponding buckets. An n-quantile is a set of n - 1 numbers representing the values that compose the n - 1 boundries of evenly bucketing the original set. For example, the 2-quantile of input = 1, 2, 3 is 2 found by trying to evenly divide the input into 2 buckets of numbers and calculating the value at the boundary between the two buckets. In this case, the buckets would be [1, 2, 3]. Since the first bucket has an extra item than the second, the second item of the first bucket (2) is the 2-quantile, or Median.

Note: Unevenly distributed buckets that produce a remainder will always add an extra items to each previous bucket until the remainer is exhausted. In this case, earlier buckets will have 1 more item than later buckets, depending on input.length / n.

Note: This package will not work with input sets shorter than n. You can't yet calculate the median of a single value, for example.

Setup

npm i @ethersage/quantile --save

Usage

const { bucket, quantile } = require('@ethersage/quantile');

bucket(2, [5, 6, 7, 8, 1, 2, 3, 4])); // => [[1, 2, 3, 4], [5, 6, 7, 8]]
bucket(3, [5, 6, 7, 8, 1, 2, 3, 4])); // => [[1, 2, 3], [4, 5, 6], [7, 8]]
bucket(3, [5, 6, 5, 3, 1, 2, 3, 4])); // => [[1, 2, 3], [3, 4, 5], [5, 6]]

quantile(2, [5, 6, 7, 8, 1, 2, 3, 4])); // => [4]
quantile(3, [5, 6, 7, 8, 1, 2, 3, 4])); // => [3, 6] 
quantile(3, [5, 6, 5, 3, 1, 2, 3, 4])); // => [3, 5]
0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

1.0.0

5 years ago