Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gmac/series-stats

Numeric series statistics algorithms and utility methods.
https://github.com/gmac/series-stats

Last synced: 29 days ago
JSON representation

Numeric series statistics algorithms and utility methods.

Awesome Lists containing this project

README

        

series-stats
============

Numeric series statistics algorithms and utility methods. Useful for data visualization an choropleth mapping, specifically for breaking up a series of numbers into legend ranges.

#Series API

**equalBreaks** `Series.equalBreaks( [series], classes );`
Accepts a numeric series (array) and a number of classes to create. Returns an array of equally-sized class breaks distributed evenly across the range of series values. Example:

Series.equalBreaks([10, 55, 87, 63, 27, 36, 23, 71, 29, 45, 2, 83, 17], 4);
// >> [2, 23.25, 44.5, 65.75, 87]

**quantileBreaks** `Series.quantileBreaks( [series], classes );`
Returns an array of unevenly-sized classes distributed at even intervals across the series of values. Example:

Series.quantileBreaks([10, 55, 87, 63, 27, 36, 23, 71, 29, 45, 2, 83, 17], 4);
// >> [2, 23, 36, 63, 87]

**jenksBreaks** `Series.jenksBreaks( [series], classes );`
Returns an array of unevenly-sized classes distributed at uneven intervals across the series of values. Breaks are algorithmically plotted around concentrations of values within the series using [Jenks Natural Breaks](http://en.wikipedia.org/wiki/Jenks_natural_breaks_optimization "Jenks Natural Breaks"). Tends to minimizes the impact of outlier values on the outskirts of the series. Example:

Series.jenksBreaks([10, 55, 87, 63, 27, 36, 23, 71, 29, 45, 2, 83, 17], 4);
// >> [2, 17, 36, 63, 87]

**plot** `Series.plot( [series], value, descending? );`
Plots a value's index position within a numeric series array. Used to plot data values within a series of computed breaks (generated by one of the available breaks functions).

By default, plotting starts at the bottom of the series (first value) and works its way upward; each number in the series is used as a threshold that the value is tested against. If the value is `<=` to a threshold, then it advances upward in the series until a maximum threshold index is found and returned. May optionally perform a descending plot; this will start at the top of the series (last value) and work its way down comparing `>=` against each threshold. The plotted index of ascending and descending operations may differ.

* `[series]`: The numeric series array used to plot the value. Assumes the series to be pre-sorted.
* `value`: The value to plot within the series.
* `descending?`: Optional parameter to enable a descending (top-down) plot.

Examples:

// Mid-range ascending/descending:
Series.plot([0, 25, 50, 75, 100], 40); // >> 1
Series.plot([0, 25, 50, 75, 100], 40, true); // >> 1

// On-threshold ascending/descending:
Series.plot([0, 25, 50, 75, 100], 50); // >> 1
Series.plot([0, 25, 50, 75, 100], 50, true); // >> 2

**sort** `Series.sort( [series], descending? );`
Performs a numeric sort on the series array.

**min** `Series.min( [series] );`
Finds the minimum value within a numeric series array.

**max** `Series.max( [series] );`
Finds the maximum value within a numeric series array.

**sum** `Series.sum( [series] );`
Calculates the sum (total) of a numeric series array.

**mean** `Series.mean( [series] );`
Calculates the mean (average) of a numeric series array.

**unique** `Series.unique( [series] );`
Collects all unique values from a numeric series array; returns a new sorted array of the unique values.