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

multinomial-pmf

v1.0.1

Published

multinomial probability mass function

Downloads

3

Readme

multinomial-pmf

NPM

Build Status

multinomial probability mass function

installation

npm install multinomial-pmf

usage

var multpmf = require('multinomial-pmf')
multpmf([0.5,0.5], [1,1]) // coin toss: HT
// 0.5
multpmf([0.5,0.5], [0,3]) // coin toss: TTT
// 0.125
var diceProbs = [1,1,1,1,1,1].map(function(x) { return x/6 })
multpmf(diceProbs, [1,2,0,3,0,1]) // fair six-sided die
// 0.0015003429355281205

There is also a log-space (but approximate) version:

var logmultpmf = require('multinomial-pmf').log
logmultpmf([0.5, 0.5], [2, 3])
// -1.163150809805681
Math.exp(logmultpmf([0.5, 0.5], [2, 3]))
// 0.31249999999999994

You'll incur some (small) loss of precision using the log version, but also you'll be able to handle much more complex multinomial distributions.

overview

This module calculates the discrete sampling probability of a multiset of a given size from an underlying source multinomial distribution. In other words, it implements the multinomial probability mass function.

It helps us answer questions like:

  • If I have 5 red, 3 blue, and 1 yellow ball in a bag, what's the probability that I draw 3 blue and 1 red (with replacement, in other words, the balls go back in the back after I've pulled them)?
var bag   = [5,3,1]
var pulls = [1,3,0]

function countsToProbs(counts) {
    var sum = counts.reduce(function(x,y) { return x+y })
    return counts.map(function(x) { return x/sum })
}

multpmf(countsToProbs(bag), pulls)
// 0.0823045267489712

The binomial distribution is a special case of the multinomial where the number of categories is 2.

license

MIT