PRACTICAL NO.
09
Discrete Probability Distributions
Binomial Distribution | Poisson Distribution
Subject: Statistics Using R Programming | Course: SYBCS / BCA / BBA
QUESTION 1 | Binomial Distribution — Fair Coin Toss
1. Problem Statement
A fair coin is tossed 12 times. Since the coin is fair, the probability of getting a Head (H) on any single toss is 0.5,
and the probability of Tail (T) is also 0.5. Each toss is independent of the others.
We need to find:
• (a) Exactly 5 heads → P(X = 5)
• (b) At most 3 heads → P(X ≤ 3)
• (c) At least 8 heads → P(X ≥ 8)
• (d) Plot the full probability distribution for X = 0, 1, 2, ..., 12
2. Theory — What is Binomial Distribution?
The Binomial Distribution is used when we repeat the same experiment a fixed number of times, and each
experiment has only two possible outcomes: Success or Failure.
Think of it like this:
• You flip a coin 12 times (n = 12 trials)
• Each flip either gives a Head (success) or Tail (failure)
• Probability of Head on each flip = 0.5 (p = 0.5)
• X = number of Heads in 12 flips → X follows Binomial Distribution
Conditions for Binomial Distribution:
• Fixed number of trials (n) — here n = 12
• Only 2 outcomes per trial — Head or Tail
• Same probability in every trial — p = 0.5 for each flip
• All trials are independent — one flip doesn't affect another
KEY PARAMETERS for this question:
n = 12 (number of coin tosses)
p = 0.5 (probability of getting a Head on each toss)
q = 1 - p = 0.5 (probability of getting a Tail)
X = number of Heads obtained → X can be 0, 1, 2, ..., 12
3. Formula — Binomial Probability
The probability of getting exactly k successes in n trials is:
P(X = k) = C(n, k) × p^k × (1-p)^(n-k)
Where:
• C(n, k) = n! / [k! × (n-k)!] → Number of ways to choose k items from n (called 'n choose k')
• p^k → probability of k successes
• (1-p)^(n-k) → probability of remaining (n-k) failures
In R language, we use two built-in functions:
• dbinom(k, n, p) → gives EXACT probability P(X = k)
• pbinom(k, n, p) → gives CUMULATIVE probability P(X ≤ k)
4. Step-by-Step Manual Calculation
Let's manually verify Part (a) to understand the formula:
Part (a): P(X = 5) with n=12, p=0.5, k=5
• C(12, 5) = 12! / (5! × 7!) = 792
• p^5 = (0.5)^5 = 0.03125
• (1-p)^7 = (0.5)^7 = 0.0078125
• P(X = 5) = 792 × 0.03125 × 0.0078125 = 0.1934
Part (b): P(X ≤ 3) → Add up P(X=0) + P(X=1) + P(X=2) + P(X=3)
• This is tedious to do by hand, so we use pbinom(3, 12, 0.5) in R
Part (c): P(X ≥ 8) → Use complement: P(X ≥ 8) = 1 - P(X ≤ 7)
• = 1 - pbinom(7, 12, 0.5) in R
5. Complete R Script with Comments
# ============================================================
# QUESTION 1: Binomial Distribution — Fair Coin Tossed 12 Times
# ============================================================
n <- 12 # Total number of coin tosses
p <- 0.5 # Probability of Head on each single toss
# ----- PART (a): P(X = 5) — Exactly 5 Heads -----
prob_a <- dbinom(5, size = n, prob = p)
cat('(a) P(X = 5) =', prob_a, '\n')
# ----- PART (b): P(X <= 3) — At Most 3 Heads -----
# 'At most 3' means X can be 0, 1, 2, OR 3
prob_b <- pbinom(3, size = n, prob = p)
cat('(b) P(X <= 3) =', prob_b, '\n')
# ----- PART (c): P(X >= 8) — At Least 8 Heads -----
# 'At least 8' means X can be 8, 9, 10, 11, OR 12
# We use complement: P(X >= 8) = 1 - P(X <= 7)
prob_c <- 1 - pbinom(7, size = n, prob = p)
cat('(c) P(X >= 8) =', prob_c, '\n')
# ----- PART (d): Plot the Probability Distribution -----
x_vals <- 0:12 # All possible values: 0 to 12
probs <- dbinom(x_vals, size=n, prob=p) # Probability for each value
barplot(probs,
[Link] = x_vals,
main = 'Binomial Distribution: n=12, p=0.5 (Coin Toss)',
xlab = 'Number of Heads (X)',
ylab = 'Probability P(X = k)',
col = 'steelblue',
border = 'white',
ylim = c(0, 0.25))
6. Line-by-Line Code Explanation
Every single line of the R code explained in simple words:
n <- 12 Store the number of coin tosses (trials) in variable 'n'. We toss 12
times.
p <- 0.5 Store the probability of Head in variable 'p'. Fair coin = equal
chance = 0.5.
dbinom(5, size=n, prob=p) 'd' = density = exact probability. This gives P(X = 5). The 'd' in
dbinom stands for 'density' which means exact probability at a
single point.
pbinom(3, size=n, prob=p) 'p' = cumulative probability. This adds up
P(X=0)+P(X=1)+P(X=2)+P(X=3). The 'p' in pbinom stands for
'probability up to and including' the given value.
1 - pbinom(7, size=n, P(X >= 8) = 1 - P(X <= 7). We subtract from 1 because all
prob=p) probabilities add to 1. This is called the Complement Rule.
x_vals <- 0:12 Create a sequence of numbers from 0 to 12. These are all possible
outcomes.
dbinom(x_vals, size=n, Calculate probability for every value from 0 to 12 at once. R
prob=p) processes the entire vector together.
barplot(probs, Draw a bar chart. Each bar's height = probability. [Link] labels
[Link]=x_vals, ...) each bar with its x value (0,1,2,...,12).
col='steelblue' Sets the color of bars to steel blue.
ylim=c(0, 0.25) Sets y-axis limits from 0 to 0.25 so bars are well visible.
7. Final Results
(a) P(X = 5) = dbinom(5, 12, 0.5) = 0.1934 (19.34%)
(b) P(X ≤ 3) = pbinom(3, 12, 0.5) = 0.0730 ( 7.30%)
(c) P(X ≥ 8) = 1 - pbinom(7, 12, 0.5) = 0.1938 (19.38%)
Interpretation in Plain English:
• If you toss a fair coin 12 times, there is roughly a 19.34% chance you get exactly 5 Heads.
• There is only about 7.3% chance of getting 3 or fewer Heads (uncommon, since you expect ~6 Heads).
• There is about 19.38% chance of getting 8 or more Heads (mirror of Part a due to symmetry of fair coin).
• By symmetry (p=0.5): P(X ≤ 3) should equal P(X ≥ 9). Check: 0.073 ≈ P(X≥9) ✓
QUESTION 2 | Binomial Distribution — Factory Defective Products
1. Problem Statement
In a factory, 10% of all products manufactured are defective. This means if you pick any product at random, there
is a 10% (= 0.10) chance it is defective and 90% (= 0.90) chance it is good.
A quality inspector randomly selects 15 products from a large batch.
We need to find:
• (a) Exactly 2 products are defective → P(X = 2)
• (b) At most 3 products are defective → P(X ≤ 3)
• (c) No product is defective → P(X = 0)
• (d) Plot the Binomial probability distribution
2. Theory — Why Binomial? (Real-World Reasoning)
We use Binomial distribution here because:
• Each product is either DEFECTIVE (success in statistical terms) or GOOD (failure) → Two outcomes only
• We are checking exactly 15 products → Fixed number of trials (n = 15)
• Each product is picked independently, and the batch is large → p stays constant at 0.10
• The probability of defective is the same for every product selected → p = 0.10 throughout
KEY PARAMETERS for this question:
n = 15 (sample size — number of products inspected)
p = 0.10 (probability that any single product is defective = 10%)
q = 0.90 (probability that product is NOT defective = 90%)
X = number of defective products in sample → X can be 0, 1, 2, ..., 15
Expected number of defectives = n × p = 15 × 0.10 = 1.5
3. Formula
P(X = k) = C(15, k) × (0.10)^k × (0.90)^(15-k)
Manual check for Part (c) — P(X = 0):
• C(15, 0) = 1 (only one way to choose 0 items from 15)
• (0.10)^0 = 1 (anything to the power 0 = 1)
• (0.90)^15 = 0.2059
• P(X = 0) = 1 × 1 × 0.2059 = 0.2059
This means there's about a 20.6% chance that NONE of the 15 selected products is defective!
4. Complete R Script with Comments
# ============================================================
# QUESTION 2: Binomial Distribution — Factory Defectives
# ============================================================
n <- 15 # Number of products randomly selected
p <- 0.10 # Probability of a product being defective (10%)
# ----- PART (a): Exactly 2 Defectives -----
prob_a <- dbinom(2, size = n, prob = p)
cat('(a) P(X = 2) =', prob_a, '\n')
# ----- PART (b): At Most 3 Defectives -----
# 'At most 3' means 0, 1, 2, or 3 defectives
prob_b <- pbinom(3, size = n, prob = p)
cat('(b) P(X <= 3) =', prob_b, '\n')
# ----- PART (c): No Product is Defective -----
prob_c <- dbinom(0, size = n, prob = p)
cat('(c) P(X = 0) =', prob_c, '\n')
# ----- PART (d): Plot the Distribution -----
x_vals <- 0:15
probs <- dbinom(x_vals, size = n, prob = p)
barplot(probs,
[Link] = x_vals,
main = 'Binomial Distribution: n=15, p=0.10 (Factory Defects)',
xlab = 'Number of Defective Products (X)',
ylab = 'Probability P(X = k)',
col = ifelse(x_vals <= 3, 'tomato', 'lightgray'),
border = 'white')
legend('topright', legend=c('At most 3 (region b)', 'Others'),
fill=c('tomato','lightgray'))
5. Line-by-Line Code Explanation
n <- 15 ; p <- 0.10 Set parameters: 15 products checked, each has 10% chance of
being defective.
dbinom(2, size=n, prob=p) Exact probability of getting exactly 2 defectives out of 15.
pbinom(3, size=n, prob=p) Cumulative probability — sums up P(X=0)+P(X=1)+P(X=2)+P(X=3)
automatically.
dbinom(0, size=n, prob=p) Probability of getting zero defectives. We use dbinom because we
want an exact value (X=0).
x_vals <- 0:15 Vector of all possible outcomes from 0 to 15.
ifelse(x_vals <= 3, Color bars red if x ≤ 3 (this is the 'at most 3' region from part b),
'tomato', 'lightgray') gray for the rest. This highlights the important region visually.
legend('topright', ...) Adds a legend box in the top-right corner explaining the bar colors.
6. Final Results
(a) P(X = 2) = dbinom(2, 15, 0.10) = 0.2669 (26.69%)
(b) P(X ≤ 3) = pbinom(3, 15, 0.10) = 0.9444 (94.44%)
(c) P(X = 0) = dbinom(0, 15, 0.10) = 0.2059 (20.59%)
Interpretation in Plain English:
• Exactly 2 defectives: About 26.7% chance — this is the most likely outcome since expected = 1.5 defectives.
• At most 3 defectives: Very high 94.4% chance. In most batches of 15, you will find 3 or fewer defectives.
• Zero defectives: About 20.6% chance. 1 out of every 5 batches will have NO defective products.
QUESTION 3 | Poisson Distribution — Call Center
1. Problem Statement
A call center receives an average of 4 calls per minute. Calls arrive randomly and independently — we don't know
exactly when the next call will come, only that on average 4 arrive each minute.
We need to find:
• (a) Exactly 6 calls in a given minute → P(X = 6)
• (b) At most 2 calls in a given minute → P(X ≤ 2)
• (c) No calls received in a given minute → P(X = 0)
• (d) Plot the Poisson distribution for calls per minute
2. Theory — What is Poisson Distribution?
The Poisson Distribution is used to find the probability of a certain number of events happening in a fixed time
period, when events occur randomly and independently at a known average rate.
Perfect for situations like:
• Number of phone calls arriving at a call center per minute
• Number of accidents on a highway per month
• Number of emails received per hour
• Number of defects in a roll of fabric
Key conditions for Poisson Distribution:
• Events occur one at a time (you can't receive 2 calls at exactly the same instant)
• Events are independent (one call doesn't cause or prevent the next)
• Average rate (λ) is constant — here λ = 4 calls/minute always
• We count events in a fixed interval (here: exactly 1 minute)
KEY PARAMETER for this question:
λ (lambda) = 4 (average number of calls per minute)
X = actual number of calls in any given minute
X can theoretically be 0, 1, 2, 3, 4, ... (no upper limit theoretically)
Mean = Variance = λ = 4 (a unique property of Poisson distribution!)
3. Formula — Poisson Probability
P(X = k) = (e^(-λ) × λ^k) / k!
Where:
• e = 2.71828... (Euler's number, a mathematical constant)
• λ = 4 (average rate — our parameter)
• k = the specific number of events we want to find probability for
• k! = k factorial = k × (k-1) × (k-2) × ... × 1
Manual calculation of Part (c) — P(X = 0):
• e^(-4) = e^(-λ) = 0.01832
• λ^0 = 4^0 = 1
• 0! = 1
• P(X = 0) = (0.01832 × 1) / 1 = 0.01832
So there is only about 1.8% chance of receiving ZERO calls in any given minute!
In R language:
• dpois(k, lambda) → P(X = k) — exact probability
• ppois(k, lambda) → P(X ≤ k) — cumulative (sum of 0 through k)
4. Complete R Script with Comments
# ============================================================
# QUESTION 3: Poisson Distribution — Call Center (lambda = 4)
# ============================================================
lambda <- 4 # Average number of calls per minute
# ----- PART (a): Exactly 6 Calls -----
# dpois gives the exact probability for a specific value
prob_a <- dpois(6, lambda = lambda)
cat('(a) P(X = 6) =', prob_a, '\n')
# ----- PART (b): At Most 2 Calls -----
# 'At most 2' means 0, 1, or 2 calls — ppois adds them all up
prob_b <- ppois(2, lambda = lambda)
cat('(b) P(X <= 2) =', prob_b, '\n')
# ----- PART (c): No Calls (Zero Calls) -----
prob_c <- dpois(0, lambda = lambda)
cat('(c) P(X = 0) =', prob_c, '\n')
# ----- PART (d): Plot Poisson Distribution -----
# Show distribution for x = 0 to 15 (covers all meaningful values)
x_vals <- 0:15
probs <- dpois(x_vals, lambda = lambda)
barplot(probs,
[Link] = x_vals,
main = 'Poisson Distribution: lambda = 4 (Calls per Minute)',
xlab = 'Number of Calls (X)',
ylab = 'Probability P(X = k)',
col = 'darkcyan',
border = 'white')
abline(v = lambda + 0.5, col = 'red', lty = 2, lwd = 2) # Mark mean
text(5.5, 0.18, paste('Mean = lambda =', lambda), col='red')
5. Line-by-Line Code Explanation
lambda <- 4 Stores the average rate λ = 4. This is the only parameter needed for
Poisson.
dpois(6, lambda=lambda) 'd' = density = exact probability. Gives P(X = 6) using the Poisson
formula.
ppois(2, lambda=lambda) 'p' = cumulative probability. Gives P(X ≤ 2) = P(0)+P(1)+P(2)
automatically.
dpois(0, lambda=lambda) P(X = 0) — probability of receiving zero calls. Uses k=0 in the
formula.
x_vals <- 0:15 We go up to 15 because probabilities beyond 15 are negligibly small
when λ=4.
abline(v=lambda+0.5, Draws a vertical dashed red line at the mean (λ=4). The +0.5 adjusts
col='red', lty=2) for bar chart centering.
text(5.5, 0.18, Adds a text label on the chart near the mean line to explain what
paste('Mean = lambda =', the red line means.
lambda))
6. Final Results
(a) P(X = 6) = dpois(6, 4) = 0.1042 (10.42%)
(b) P(X ≤ 2) = ppois(2, 4) = 0.2381 (23.81%)
(c) P(X = 0) = dpois(0, 4) = 0.0183 ( 1.83%)
Interpretation in Plain English:
• Exactly 6 calls: About 10.4% chance. This is above the average (4), so it's moderately unlikely.
• At most 2 calls: About 23.8% chance — roughly 1 in 4 minutes will be 'quiet' with 0, 1, or 2 calls.
• Zero calls: Very rare! Only 1.83% chance (~1 in every 55 minutes will have complete silence).
QUESTION 4 | Poisson Distribution — Traffic Accidents (lambda = 3)
1. Problem Statement
On average, 3 accidents occur per day at a busy traffic junction. This is a classic Poisson scenario — accidents
happen randomly, independently, and at a constant average rate.
We need to find:
• (a) Exactly 5 accidents on a particular day → P(X = 5)
• (b) At least 4 accidents on a particular day → P(X ≥ 4)
• (c) Fewer than 2 accidents on a particular day → P(X < 2)
• (d) Draw a Poisson probability bar chart
2. Theory — Poisson Distribution (Recap + Extension)
This is another Poisson problem, just like Question 3, but now λ = 3 instead of 4. The same theory applies.
Why Poisson for accidents?
• Accidents happen one at a time (not simultaneously)
• Each accident is independent — one accident doesn't cause the next
• Average rate = 3 per day (constant)
• We want the count of events in a fixed period (1 day)
KEY PARAMETER for this question:
λ (lambda) = 3 (average accidents per day)
X = number of accidents on a particular day
Mean = Variance = λ = 3
P(X ≥ 4) = 1 - P(X ≤ 3) [complement method]
P(X < 2) = P(X ≤ 1) = P(X=0) + P(X=1) [same as ppois(1, 3)]
3. Formula and Calculation Strategy
P(X = k) = (e^(-3) × 3^k) / k!
For Part (b) — P(X ≥ 4): Why use complement?
• P(X ≥ 4) means X can be 4, 5, 6, 7, 8, ... (infinite values!)
• We can't add infinite probabilities directly
• Solution: P(X ≥ 4) = 1 - P(X ≤ 3) — much simpler!
• ppois(3, 3) gives P(X ≤ 3), then subtract from 1
For Part (c) — P(X < 2):
• 'Fewer than 2' means X can only be 0 or 1 (NOT including 2)
• P(X < 2) = P(X ≤ 1) = ppois(1, 3)
• This is NOT the same as P(X ≤ 2) — be careful!
4. Complete R Script with Comments
# ============================================================
# QUESTION 4: Poisson Distribution — Traffic Accidents (lambda=3)
# ============================================================
lambda <- 3 # Average number of accidents per day
# ----- PART (a): Exactly 5 Accidents -----
prob_a <- dpois(5, lambda = lambda)
cat('(a) P(X = 5) =', prob_a, '\n')
# ----- PART (b): At Least 4 Accidents -----
# Strategy: P(X >= 4) = 1 - P(X <= 3) [Complement Rule]
# Direct calculation: P(4)+P(5)+P(6)+... is infinite
# Complement is much easier!
prob_b <- 1 - ppois(3, lambda = lambda)
cat('(b) P(X >= 4) =', prob_b, '\n')
# ----- PART (c): Fewer Than 2 Accidents -----
# 'Fewer than 2' = X < 2 = X <= 1 (i.e., 0 or 1 accidents)
# IMPORTANT: ppois(1,...) not ppois(2,...) because we EXCLUDE 2
prob_c <- ppois(1, lambda = lambda)
cat('(c) P(X < 2) =', prob_c, '\n')
# ----- PART (d): Poisson Bar Chart -----
x_vals <- 0:12 # Display 0 to 12 accidents
probs <- dpois(x_vals, lambda = lambda)
# Color the bars: highlight the three asked regions
bar_cols <- ifelse(x_vals == 5, 'gold',
ifelse(x_vals >= 4, 'tomato',
ifelse(x_vals < 2, 'steelblue', 'lightgray')))
barplot(probs,
[Link] = x_vals,
main = 'Poisson Distribution: lambda = 3 (Accidents per Day)',
xlab = 'Number of Accidents per Day (X)',
ylab = 'Probability P(X = k)',
col = bar_cols,
border = 'white',
ylim = c(0, 0.25))
legend('topright',
legend = c('X=5 (part a)', 'X>=4 (part b)', 'X<2 (part c)',
'Other'),
fill = c('gold', 'tomato', 'steelblue', 'lightgray'))
5. Line-by-Line Code Explanation
lambda <- 3 Set the Poisson parameter λ = 3 (average accidents/day).
dpois(5, lambda=lambda) Exact probability of exactly 5 accidents. Uses formula: e^(-
3)×3^5/5!
1 - ppois(3, P(X≥4) using complement. ppois(3,3) gives P(X≤3); subtract from 1
lambda=lambda) to get P(X≥4).
ppois(1, lambda=lambda) P(X<2) = P(X≤1). We use '1' (not '2') because 'fewer than 2' excludes
X=2.
ifelse(x_vals==5, 'gold', Nested ifelse to assign different colors to bars based on which
ifelse(x_vals>=4, region they belong to. x=5 gets gold; x≥4 gets red; x<2 gets blue;
'tomato', ...))
rest get gray.
legend('topright', Adds a colored legend box to explain what each bar color
legend=..., fill=...) represents.
6. Final Results
(a) P(X = 5) = dpois(5, 3) = 0.1008 (10.08%)
(b) P(X ≥ 4) = 1 - ppois(3, 3) = 0.3528 (35.28%)
(c) P(X < 2) = ppois(1, 3) = 0.1991 (19.91%)
Interpretation in Plain English:
• Exactly 5 accidents: About 10% chance on any given day. Higher than average (3), but not extremely rare.
• At least 4 accidents: About 35% chance! More than 1 in 3 days will see 4 or more accidents. This is a busy
junction!
• Fewer than 2 accidents: About 20% chance — roughly 1 in 5 days will be relatively safe with 0 or 1 accident.
COMPLETE ANSWER SUMMARY | Practical No. 09
All final answers at a glance:
Q Distribution Part R Code Answer
1 Binomial n=12, (a) P(X=5) dbinom(5,12,0.5) ≈ 0.1934 (19.34%)
p=0.5
Fair Coin 12 (b) P(X≤3) pbinom(3,12,0.5) ≈ 0.0730 ( 7.30%)
Tosses
(c) P(X≥8) 1- ≈ 0.1938 (19.38%)
pbinom(7,12,0.5)
2 Binomial n=15, (a) P(X=2) dbinom(2,15,0.1) ≈ 0.2669 (26.69%)
p=0.1
Factory (b) P(X≤3) pbinom(3,15,0.1) ≈ 0.9444 (94.44%)
Defectives
(c) P(X=0) dbinom(0,15,0.1) ≈ 0.2059 (20.59%)
3 Poisson λ=4 (a) P(X=6) dpois(6,4) ≈ 0.1042 (10.42%)
Call Center (b) P(X≤2) ppois(2,4) ≈ 0.2381 (23.81%)
(c) P(X=0) dpois(0,4) ≈ 0.0183 ( 1.83%)
4 Poisson λ=3 (a) P(X=5) dpois(5,3) ≈ 0.1008 (10.08%)
Traffic Accidents (b) P(X≥4) 1-ppois(3,3) ≈ 0.3528 (35.28%)
(c) P(X<2) ppois(1,3) ≈ 0.1991 (19.91%)
Quick R Function Reference — Binomial vs Poisson:
Function Binomial Poisson What it does
d (density) dbinom(k, n, p) dpois(k, lambda) P(X = k) — Exact probability at
one value
p pbinom(k, n, p) ppois(k, lambda) P(X ≤ k) — Sum from 0 up to k
(cumulative)
q (quantile) qbinom(p, n, p) qpois(p, lambda) Inverse: find k given probability
r (random) rbinom(n, size, rpois(n, lambda) Generate n random values from
p) distribution
Key Formulas Summary:
Binomial: P(X=k) = C(n,k) × p^k × (1-p)^(n-k) | Mean=np,
Variance=np(1-p)
Poisson: P(X=k) = (e^(-λ) × λ^k) / k! | Mean = Variance =
λ
REMEMBER — When to use which distribution:
Binomial : Fixed n trials, two outcomes (success/failure), constant p, independent
Examples: coin toss, defective/good, pass/fail, yes/no surveys
Poisson : Counting events in fixed time/space, events are rare & random, constant rate λ
Examples: calls per hour, accidents per day, emails per hour, errors in pages