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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tpmjs/tools-beta-binomial-update

v0.2.0

Published

Bayesian beta-binomial conjugate posterior update for estimating probabilities

Downloads

51

Readme

Beta-Binomial Update

Bayesian beta-binomial conjugate posterior update for estimating probabilities from data with prior beliefs.

Installation

npm install @tpmjs/tools-beta-binomial-update

Usage

import { betaBinomialUpdateTool } from '@tpmjs/tools-beta-binomial-update';

// Example: Estimate conversion rate with prior belief
// Prior: Beta(2, 2) = uniform-ish prior slightly favoring 0.5
// Data: 15 conversions out of 100 trials
const result = await betaBinomialUpdateTool.execute({
  priorAlpha: 2,
  priorBeta: 2,
  successes: 15,
  trials: 100,
  credibleLevel: 0.95, // 95% credible interval
});

console.log(result);
// {
//   posteriorAlpha: 17,      // 2 + 15
//   posteriorBeta: 87,       // 2 + (100 - 15)
//   posteriorMean: 0.163,    // Best estimate
//   posteriorMode: 0.157,    // Most likely value
//   posteriorVariance: 0.001,
//   credibleInterval: {
//     lower: 0.098,
//     upper: 0.239,
//     level: 0.95
//   },
//   statistics: {
//     effectiveSampleSize: 4,
//     priorMean: 0.5,
//     dataLikelihood: 0.15
//   }
// }

API

Input

  • priorAlpha (required): Prior successes + 1 (e.g., 1 for uninformative, 2 for weak prior)
  • priorBeta (required): Prior failures + 1
  • successes (required): Number of successes observed
  • trials (required): Total number of trials
  • credibleLevel (optional): Credible interval level (default: 0.95)

Output

  • posteriorAlpha: Updated alpha parameter
  • posteriorBeta: Updated beta parameter
  • posteriorMean: Expected value of probability
  • posteriorMode: Most likely probability value
  • posteriorVariance: Uncertainty in estimate
  • credibleInterval: Bayesian confidence interval
  • statistics: Prior mean, likelihood, effective sample size

Algorithm

Uses conjugate Beta-Binomial model:

Prior: θ ~ Beta(α, β) Likelihood: X ~ Binomial(n, θ) Posterior: θ|X ~ Beta(α + k, β + (n - k))

Where:

  • k = successes
  • n = trials
  • θ = unknown probability

The Beta distribution is conjugate to the Binomial, making the update simple and exact.

Common Priors

  • Uninformative: Beta(1, 1) = Uniform[0, 1]
  • Jeffreys: Beta(0.5, 0.5) = Uninformative invariant prior
  • Weak: Beta(2, 2) = Slight preference for θ = 0.5
  • Strong: Beta(20, 20) = Strong belief in θ = 0.5

Use Cases

  • A/B test analysis (conversion rates)
  • Click-through rate estimation
  • Medical test sensitivity/specificity
  • Quality control (defect rates)
  • Sports analytics (win probabilities)

Credible Interval

The credible interval is the Bayesian analog of a confidence interval. A 95% credible interval means "there is a 95% probability that θ lies in this interval given the data."

License

MIT