Simple statistics is a JavaScript library that does descriptive statistics, regression, and classification. It can tell you basic things like minimum and maximum, but it can also compute tricky things like standard deviation and sample correlation. But more importantly, it's see-through: you can read it, and it's written in a friendly, literate manner.
npm install simple-statistics
var ss = require('simple-statistics');
git clone git://github.com/tmcw/simple-statistics.git
Basic contracts of functions:
null.Optionally mix in the following functions into the Array prototype. Otherwise
you can use them off of the simple-statistics object itself.
Mean of a single-dimensional Array of numbers. Also available as .average(x)
Sum of a single-dimensional Array of numbers.
Variance of a single-dimensional Array of numbers.
Standard Deviation of a single-dimensional Array of numbers.
Median of a single-dimensional array of numbers.
Geometric mean of a single-dimensional array of positive numbers.
Finds the minimum of a single-dimensional array of numbers. This runs in linear O(n) time.
Finds the maximum of a single-dimensional array of numbers. This runs in linear O(n) time.
Does a student's t-test of a dataset sample, represented by a single-dimensional array of numbers. x is the known value, and the result is a measure of statistical significance.
Produces sample variance of a single-dimensional array of numbers.
Produces sample covariance of two single-dimensional arrays of numbers.
Produces sample correlation of two single-dimensional arrays of numbers.
Does a quantile of a dataset sample,
at p. For those familiary with the k/q syntax, p == k/q. sample must
be a single-dimensional array of numbers, and p must be a number greater
than zero and less than one.
Calculates the Interquartile range of a sample - the difference between the upper and lower quartiles. Useful as a measure of dispersion.
Also available as .interquartile_range(x)
Find the Jenks Natural Breaks for
a single-dimensional array of numbers as input and a desired number_of_classes.
The result is a single-dimensional with class breaks, including the minimum
and maximum of the input array.
Find the r-squared value of a particular dataset, expressed as a two-dimensional Array of numbers, against a Function.
var r_squared = ss.r_squared([[1, 1]], function(x) { return x * 2; });
Create a new linear regression solver.
Set the data of a linear regression. The input is a two-dimensional array of numbers, which are treated as coordinates, like [[x, y], [x1, y1]].
Get the linear regression line: this returns a function that you can
give x values and it will return y values. Internally, this uses the m()
and b() values and the classic y = mx + b equation.
var linear_regression_line = ss.linear_regression()
.data([[0, 1], [2, 2], [3, 3]]).line();
linear_regression_line(5);
Just get the slope of the fitted regression line, the m component of the full
line equation. Returns a number.
Just get the y-intercept of the fitted regression line, the b component
of the line equation. Returns a number.
Create a naïve bayesian classifier.
Train the classifier to classify a certain item, given as an object with keys, to be in a certain category, given as a string.
Get the classifications of a certain item, given as an object of
category -> score mappings.
var bayes = ss.bayesian();
bayes.train({ species: 'Cat' }, 'animal');
bayes.score({ species: 'Cat' });
// { animal: 1 }