Skip to content

Measures of Central Tendency And Dispersion: A JavaScript library for probability & statistics

License

Notifications You must be signed in to change notification settings

erictheise/mctad.js

Repository files navigation

Travis CI Build Status Dependency Status

mctad.js

Measures of Central Tendency And Dispersion: A JavaScript library for probability & statistics

About

mctad.js is a JavaScript library for probability and statistics. A goal is to provide functionality missing from other such libraries, including the ability to generate random variables from many common discrete and continuous probability distributions, and having a basic implementation of directional statistics.

Use

You'll want either the file mctad.min.js or the file mctad.js in the root of this repository.

Documentation

See the GitHub pages for examples of using mctad.js. In addition, mctad.js runs groc as a grunt task to automatically generate html documentation from comments in the source code. Access that documentation by opening a browser on your local copy of /doc/index.html after you git clone this repository or look at the /doc/ directory of the GitHub pages.

Continuous and Discrete Probability Distributions

Distributions can be called by their common names and required parameters, e.g., mctad.poisson(7). This returns an object containing:

  • statistics on the distribution, including

    • mean
    • median
    • mode
    • variance
    • skewness
    • entropy
  • pdf, the probability density function (continuous distributions), or pmf, the probability mass function (discrete distributions)

  • cdf, the cumulative_distribution_function

  • convenience methods to access pmf as P(X) and cdf as F(X)

  • generate(n), a method for generating n random variables from the distribution

making it possible to say things such as

  • mctad.poisson(7).mean
  • mctad.poisson(7).P(5)
  • mctad.poisson(7).F(2)
  • mctad.triangular(3, 9, 4).generate(36)
  • mctad.normal(60.2, 4.5).generate(100)

Statistics on the distributions will return undefined if not implemented (this is version 0.0.X after all ) or if actually not defined for the distribution. Since there need not be a single mode, mode always returns an Array.

Tests

mctad.js uses mocha with chai assertions as a grunt task to run the test suite. The general format of the tests is to test exceptions before testing functionality. When possible, test data is taken from a wikipedia article or other hopefully long-lived reference. If these are not available, hand-worked examples are used for testing.

Conventions

The ability to use Greek letters directly in code appeals to me, and they are used internally. I am still considering the extent to which they should be exposed externally. In an ideal world, it would be reliable to use constructions such as p-hat (p̂) and x-bar (x̄) as variable names.

You will come across examples of type hinting, e.g., in the form of 1 versus 1.0, to help clarify whether quantities are expected to take integer or real values.

To Do

  • "self-estimating" distributions
  • chi square goodness of fit
  • analysis of variance

About

Measures of Central Tendency And Dispersion: A JavaScript library for probability & statistics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published