Binomial Distribution Calculator
Calculate binomial probabilities P(X=k), P(X≤k), and P(X≥k) for discrete events.
About this tool
The Binomial Distribution Calculator computes the exact probabilities of discrete events that have exactly two possible outcomes. This tool is essential for statisticians, data scientists, and anyone working with quality control, medical trials, or any scenario involving repeated independent experiments with constant success probability.
To use this calculator, enter the number of trials (n), the probability of success on each trial (p between 0 and 1), and the number of successes you want to analyze (k). The tool instantly calculates three key probabilities: the exact probability of getting exactly k successes, the cumulative probability of getting k or fewer successes, and the probability of getting k or more successes. This flexibility lets you answer both precise and range-based questions about your binomial scenario.
The binomial distribution applies to countless real-world situations: predicting the number of defective items in a batch, determining patient recovery rates in medical studies, analyzing customer conversion rates, or assessing manufacturing quality. Understanding these probabilities helps you make informed decisions based on expected outcomes rather than guesswork.
Frequently Asked Questions
Code Implementation
import math
def binomial_pmf(n: int, k: int, p: float) -> float:
"""P(X = k) for Binomial(n, p)"""
log_c = math.lgamma(n + 1) - math.lgamma(k + 1) - math.lgamma(n - k + 1)
log_p = k * math.log(p) + (n - k) * math.log(1 - p) if 0 < p < 1 else (0 if p == k / n else float('-inf'))
return math.exp(log_c + log_p)
def binomial_cdf(n: int, k: int, p: float) -> float:
"""P(X <= k)"""
return sum(binomial_pmf(n, i, p) for i in range(k + 1))
# Example: 10 coin flips, p=0.5, exactly 6 heads
n, k, p = 10, 6, 0.5
print(f"P(X = {k}) = {binomial_pmf(n, k, p):.4f}")
print(f"P(X ≤ {k}) = {binomial_cdf(n, k, p):.4f}")
print(f"P(X ≥ {k}) = {1 - binomial_cdf(n, k - 1, p):.4f}")
print(f"Mean = {n * p:.2f}, Std Dev = {(n * p * (1 - p)) ** 0.5:.2f}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.