Binomial Distribution Calculator
Calculator
Parameters
Distribution Chart
Click Calculate to view the distribution chart
Learn More
Binomial Distribution: Definition, Formula, and Examples
Binomial Distribution
Definition: The binomial distribution is a discrete probability distribution that models the number of successes in a fixed number of independent Bernoulli trials. A Bernoulli trial is an experiment with two possible outcomes: success or failure.
Formula:
Where:
- is the number of trials
- is the number of successes
- is the probability of success on each trial
- \inom{n}{k} is the binomial coefficient
Examples: Suppose you flip a fair coin times . Let's calculate various probabilities:
- Probability of getting exactly 6 heads:
- Probability of getting between 3 and 7 heads :
- Probability of getting less than 5 heads :
- Probability of getting more than 4 heads :
Properties of Binomial Distribution
- Mean:
- Variance:
- Standard Deviation:
How to Calculate Binomial Probabilities in R?
R
# Set parameters
n <- 10 # number of trials
p <- 0.5 # probability of success
# Calculate P(X = 6)
prob_equal_6 <- dbinom(6, size = n, prob = p)
print(paste("P(X = 6):", prob_equal_6))
# Calculate P(X <= 4)
prob_less_equal_4 <- pbinom(4, size = n, prob = p)
print(paste("P(X <= 4):", prob_less_equal_4))
# Calculate P(X > 7)
prob_greater_7 <- 1 - pbinom(7, size = n, prob = p)
print(paste("P(X > 7):", prob_greater_7))
# Calculate P(3 < X < 8)
prob_between_3_and_8 <- pbinom(7, size = n, prob = p) - pbinom(3, size = n, prob = p)
print(paste("P(3 < X < 8):", prob_between_3_and_8))
# Calculate mean and variance
mean <- n * p
variance <- n * p * (1 - p)
print(paste("Mean:", mean))
print(paste("Variance:", variance))
How to Calculate Binomial Probabilities in Python?
Python
import scipy.stats as stats
# Set parameters
n = 10 # number of trials
p = 0.5 # probability of success
# Calculate P(X = 6)
prob_equal_6 = stats.binom.pmf(6, n, p)
print(f"P(X = 6): {prob_equal_6:.4f}")
# Calculate P(X <= 4)
prob_less_equal_4 = stats.binom.cdf(4, n, p)
print(f"P(X <= 4): {prob_less_equal_4:.4f}")
# Calculate P(X > 7)
prob_greater_7 = 1 - stats.binom.cdf(7, n, p)
print(f"P(X > 7): {prob_greater_7:.4f}")
# Calculate P(3 < X < 8)
prob_between_3_and_8 = stats.binom.cdf(7, n, p) - stats.binom.cdf(3, n, p)
print(f"P(3 < X < 8): {prob_between_3_and_8:.4f}")
# Calculate mean and variance
mean = n * p
variance = n * p * (1 - p)
print(f"Mean: {mean}")
print(f"Variance: {variance}")