Package Exports
- simple-statistics
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simple-statistics) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A project to learn about and make simple reference implementations of statistics algorithms.
This code is designed to work in browsers (including IE) as well as in node.js.
Basic Descriptive Statistics
// Require simple statistics
var ss = require('simple-statistics');
// The input is a simple array
var list = [1, 2, 3];
// Many different descriptive statistics are supported
var sum = ss.sum(list),
mean = ss.mean(list),
min = ss.min(list),
geometric_mean = ss.geometric_mean(list),
max = ss.max(list),
quantile = ss.quantile(0.25);Linear Regression
// For a linear regression, it's a two-dimensional array
var data = [ [1, 2], [2, 3] ];
// simple-statistics can produce a linear regression and return
// a friendly javascript function for the line.
var line = ss.linear_regression()
.data(data)
.line();
// get a point along the line function
line(0);
var line = ss.linear_regression()
// Get the r-squared value of the line estimation
ss.r_squared(data, line);Literate Documentation
Mixin Style
This is optional and not used by default. You can opt-in to mixins
with ss.mixin().
This mixes simple-statistics methods into the Array prototype - note that
extending native objects is a
tricky move.
This will only work if defineProperty is available, which means modern browsers
and nodejs - on IE8 and below, calling ss.mixin() will throw an exception.
// mixin to Array class
ss.mixin();
// The input is a simple array
var list = [1, 2, 3];
// The same descriptive techniques as above, but in a simpler style
var sum = list.sum(),
mean = list.mean(),
min = list.min(),
max = list.max(),
quantile = list.quantile(0.25);Bayesian Classifier
var bayes = ss.bayesian();
bayes.train({ species: 'Cat' }, 'animal');
bayes.score({ species: 'Cat' });
// { animal: 1 }Examples
- Linear regression with simple-statistics and d3js
- Jenks Natural Breaks with a choropleth map with d3js
Usage
To use it in browsers, grab simple_statistics.js. To use it in node, install it with npm or add it to your package.json.
npm install simple-statisticsTo use it with component,
component install tmcw/simple-statisticsDocumentation
Tests
Contributors
- Tom MacWright
- Matt Sacks
- Doron Linder
- Alexander Sicular
See Also
- stream-statistics, a sister project that implements many of the same measures for streaming data - as online algorithms
Javascript
- science.js
- atoll.js
- descriptive_statistics
- jStat
- classifier is a naive bayesian classifier (though specialized for the words-spam case)
- underscore.math
