07-01: Exercises — Continuous, Uniform and Exponential Distributions¶
Notes reference: 07-01: Continuous, Uniform and Exponential Distributions
Q1: Discrete or continuous — and why it changes the arithmetic¶
For each, say whether P(X = 5) is zero or positive, and explain.
X= number of emails received in an hourX= time in minutes until the next emailX= number of heads in 10 flipsX= weight of a randomly chosen apple in kg
Solution
1. DISCRETE → P(X = 5) is POSITIVE (a specific, attainable count)
2. CONTINUOUS → P(X = 5) = 0. Ask instead for P(4.5 < X < 5.5).
3. DISCRETE → P(X = 5) is POSITIVE
4. CONTINUOUS → P(X = 5) = 0
Consequence for continuous variables:
P(X < a) = P(X ≤ a) and P(a < X < b) = P(a ≤ X ≤ b)
That is NOT true for discrete variables, where the endpoints carry
positive probability. Getting this backwards is what the continuity
correction in 07-02 fixes.
Q2: Uniform distribution¶
A subway train arrives every 12 minutes. You arrive at a random time, so your wait X is uniform on [0, 12].
- The density
f(x) P(wait < 4 minutes)P(wait between 5 and 9 minutes)P(wait > 10 minutes)μandσ- The 90th percentile of the wait
Solution
a = 0, b = 12
1. f(x) = 1/(12 − 0) = 1/12 = 0.08333 for 0 ≤ x ≤ 12, and 0 elsewhere
2. P(X < 4) = (4 − 0)/12 = 4/12 = 0.3333
3. P(5 < X < 9) = (9 − 5)/12 = 4/12 = 0.3333
4. P(X > 10) = (12 − 10)/12 = 2/12 = 0.1667
5. μ = (0 + 12)/2 = 6.0 minutes
σ = √((12 − 0)²/12) = √12 = 3.4641 minutes
6. P90: 0.90 = (x − 0)/12 → x = 10.8 minutes
Note that #2 and #3 give the same answer — for a uniform distribution only the length of the interval matters, not where it sits.
=1/(12-0) ' density -> 0.08333
=(4-0)/(12-0) ' P(X<4) -> 0.33333
=(12-0)/2 ' mean -> 6
=SQRT((12-0)^2/12) ' sd -> 3.4641
=0+0.90*(12-0) ' P90 -> 10.8
punif(4, 0, 12) # 0.3333
punif(9, 0, 12) - punif(5, 0, 12) # 0.3333
punif(10, 0, 12, lower.tail = FALSE) # 0.1667
qunif(0.90, 0, 12) # 10.8
U = stats.uniform(loc=0, scale=12)
U.cdf(4), U.cdf(9) - U.cdf(5), U.sf(10), U.ppf(0.90), U.mean(), U.std()
Q3: Uniform on a non-zero start¶
Delivery times are uniform between 20 and 50 minutes.
P(delivery in under 30 minutes)P(delivery takes 35 to 45 minutes)μandσ- If the company promises "under 45 minutes or it's free", what fraction of orders are free?
Solution
a = 20, b = 50, b − a = 30
1. P(X < 30) = (30 − 20)/30 = 10/30 = 0.3333
2. P(35 < X < 45) = (45 − 35)/30 = 10/30 = 0.3333
3. μ = (20 + 50)/2 = 35 minutes
σ = √(30²/12) = √75 = 8.6603 minutes
4. P(X > 45) = (50 − 45)/30 = 5/30 = 0.1667 → 16.7% of orders are free
Business note: giving away one order in six is expensive. Promising "under 48 minutes" would cut it to 2/30 = 6.7%.
Q4: Exponential — waiting time¶
A call centre receives calls at 6 per hour, so waiting time between calls is exponential with λ = 6 per hour.
- Mean and standard deviation of the wait, in minutes
P(next call within 5 minutes)P(next call takes more than 20 minutes)P(wait between 5 and 20 minutes)- The 95th percentile of the wait
Solution
λ = 6 per hour. Work in hours, convert at the end.
1. μ = 1/λ = 1/6 hour = 10 minutes
σ = 1/λ = 10 minutes (mean = SD for the exponential)
2. 5 minutes = 1/12 hour
P(X ≤ 1/12) = 1 − e^(−6/12) = 1 − e^(−0.5) = 1 − 0.606531 = 0.393469
→ 0.3935
3. 20 minutes = 1/3 hour
P(X > 1/3) = e^(−6/3) = e^(−2) = 0.135335 → 0.1353
4. P(5 < X < 20 min) = P(X ≤ 1/3) − P(X ≤ 1/12)
= (1 − 0.135335) − 0.393469
= 0.864665 − 0.393469 = 0.471196 → 0.4712
5. P95: 1 − e^(−6x) = 0.95 → e^(−6x) = 0.05
−6x = ln(0.05) = −2.995732
x = 0.499289 hours = 29.96 minutes
=EXPON.DIST(1/12, 6, TRUE) ' 0.393469
=1-EXPON.DIST(1/3, 6, TRUE) ' 0.135335
=EXPON.DIST(1/3,6,TRUE)-EXPON.DIST(1/12,6,TRUE) ' 0.471196
=-LN(1-0.95)/6 ' 0.499289 hr = 29.96 min
pexp(1/12, rate = 6) # 0.3934693
pexp(1/3, 6, lower.tail = FALSE) # 0.1353353
qexp(0.95, 6) * 60 # 29.957 minutes
Unit discipline. Keep λ and
xin the same time unit throughout, then convert only the final answer.
Q5: The Poisson–exponential link¶
Using the Q4 call centre (λ = 6 per hour), compute P(no calls in the next 20 minutes) two ways.
Solution
WAY 1 — EXPONENTIAL (waiting time)
"No call in 20 minutes" = "the wait exceeds 20 minutes"
P(X > 1/3 hour) = e^(−6 × 1/3) = e^(−2) = 0.135335
WAY 2 — POISSON (count of events)
In 20 minutes the expected count is λ' = 6 × (1/3) = 2
P(N = 0) = 2⁰ e^(−2) / 0! = e^(−2) = 0.135335
IDENTICAL — 0.1353.
They are two views of the same process: Poisson counts the events,
exponential measures the gaps between them.
Q6: Memorylessness¶
A component's lifetime is exponential with a mean of 5 years.
P(it lasts more than 3 years)P(it lasts more than 8 years)- Given that it has already lasted 5 years,
P(it lasts 3 more) - Compare #3 with #1 and explain.
Solution
Mean 5 years → λ = 1/5 = 0.2 per year
1. P(X > 3) = e^(−0.2 × 3) = e^(−0.6) = 0.548812
2. P(X > 8) = e^(−0.2 × 8) = e^(−1.6) = 0.201897
3. P(X > 8 | X > 5) = P(X > 8) / P(X > 5)
= e^(−1.6) / e^(−1.0)
= 0.201897 / 0.367879
= 0.548812
4. #3 = #1 EXACTLY. This is MEMORYLESSNESS:
P(X > s + t | X > s) = P(X > t)
A 5-year-old component is, under this model, exactly as likely to
survive another 3 years as a brand-new one.
WHEN THIS IS WRONG: real components wear out, so their failure rate
RISES with age. The exponential is appropriate for random, age-independent
failures (a lightning strike, a cosmic-ray bit flip), not for mechanical
wear. Use a Weibull distribution when the failure rate changes with age.
Q7: Density is not probability¶
A uniform distribution on [0, 0.5] has f(x) = 2.
- Is a "probability" of 2 legal?
- What IS the probability that
Xfalls in[0.1, 0.3]?
Solution
1. f(x) = 1/(0.5 − 0) = 2. This is a DENSITY, not a probability.
Densities may exceed 1 — they are probability PER UNIT of x.
Only AREAS are probabilities, and areas are still ≤ 1:
total area = 2 × 0.5 = 1 ✓
2. P(0.1 ≤ X ≤ 0.3) = width × height = (0.3 − 0.1) × 2 = 0.4
Rule: for a continuous variable, PROBABILITY = AREA UNDER THE CURVE.
The height alone means nothing on its own.
Q8: Simulate and check¶
Simulate 100,000 exponential waits with λ = 6 per hour and verify the theoretical mean, SD, and P(X > 1/3).
Solution
set.seed(3)
w <- rexp(1e5, rate = 6)
c(theory_mean = 1/6, sim_mean = mean(w))
c(theory_sd = 1/6, sim_sd = sd(w))
c(theory_p = exp(-2), sim_p = mean(w > 1/3))
hist(w, breaks = 60, col = "#0FA3A3", border = NA, freq = FALSE,
main = "Exponential(rate = 6)", xlab = "hours")
curve(dexp(x, 6), add = TRUE, col = "#5B2A86", lwd = 2)
rng = np.random.default_rng(3)
w = rng.exponential(scale=1/6, size=100_000)
1/6, w.mean()
1/6, w.std(ddof=1)
np.exp(-2), (w > 1/3).mean()
' A2: =-LN(RAND())/6 — inverse-transform sampling; fill down 10,000 rows
=AVERAGE(A2:A10001) ' ≈ 0.1667
=STDEV.S(A2:A10001) ' ≈ 0.1667
=COUNTIF(A2:A10001,">"&1/3)/10000 ' ≈ 0.1353
What to notice: the simulated mean and SD are both close to 1/6 — the exponential's signature property, and a good sanity check that your λ/scale parameterization is right.
⬅️ Previous: 06-02: Exercises — Binomial and Poisson Distributions ➡️ Next: 07-02: Exercises — The Normal Distribution and Z-Scores