Computes histogram bins for an array of values.
$ npm install compute-histogram
To use the module,
var computeHistogram = require( 'compute-histogram' );
Computes the histogram for the provided input array
. Returns a two dimensional array. The first dimension is the bin
index. The second dimension is the number of items in the bin.
var arr = [ 8, 2, 3, 9, 5, 1, 4, 10, 7, 0, 6 ];
var r = computeHistogram(arr);
// [ [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ], [ 4, 3 ] ]
If numBins
isn't specified or is set to zero, the number of bins is automatically
computed using the maximum of the Sturges and
Freedman–Diaconis' choice methods.
Otherwise the histogram for the provided input array
and binSize
is computed.
var arr = [ 8, 2, 3, 9, 5, 1, 4, 10, 7, 0, 6 ];
var r = computeHistogram(arr, 5);
// [ [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ], [ 4, 3 ] ]
Computes the histogram for the provided input array
and binSize
. This also trims a percertage from each
end of the distribution using trimTailPercentage
to allow filtering of outliers.
var arr = [ 8, 2, 3, 9, 5, 1, 4, 10, 7, 0, 6 ];
var r = computeHistogram(arr, 5, .05);
// [ [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ], [ 4, 2 ] ]
The automatic bin size heuristic is based on NumPy's implementation
Copyright © 2018. Christopher Baus.