07-01: Continuous, Uniform and Exponential Distributions¶
Discrete variables have gaps; continuous variables do not. That one change forces a different way of computing probability — areas instead of sums — and it is the setup for the normal distribution in 07-02.
From Sums to Areas¶
For a discrete variable you add probabilities. For a continuous variable you measure the area under a curve.
Discrete P(X = x) is a real number, and Σ P(x) = 1
Continuous P(X = x) = 0 for every single value x
P(a ≤ X ≤ b) = area under the density curve between a and b
Total area under the curve = 1
Why P(X = x) = 0? There are infinitely many possible values, so no single one carries positive probability. Ask instead for the probability of an interval.
A convenient consequence: with continuous variables the endpoints do not matter.
That is not true for discrete variables — a distinction worth being deliberate about.
Density function vs. distribution function¶
| Function | Symbol | Meaning |
|---|---|---|
| Probability density function (PDF) | f(x) |
Height of the curve. Not a probability — it can exceed 1 |
| Cumulative distribution function (CDF) | F(x) = P(X ≤ x) |
Area to the left of x. Always between 0 and 1 |
Everything reduces to CDF arithmetic:
Every software function in this chapter is one of those three lines.
The Continuous Uniform Distribution¶
All values in [a, b] are equally likely — the flat rectangle.
1
f(x) = ─────── for a ≤ x ≤ b, 0 otherwise
b − a
x − a
F(x) = ─────────── for a ≤ x ≤ b
b − a
d − c
P(c ≤ X ≤ d) = ───────────────── for a ≤ c ≤ d ≤ b
b − a
Worked example¶
A bus arrives at a uniformly random time between 0 and 20 minutes after you arrive.
a = 0, b = 20, f(x) = 1/20 = 0.05
P(wait ≤ 5 min) = (5 − 0)/20 = 0.25
P(wait between 8 and 12) = (12 − 8)/20 = 0.20
P(wait > 15) = (20 − 15)/20 = 0.25
μ = (0 + 20)/2 = 10 minutes
σ = √(20²/12) = √33.33 = 5.77 minutes
The Exponential Distribution¶
Models the waiting time between events that occur at a constant rate — the continuous partner of the Poisson distribution of 06-02. If events arrive Poisson with rate λ per unit time, the gaps between them are Exponential with the same λ.
Mean and standard deviation are equal — the exponential is always strongly right-skewed.
Memorylessness: P(X > s + t | X > s) = P(X > t). A component that has already survived 5 years is, under this model, exactly as likely to survive another year as a brand-new one.
Worked example¶
Customers arrive at a rate of 4 per hour, so λ = 4 per hour (mean gap 1/4 hour = 15 minutes).
P(next arrival within 10 min) = P(X ≤ 1/6 hr) = 1 − e^(−4/6) = 1 − 0.5134 = 0.4866
P(next arrival takes > 30 min) = P(X > 0.5 hr) = e^(−4 × 0.5) = e^(−2) = 0.1353
P(gap between 10 and 30 min) = 0.8647 − 0.4866 = 0.3781
μ = 1/4 hour = 15 minutes, σ = 15 minutes
Cross-check with the Poisson. P(no arrivals in 30 minutes) from the Poisson with λ = 4(0.5) = 2 is e^(−2) = 0.1353 — the same number. Two views of one process.
Excel¶
' ── UNIFORM (no built-in — the formulas are one-liners) ─────────────
' a in B1, b in B2
=1/(B2-B1) ' density f(x) -> 0.05
=(5-B1)/(B2-B1) ' P(X ≤ 5) -> 0.25
=(12-8)/(B2-B1) ' P(8 ≤ X ≤ 12) -> 0.20
=1-(15-B1)/(B2-B1) ' P(X > 15) -> 0.25
=(B1+B2)/2 ' mean -> 10
=SQRT((B2-B1)^2/12) ' standard deviation -> 5.7735
=B1+RAND()*(B2-B1) ' one random uniform draw
' ── EXPONENTIAL ─────────────────────────────────────────────────────
=EXPON.DIST(1/6, 4, TRUE) ' P(X ≤ 1/6 hr) CDF -> 0.48658
=EXPON.DIST(1/6, 4, FALSE) ' density f(1/6) -> 2.05366
=1-EXPON.DIST(0.5, 4, TRUE) ' P(X > 0.5 hr) -> 0.13534
=EXP(-4*0.5) ' same, by formula -> 0.13534
=EXPON.DIST(0.5,4,TRUE)-EXPON.DIST(1/6,4,TRUE) ' P(1/6 < X < 0.5) -> 0.37808
=1/4 ' mean and SD (both = 1/λ) -> 0.25 hr
' Inverse: the time by which 90% of gaps have elapsed
=-LN(1-0.9)/4 ' -> 0.5756 hours ≈ 34.5 minutes
' Random exponential draw
=-LN(RAND())/4
' ── Cross-check against Poisson ─────────────────────────────────────
=POISSON.DIST(0, 4*0.5, FALSE) ' P(no arrivals in 30 min) -> 0.13534
Note
Excel's EXPON.DIST(x, lambda, cumulative) takes the rate λ, not the mean. If a problem gives you "a mean of 15 minutes", convert: λ = 1/15 per minute, or λ = 4 per hour. Keep the time units consistent throughout.
R¶
# ── UNIFORM: dunif / punif / qunif / runif ────────────────────────
dunif(7, min = 0, max = 20) # density -> 0.05
punif(5, 0, 20) # P(X ≤ 5) -> 0.25
punif(12, 0, 20) - punif(8, 0, 20) # P(8 ≤ X ≤ 12) -> 0.20
punif(15, 0, 20, lower.tail = FALSE) # P(X > 15) -> 0.25
qunif(0.90, 0, 20) # 90th percentile-> 18
runif(5, 0, 20) # 5 random draws
c(mean = (0 + 20)/2, sd = sqrt((20 - 0)^2 / 12)) # 10, 5.7735
curve(dunif(x, 0, 20), from = -2, to = 22, n = 1000,
col = "#5B2A86", lwd = 2, ylab = "f(x)", main = "Uniform(0, 20)")
# ── EXPONENTIAL: dexp / pexp / qexp / rexp ────────────────────────
lambda <- 4 # arrivals per hour
pexp(1/6, rate = lambda) # P(X ≤ 10 min) -> 0.48658
pexp(0.5, lambda, lower.tail = FALSE) # P(X > 30 min) -> 0.13534
pexp(0.5, lambda) - pexp(1/6, lambda) # P(10 < X < 30) -> 0.37808
qexp(0.90, lambda) # 90th pct -> 0.5756 hr
rexp(5, lambda)
c(mean = 1/lambda, sd = 1/lambda) # 0.25, 0.25 hours
curve(dexp(x, lambda), from = 0, to = 1.5, n = 500,
col = "#0FA3A3", lwd = 2, ylab = "f(x)",
main = "Exponential(rate = 4)")
# Cross-check against Poisson
dpois(0, lambda = 4 * 0.5) # 0.13534 — identical
# Memorylessness, verified
pexp(6, 1, lower.tail = FALSE) / pexp(5, 1, lower.tail = FALSE) # P(X>6 | X>5)
pexp(1, 1, lower.tail = FALSE) # P(X>1) — same
Python¶
import numpy as np
from scipy import stats
# ── UNIFORM (loc = a, scale = b − a) ──────────────────────────────
U = stats.uniform(loc=0, scale=20)
U.pdf(7) # density -> 0.05
U.cdf(5) # P(X ≤ 5) -> 0.25
U.cdf(12) - U.cdf(8) # P(8 ≤ X ≤ 12) -> 0.20
U.sf(15) # P(X > 15) -> 0.25
U.ppf(0.90) # 90th percentile-> 18.0
U.rvs(5, random_state=1) # random draws
U.mean(), U.std() # 10.0, 5.7735
# ── EXPONENTIAL (scipy uses SCALE = 1/λ, not the rate!) ───────────
lam = 4 # arrivals per hour
E = stats.expon(scale=1 / lam)
E.cdf(1/6) # P(X ≤ 10 min) -> 0.48658
E.sf(0.5) # P(X > 30 min) -> 0.13534
E.cdf(0.5) - E.cdf(1/6) # P(10 < X < 30) -> 0.37808
E.ppf(0.90) # 90th pct -> 0.5756 hr
E.mean(), E.std() # 0.25, 0.25
# Cross-check against Poisson
stats.poisson.pmf(0, mu=4 * 0.5) # 0.13534 — identical
# Memorylessness
E1 = stats.expon(scale=1)
E1.sf(6) / E1.sf(5), E1.sf(1) # equal
# ── Plot both ──────────────────────────────────────────────────────
import matplotlib.pyplot as plt
fig, (a1, a2) = plt.subplots(1, 2, figsize=(10, 3))
xs = np.linspace(-2, 22, 500)
a1.plot(xs, U.pdf(xs), color="#5B2A86"); a1.set_title("Uniform(0, 20)")
xs = np.linspace(0, 1.5, 500)
a2.plot(xs, E.pdf(xs), color="#0FA3A3"); a2.set_title("Exponential(rate=4)")
plt.tight_layout(); plt.show()
Warning
Parameterization traps. Excel's EXPON.DIST and R's dexp/pexp take the rate λ. SciPy's stats.expon takes the scale 1/λ. Passing 4 where SciPy expects 0.25 gives an answer that looks plausible and is completely wrong. Similarly, SciPy's uniform takes loc and scale = b − a, not a and b.
Quick Reference¶
| Task | Excel | R | Python |
|---|---|---|---|
| Uniform density | 1/(b-a) |
dunif(x,a,b) |
uniform(a, b-a).pdf(x) |
Uniform P(X ≤ x) |
(x-a)/(b-a) |
punif(x,a,b) |
uniform(a, b-a).cdf(x) |
| Uniform percentile | a+p*(b-a) |
qunif(p,a,b) |
uniform(a, b-a).ppf(p) |
| Uniform random | a+RAND()*(b-a) |
runif(n,a,b) |
uniform(a, b-a).rvs(n) |
| Exponential density | EXPON.DIST(x,λ,FALSE) |
dexp(x,λ) |
expon(scale=1/λ).pdf(x) |
Exponential P(X ≤ x) |
EXPON.DIST(x,λ,TRUE) |
pexp(x,λ) |
expon(scale=1/λ).cdf(x) |
Exponential P(X > x) |
EXP(-λ*x) |
pexp(x,λ,lower.tail=FALSE) |
expon(scale=1/λ).sf(x) |
| Exponential percentile | -LN(1-p)/λ |
qexp(p,λ) |
expon(scale=1/λ).ppf(p) |
| Distribution | Mean | Variance | Shape |
|---|---|---|---|
Uniform (a,b) |
(a+b)/2 |
(b−a)²/12 |
Flat rectangle |
Exponential (λ) |
1/λ |
1/λ² |
Right-skewed, decaying |
Common Mistakes¶
- Asking for
P(X = 3)on a continuous variable — it is 0. Ask for an interval. - Passing the mean where the software wants the rate (or vice versa).
- Mixing time units:
λper hour withxin minutes. - Treating the density
f(x)as a probability. ForUniform(0, 0.5)the density is 2 — perfectly legal, and not a probability. - Forgetting that a uniform probability is just
(length of the sub-interval) / (total length)— no calculus needed.
Exercises: 07-01: Exercises — Continuous, Uniform and Exponential Distributions
⬅️ Previous: 06-02: Binomial and Poisson Distributions ➡️ Next: 07-02: The Normal Distribution and Z-Scores