Bernoulli and Binomial Distributions¶
Overview¶
The Bernoulli distribution models a single trial with two outcomes (success/failure), while the binomial distribution extends this to count the number of successes in \(n\) independent trials. Together, they form the foundation of discrete probability modeling.
Bernoulli Distribution¶
Definition¶
A random variable \(X\) follows a Bernoulli distribution if it takes value 1 (success) with probability \(p\) and value 0 (failure) with probability \(1 - p\):
Properties¶
Derivation of Variance¶
Binomial Distribution¶
Definition¶
If \(X_1, X_2, \ldots, X_n\) are independent \(\text{Bernoulli}(p)\) random variables, then \(Y = \sum_{i=1}^n X_i\) follows a binomial distribution:
The binomial coefficient \(\binom{n}{k} = \frac{n!}{k!(n-k)!}\) counts the number of ways to choose \(k\) successes from \(n\) trials.
Properties¶
Derivation of Mean and Variance¶
Since \(Y = \sum_{i=1}^n X_i\) where \(X_i \overset{\text{iid}}{\sim} \text{Bernoulli}(p)\):
By independence:
Verifying the PMF Sums to 1¶
By the binomial theorem:
Binomial Coefficient Identities¶
Several identities are useful for working with binomial distributions:
The absorption identity is particularly useful for computing \(E[Y]\) directly from the PMF:
Worked Example¶
Problem: A stock has a 60% chance of rising on any given day (independent across days). Over 10 trading days, what is the probability it rises on exactly 7 days?
Solution:
Expected number of up days: \(E[Y] = 10 \times 0.6 = 6\).
Python: PMF, CDF, and Sampling¶
PMF and CDF¶
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
n, p = 10, 0.6
x = np.arange(0, n + 1)
fig, ax = plt.subplots(figsize=(12, 3))
ax.bar(x - 0.15, stats.binom(n, p).pmf(x), width=0.3, label='PMF', alpha=0.7)
ax.bar(x + 0.15, stats.binom(n, p).cdf(x), width=0.3, label='CDF', alpha=0.7)
ax.set_xlabel('k')
ax.set_xticks(x)
ax.spines[['top', 'right']].set_visible(False)
ax.legend()
plt.show()
Comparing Different Parameters¶
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
fig, ax = plt.subplots(figsize=(12, 3))
for n, p in [(10, 0.5), (20, 0.5), (20, 0.7)]:
x = np.arange(0, n + 1)
ax.plot(x, stats.binom(n, p).pmf(x), 'o-', label=f'n={n}, p={p}', markersize=4)
ax.spines[['top', 'right']].set_visible(False)
ax.set_xlabel('k')
ax.legend()
plt.show()
Sampling and Verification¶
import numpy as np
from scipy import stats
np.random.seed(42)
n, p = 10, 0.6
samples = stats.binom(n, p).rvs(100_000)
print(f"Theoretical mean: {n*p:.4f}, Sample mean: {samples.mean():.4f}")
print(f"Theoretical var: {n*p*(1-p):.4f}, Sample var: {samples.var():.4f}")
Normal Approximation to the Binomial¶
For large \(n\), the binomial distribution is well approximated by a normal distribution:
With continuity correction, \(P(Y \leq k) \approx \Phi\left(\frac{k + 0.5 - np}{\sqrt{np(1-p)}}\right)\).
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
n, p = 50, 0.4
x_disc = np.arange(0, n + 1)
x_cont = np.linspace(0, n, 200)
fig, ax = plt.subplots(figsize=(12, 3))
ax.bar(x_disc, stats.binom(n, p).pmf(x_disc), alpha=0.5, label='Binomial PMF')
ax.plot(x_cont, stats.norm(n*p, np.sqrt(n*p*(1-p))).pdf(x_cont),
'r-', lw=2, label='Normal approx.')
ax.spines[['top', 'right']].set_visible(False)
ax.legend()
plt.show()
Key Takeaways¶
- The Bernoulli distribution models a single binary trial; the binomial counts successes over \(n\) independent trials.
- The binomial PMF uses the binomial coefficient to account for all possible orderings of successes.
- Mean \(np\) and variance \(np(1-p)\) follow directly from the sum-of-independent-Bernoullis representation.
- For large \(n\), the binomial is well approximated by the normal distribution, connecting discrete and continuous probability.