npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

distriprob

v0.2.0

Published

A library for calculating the PDF, CDFs, and quantile function values of common probability distributions

Downloads

14

Readme

distriprob

Motivation

The distriprob library allows the calculation of probility density (mass in the case of discrete distributions), cumulative distribution, and quantile (a.k. inverse cdf) function values in Node or in the browser. The distriprob library is written in typescript so users of the libary can take advantage of intellisense on the module exports without any need to worry about downloading d.ts files. Plain old javascript users can also use the library, but without the benefits of typescript. The asynchronous (non-Sync) functions in the library use web workers( or webworker-threads in Node) to avoid clogging up the event loop with calculations. The library is tested against the equivalent functionality in R and every attempt is made to make the library as accurate (compared to R) and fast as possible.

Instalation and Usage

The distriprob libaray can be downloaded using NPM:

npm install distriprob

Or by cloning the github repository:

git clone https://github.com/zachmart/distriprob.git
cd distriprob
npm run build

The distriprob libary is designed to be used with nodejs or in the browser. Distriprob is written in typescript and transpiled to ES6. So the package may be imported using ES6 imports:

import * as distriprob from "distriprob";

or using commonjs require's:

const distriprob = require("distriprob");

In addition, the distriprob library contains a browserify-ed bundle for use in the browser with <script> tags which will introduce the global variable distriprob:

<script src="node_modules/distriprob/bundle.js" type="text/javascript></script>

Supported Distributions

###Continuous

  1. Normal (distriprob.normal)
  2. [Student's t](#student's t) (distriprob.t)
  3. [Chi Squared](#chi Squared) (distriprob.chi2)
  4. F (distriprob.F)

###Discrete 5. Binomial (distriprob.binomial) 6. Poisson (distriprob.poisson) 7. Hypergeometric (distriprob.hypergeometric)

The functionality for each of these distributions is located directly on the exported distriprob object. On each of the distribution objects there are three functions: pdf(pmf for discrete distributions), cdf, and quantile for the probability density (mass), cumulative distribution, and quantile (inverse cdf) functions respectively. Each of these functions has a synchronous version (with the "Sync" suffix) and an asynchronous version which returns an ES6 promise for the desired value. Examples:

console.log(distriprob.normal.pdfSync(0, 0, 1));   // 0.3989422804014327
distriprob.possion.quantile(0.5, 1).then((result) => {
  console.log(result);                            // 1
});

API by Distribution

###Continuous Distributions

####Normal Given a random variable X with a Normal probability distribution with mean mu and standard deviation sigma:

  • distriprob.normal.pdf(x, mu, sigma) returns an ES6 promise for the numeric probability density of X where:
    • x: number - is the value of X for the desired density
    • mu: number - is the mean of X, defaults to 0
    • sigma: number > 0 - is the standard deviation of X, defaults to 1
  • distriprob.normal.pdfSync(x, mu, sigma) returns the numeric probability density of X where:
    • x: number - is the value of X for the desired density
    • mu: number - is the mean of X, defaults to 0
    • sigma: number > 0 - is the standard deviation of X, defaults to 1
  • distriprob.normal.cdf(x, mu, sigma, lowerTail) returns an ES6 promise for the numeric cumulative distribution probability that X falls in the region delimited by the argument values below, where:
    • x: number - is the value of X bounding the region of accumulation for the desired cumulative distribution
    • mu: number - is the mean of X, defaults to 0
    • sigma: number > 0 - is the standard deviation of X, defaults to 1
    • lowerTail: boolean - determines whether the calculated cumulative distribution is for all values in the lower or upper tail (those above or below the given x)
  • distriprob.normal.cdfSync(x, mu, sigma) returns the numeric cumulative distribution probability that X falls in the region delimited by the argument values below, where:
    • x: number - is the value of X bounding the region of accumulation for the desired cumulative distribution
    • mu: number - is the mean of X, defaults to 0
    • sigma: number > 0 - is the standard deviation of X, defaults to 1
    • lowerTail: boolean - determines whether the calculated cumulative distribution is for all values in the lower or upper tail (those above or below the given x) ####Student's t

####Chi Squared

####F

###Discrete Distributions

####Binomial

####Poisson

####Hypergeometric

License

MIT --- open source