Continuous Random Variables
Probability Theory
From Counts to Measurements — The World of Densities
Continuous random variables take values on uncountable sets — heights, weights, times, temperatures. Every individual outcome has probability zero; only intervals carry probability.
- Heights — , but
- Time — the exact moment of an event has zero probability
- Temperature — measured on a continuous scale
- Money — can be modeled continuously for large amounts
The density function is not a probability — it is a rate of probability accumulation.
Core Concepts
Continuous random variables take values in an uncountable set (typically an interval of ). Unlike discrete random variables, every individual outcome has probability zero — probability is only meaningful over intervals. This necessitates the density function as the fundamental object of study.
Cumulative Distribution Function (CDF)
The Fundamental Theorem of Calculus Connection
Expectation
Variance
The computational formula is identical to the discrete case, derived in the same way from the definition.
Moments and Moment Generating Functions
Quantile Function and Inverse CDF
Worked Example: Exponential Distribution
Worked Example: Beta Distribution
Worked Example: Change of Variables
Python Implementation
import numpy as np
from scipy import stats
np.random.seed(42)
# Demonstrate PDF properties with exponential distribution
lam = 2.0
x = np.linspace(0, 4, 1000)
pdf_values = stats.expon.pdf(x, scale=1/lam)
cdf_values = stats.expon.cdf(x, scale=1/lam)
# Verify PDF integrates to 1
from scipy.integrate import quad
integral, _ = quad(lambda t: stats.expon.pdf(t, scale=1/lam), 0, np.inf)
print(f"Exponential(lambda={lam})")
print(f" PDF integral: {integral:.6f} (should be 1.0)")
# Verify mean and variance
mean_theory = 1/lam
var_theory = 1/lam**2
print(f" Mean: {mean_theory:.4f}, Variance: {var_theory:.4f}")
# Verify P(X = c) = 0 for continuous RV
print(f" P(X = 1.0): {stats.expon.cdf(1.0, scale=1/lam) - stats.expon.cdf(1.0, scale=1/lam):.6f}")
# Demonstrate probability integral transform
samples = np.random.exponential(1/lam, size=5000)
u_samples = stats.expon.cdf(samples, scale=1/lam)
print(f"\nProbability Integral Transform:")
print(f" Mean of F(X): {np.mean(u_samples):.4f} (should be 0.5)")
print(f" Variance of F(X): {np.var(u_samples, ddof=0):.4f} (should be 1/12 ≈ 0.0833)")
Python Implementation: MGF and Moments
import numpy as np
from scipy import stats
from scipy.integrate import quad
# Compute moments numerically for a standard normal
lam = 1.0 # standard normal: mu=0, sigma=1
# E[X^k] for k = 1, 2, 3, 4
print("Standard Normal Moments:")
for k in range(1, 5):
moment, _ = quad(lambda x: x**k * stats.norm.pdf(x), -np.inf, np.inf)
theory = 0 if k % 2 == 1 else np.math.factorial(k-1) # (k-1)!! for even k
print(f" E[X^{k}] = {moment:.6f} (theoretical: {theory})")
# Verify MGF: M_X(t) = exp(t^2/2) for standard normal
t_values = [0.1, 0.5, 1.0]
print("\nStandard Normal MGF:")
for t in t_values:
mgf_numerical, _ = quad(lambda x: np.exp(t*x) * stats.norm.pdf(x), -np.inf, np.inf)
mgf_theory = np.exp(t**2 / 2)
print(f" M({t}) = {mgf_numerical:.6f} (theoretical: {mgf_theory:.6f})")
# Change of variables: if X ~ N(0,1), then Y = 2X + 3 ~ N(3, 4)
samples_x = np.random.standard_normal(10000)
samples_y = 2 * samples_x + 3
print(f"\nLinear transformation Y = 2X + 3:")
print(f" E[Y] = {np.mean(samples_y):.4f} (theoretical: 3)")
print(f" Var(Y) = {np.var(samples_y, ddof=0):.4f} (theoretical: 4)")