🌜
🌞
simple-statistics

simple-statistics

v7.7.5

Simple Statistics

npm install simple-statistics

README

Simple Statistics

A JavaScript implementation of descriptive, regression, and inference statistics.

Coverage Status npm version

Implemented in literate JavaScript with no dependencies, designed to work in all modern browsers (including IE) as well as in node.js.

Installation

  • I'm using Node.js, Webpack, Browserify, Rollup, or another module bundler, and install packages from npm.
    • First, install the simple-statistics module, using npm install simple-statistics, then include the code with require or import:
    • I use the require function to use modules in my project. (most likely)
      • When you use require, you have the freedom to assign the module to any variable name you want, but you need to specify the module's name exactly: in this case, 'simple-statistics'. The require method returns an object with all of the module's methods attached to it.
        var ss = require('simple-statistics')
    • I use import to use modules in my project. I'm probably using Babel, @std/esm, Webpack, or Rollup.
      • Import all functions under the ss object:
        import * as ss from 'simple-statistics'
        Include a specific named export:
        import {min} from 'simple-statistics'
        Simple statistics has only named exports for ES6.
  • I'm using Deno.
  • I'm not using a module bundler. I'm writing a web page, and want to include simple-statistics using a script tag.
    • I want to support all browsers
      • When you use simple-statistics from a script tag, you don't get to choose the variable name it is assigned to: simple-statistics will always become available globally as the variable ss. You can reassign this variable to another name if you want to, but doing so is optional.
        <script src='https://unpkg.com/[email protected]/dist/simple-statistics.min.js'>
        </script>
        
    • I want to use ES6 modules in a browser and I'm willing to only support new browsers to do it
      • This module works great with the ?module query parameter of unpkg. If you specify type='module' in your script tag, you'll be able to import simple-statistics directly - through index.js and with true ES6 import syntax and behavior.
        <script type='module'>
        import {min} from "https://unpkg.com/[email protected]/index.js?module"
        console.log(min([1, 2, 3]))
        </script>
        
        This feature is still experimental in unpkg and very bleeding-edge.

Release Notes

2.2.0
By Tom MacWright • Published on October 20, 2016
  • Improved Ckmeans algorithm from the updated R project that dramatically increases performance.
  • Adds permutationHeap method for computing all permutations of an array.
  • Adds combinations for combinations without replacement
  • Adds combinationsReplacement for combinations with replacement
2.0.0
By Tom MacWright • Published on May 26, 2016

New features:

  • product: returns the product of a series of numbers
  • medianSorted: exposes the internal method of median that only operates on sorted arrays and works in constant time
  • modeSorted: exposes the internal method of mode and works in linear time.

Specifications:

  • Adds Flow annotations to all methods, allowing up-front typechecking if you use Flow in your application.

Changes:

  • Invalid input now uniformly produces the value NaN instead of previously a mix of null and undefined.
  • The method sortedUniqueCount is now called uniqueCountSorted to match the other sorted methods, medianSorted and modeSorted

Fixes:

  • equalIntervalBreaks was not exported by index.js, and now is.
1.0.1
By Tom MacWright • Published on November 30, 2015

Fixes:

  • Fixes to ckmeans algorithm (thanks to @llimllib) (#125)

Housekeeping:

  • Add keywords to package. Fixes #120
  • Standardize indentation, add example for epsilon
  • Browser testing with Sauce Labs

Bundle size optimizations:

  • Add external sourcemaps for minified and unminified standalone bundles
  • Use bundle-collapser for smaller bundles
  • Indicate numericSort as an internal method.
1.0.0
By Tom MacWright • Published on August 10, 2015

This is the first major release of simple-statistics. It represents the work of 18 contributors, many improvements and battle-testing in over 3 years of development.

There are also several major changes that happened in this release.

In the course of many great additions, the monolithic simple_statistics.js file grew to over 1,500 lines, making it relatively unwieldy to develop. This release adopts the node require() method to split the methods into small focused files. This doesn't mean that node is required: a robust browser distribution is now provided in uncompressed & compressed forms under the /dist directory, and tools like browserify and webpack make it very convenient to use this kind of module unchanged.

The original simple-statistics absorbed one of my transgressions against JavaScript code style: underscore naming instead of camelCase naming. v1.0.0 reverses this decision, adopting the near-universal camelCase naming style for all methods.

v1.0.0 keeps all of the literate documentation that helps make tricky statistical methods understandable, but adds a big new documentation component: JSDoc, interpreted through documentation.js. documentation.js has been a side project of mine for quite a while now and this API-style documentation has proven to be a more scannable & uniformly styled counterpart to literate documentation. This also means that we're showing many more code samples inline with documentation to make it immediately clear what input and output types are used with each method.

On the algorithmic side, an implementation of Ckmeans clustering by Haizhou Wang and Mingzhou Song replaces the implementation of Jenks clustering ported from the original Fortran. A big thanks to Mason Lai for pointing me to this great research that establishes a more consistent, better explained, and faster implementation of the clustering problem.

Full changelog to follow:


1.0.0

Breaking Changes

  • Removed the .m() and .b() shortcuts from the linear regression class. Use .mb().b and .mb().m instead.
  • linearRegression is now a function, and linearRegressionLine is a separate function.

UPGRADING

Linear Regression

Before:

var l = ss.linear_regression().data([[0, 0], [1, 1]]);
l.line()(0); // 0

After:

var line = ss.linearRegressionLine(ss.linearRegression([[0, 0], [1, 1]]));
line(0); // 0

Jenks -> ckmeans

The implementation of Jenks natural breaks was removed: an implementation of Ckmeans, an improvement on its technique, is added. Ckmeans should work better for nearly all Jenks usecases.

Before:

ss.jenks([1, 2, 4, 5, 7, 9, 10, 20], 3) //= [1, 7, 20, 20]

After:

ss.ckmeans([1, 2, 4, 5, 7, 9, 10, 20], 3))
//= [ [ 1,  2,  4,  5, 7, 9 ],  [ 10 ],  [ 20 ] ]

Instead of class breaks, ckmeans returns clustered data. Class breaks can be derived by taking the first value from each cluster:

var breaks = ss.ckmeans([1, 2, 4, 5, 7, 9, 10, 20], 3)).map(function(cluster) {
  return cluster[0];
});
  • BayesModel is now a class
  • PerceptronModel is now a class, and the weights and bias members are accessable as properties rather than methods.
  • All multi-word method names are now camelCase rather than underscore_cased: this means that a method like ss.r_squared is now accessible as ss.rSquared

New Features

  • Ckmeans replaces Jenks
  • sortedUniqueCount provides an extremely fast method for counting unique values of sorted arrays.
  • sumNthPowerDeviations is now exposed, providing a simple way to calculate the fundamental aspect of measures like variance and skewness.

Non-Breaking Changes

  • JSDoc documentation throughout
  • Each function is now its own file, and simple-statistics is assembled with CommonJS-style require() statements. simple-statistics can still be used in a browser with browserify.
  • The standard normal table is now calculated using the cumulative distribution function, rather than hardcoded.

General

License
ISC
Typescript Types
Built-in
Tree-shakeable
Yes

Popularity

GitHub Stargazers
2,792
Community Interest
3,004
Number of Forks
224

Maintenance

Commits
10/219/2209
Last Commit
Open Issues
18
Closed Issues
156
Open Pull Requests
5
Closed Pull Requests
155

Versions

Versions Released
10/219/2203
Latest Version Released
Mar 6, 2022
Current Tags
latest7.7.5
testing7.0.9-alpha.0

Contributors

tmcw
tmcw
Commits: 448
greenkeeper[bot]
greenkeeper[bot]
Commits: 52
erictheise
erictheise
Commits: 29
Yomguithereal
Yomguithereal
Commits: 13
DenisCarriere
DenisCarriere
Commits: 11
ajschumacher
ajschumacher
Commits: 10
e-n-f
e-n-f
Commits: 8
mourner
mourner
Commits: 8
danallison
danallison
Commits: 7
dsaxton
dsaxton
Commits: 7
tniessen
tniessen
Commits: 7
jseppi
jseppi
Commits: 6
harunorimurata
harunorimurata
Commits: 5
phoeagon
phoeagon
Commits: 3
rluta
rluta
Commits: 3