A Binomial variable can be written as the sum of \(n\) independent Bernoulli random variables: \(X = \sum_{i=1}^n Y_i\), where \(Y_i \sim \text{Bernoulli}(p)\).
First, find the expectation of a single Bernoulli trial: \[\mathbb{E}[Y_i] = (1 \cdot p) + (0 \cdot (1-p)) = p\]
By the linearity of expectation: \[\mathbb{E}[X] = \mathbb{E}\left[\sum_{i=1}^n Y_i\right] = \sum_{i=1}^n \mathbb{E}[Y_i] = \sum_{i=1}^n p = np\]
Variance of Binomial(n,p)
First, we find the variance of a single Bernoulli trial \(Y_i\): \[\mathbb{E}[Y_i^2] = (1^2 \cdot p) + (0^2 \cdot (1-p)) = p\]\[\text{Var}(Y_i) = \mathbb{E}[Y_i^2] - (\mathbb{E}[Y_i])^2 = p - p^2 = p(1-p)\]
Because the \(n\) Bernoulli trials are independent, the variance of their sum equals the sum of their variances: \[\text{Var}(X) = \text{Var}\left(\sum_{i=1}^n Y_i\right) = \sum_{i=1}^n \text{Var}(Y_i) = n p(1-p)\]
Example 1: Quality Control
Manufacturing plants use the binomial distribution to predict and manage product defects.
Scenario: A factory tests a batch of microchips.
Parameters: Suppose historically, the probability of any single chip being defective is \(p = 0.02\) and the factory tests \(n=50\) microchips. The Binomial parameters are then \(n=50\) and \(p=0.02\).
Problem: Calculate the probability that \(x \le 2\) chips are defective and find the mean and variance of the number of defective chips.
Solutions
Exact Probability \(P(X \le 2) = f(0)+f(1)+f(2)\) = 92.16%
Mean or expected number of defective chips is (50)(.02) = 1
Variance of the number of defective chips is (50)(.02)(.98) = .98.
QC Visualization
library(ggplot2)n <-50p <-0.02df_qc <-data.frame(x =0:8, pmf =dbinom(0:8, size = n, prob = p))df_qc$highlight <-ifelse(df_qc$x <=2, "Target (<=2)", "Other")ggplot(df_qc, aes(x =factor(x), y = pmf, fill = highlight)) +geom_col(width =0.7) +scale_fill_manual(values =c("Target (<=2)"="darkgreen", "Other"="grey70")) +labs(title ="QC Defect Probability Matrix (n=50, p=0.02)",x ="Number of Defective Chips (x)", y ="Probability", fill ="Region") +theme_minimal()
QC Visualization
Example 2: A/B Testing
Digital marketers rely on the binomial distribution to see if website changes actually improve performance.
Scenario: An e-commerce site routes users to a new checkout page design.
Parameters: If the baseline checkout rate is known to be \(p = 0.08\) and the site routes \(n=500\) users to the new checkout page design, then the Binomial parameters are \(n=500\) and \(p=0.08\).
Question: How likely it is to observe \(x \ge 50\) successful purchases by pure chance?
To calculate the Binomial cdf, we use the pbinom function. The probability in Example 1 is also given by
pbinom(2,50,.02)
[1] 0.9215723
To find quantiles of the Binomial distribution, we use the function qbinom.
To generate random numbers from a Binomial distribution, we use rbinom.
Example 3
What is the probability of getting exactly 50 heads if a fair coin is flipped 100 times?
Solution:
Let X = number of heads obtained after 100 flips. Then \(X\sim \text{Binomial}(100,0.5)\) and \(P(X = 50)\) is
dbinom(50,100,0.5)
[1] 0.07958924
Example 4
What is the probability of getting less than 45 heads?
Solution:
\(P(X < 45)\) is
pbinom(44,100,.5)
[1] 0.1356265
Example 5
What is the probability of getting anywhere from 45 to 55 heads?
Solution:
\(P(45 \le X \le 55)\) is calculated as
pbinom(55,100,.5)-pbinom(44,100,.5)
[1] 0.728747
Example 6
What is the 3rd quartile of the \(\text{Binomial}(100,0.5)\) distribution?
Solution:
The 3rd quartile is the 75th quantile and is calculated as
qbinom(.75,100,0.5)
[1] 53
Empirical Simulation: Coin Flipping
What happens if we simulate a Binomial process empirically?
Experiment: Simulate flipping a fair coin (\(p = 0.5\)) \(100\) times (\(n = 100\)).
Repetitions: Repeat this whole process \(1,000\) times.
Objective: Map out the generated values and approximate the distribution’s mean and variance from the simulation.
Simulation & Analysis
library(ggplot2)set.seed(42) # Ensure reproducible results# 100 trials, 1000 repetitions, p = 0.5sim_trials <-rbinom(n =1000, size =100, prob =0.5)df_sim <-data.frame(heads = sim_trials)# Calculate empirical valuessim_mean <-mean(sim_trials)sim_var <-var(sim_trials)# Dynamic Title with resultsplot_title <-paste0("Empirical Coin Flips (1000 trials of n=100)\n","Simulated Mean: ", round(sim_mean, 2), " | Simulated Variance: ", round(sim_var, 2))# Plot histogramggplot(df_sim, aes(x = heads)) +geom_histogram(binwidth =1, fill ="purple", color ="white", alpha =0.8) +geom_vline(xintercept = sim_mean, color ="black", linetype ="dashed", size =1) +labs(title = plot_title, x ="Number of Heads (X)", y ="Frequency") +theme_minimal()
Note that the theoretical mean is 50 and the theoretical variance is 25 so the simulation is not bad.
Simulation & Analysis
References
History of the Distribution: Hald, A. (1998). A History of Mathematical Statistics from 1750 to 1930. New York, NY: John Wiley & Sons.
Properties of the Distribution Ross, S. M. (2014). A First Course in Probability (9th ed.). Pearson.
Computational Software: R Core Team (2026). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. Vienna, Austria. Available at https://www.R-project.org/.