Calculate exact, cumulative, and range probabilities for binomial distributions.
Calculation Results
P(X = k):
P(X < k):
P(X ≤ k):
P(X > k):
P(X ≥ k):
Mean (μ):
Understanding Binomial Distribution
The binomial distribution is a discrete probability distribution that summarizes the likelihood that a value will take one of two independent values under a given set of parameters or assumptions. It is used to model the number of successes in a fixed number of independent trials.
Core Components
Trials (n): The total number of identical, independent experiments.
Successes (k): The specific number of positive outcomes you are measuring.
Probability (p): The constant probability of success in any single trial (must be between 0 and 1).
The Binomial Formula
P(X = k) = (n! / (k!(n-k)!)) * p^k * (1-p)^(n-k)
Practical Example: Quality Control
Imagine a factory produces light bulbs, and 5% (p = 0.05) are known to be defective. If you randomly select a sample of 20 bulbs (n = 20), what is the probability that exactly 2 (k = 2) are defective?
Using this calculator, you would input n=20, p=0.05, and k=2 to find that the probability of having exactly 2 defective bulbs is approximately 0.1887 (or 18.87%).
function calculateBinomial() {
var n = parseInt(document.getElementById('trials_n').value);
var p = parseFloat(document.getElementById('probability_p').value);
var k = parseInt(document.getElementById('successes_k').value);
var resultsDiv = document.getElementById('binomial-results');
if (isNaN(n) || isNaN(p) || isNaN(k) || n < 0 || p 1 || k n) {
alert("Please enter valid numbers. Ensure p is between 0 and 1, and k is not greater than n.");
return;
}
function factorial(num) {
if (num < 0) return 1;
if (num === 0 || num === 1) return 1;
var res = 1;
for (var i = 2; i <= num; i++) res *= i;
return res;
}
function combinations(n, k) {
if (k n) return 0;
if (k === 0 || k === n) return 1;
if (k > n / 2) k = n – k;
var res = 1;
for (var i = 1; i <= k; i++) {
res = res * (n – i + 1) / i;
}
return res;
}
function binomialProb(n, k, p) {
return combinations(n, k) * Math.pow(p, k) * Math.pow(1 – p, n – k);
}
var probExact = binomialProb(n, k, p);
var probLess = 0;
for (var i = 0; i < k; i++) {
probLess += binomialProb(n, i, p);
}
var probLessEq = probLess + probExact;
var probGreater = 1 – probLessEq;
var probGreaterEq = 1 – probLess;
var mean = n * p;
document.getElementById('res_exact').innerText = probExact.toFixed(6);
document.getElementById('res_less').innerText = probLess.toFixed(6);
document.getElementById('res_less_eq').innerText = probLessEq.toFixed(6);
document.getElementById('res_greater').innerText = probGreater.toFixed(6);
document.getElementById('res_greater_eq').innerText = probGreaterEq.toFixed(6);
document.getElementById('res_mean').innerText = mean.toFixed(2);
resultsDiv.style.display = 'block';
}