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.
DfProbability Density Function (PDF)
A function is the PDF of a continuous random variable if:
Equivalently, satisfies: (i) for all , and (ii) .
PDF vs Probability
The PDF value is not a probability — it is a density. It is possible for as long as the total integral is 1. For example, has for . The probability of any single point is always zero: .
Cumulative Distribution Function (CDF)
DfCDF
The cumulative distribution function of is:
ThProperties of the CDF
For any CDF :
(i) is non-decreasing:
(ii) and
(iii) is right-continuous:
(iv)
(v) for all when is continuous (since is continuous)
Probability Over an Interval
Here,
- =Probability density function
- =Cumulative distribution function
- =Interval endpoints with a < b
The Fundamental Theorem of Calculus Connection
PDF-CDF Relationship
When is continuous at , the fundamental theorem of calculus gives:
This means the PDF is the derivative of the CDF. In cases where has jump discontinuities (mixed distributions), we use the generalized derivative, which includes Dirac delta contributions.
Expectation
Continuous Expectation
Here,
- =PDF of X
- =Expected value (first moment)
Derivation of the Change of Variables Formula
For a measurable function , the law of the unconscious statistician states:
Proof sketch: For a simple function , this follows from the definition of the integral. For general , approximate by simple functions and use monotone convergence.
This is powerful: to find , you don't need the distribution of — you integrate against the PDF of directly.
Variance
Continuous Variance
Here,
- =Mean of X
- =Second raw moment
The computational formula is identical to the discrete case, derived in the same way from the definition.
Moments and Moment Generating Functions
k-th Moment
Here,
- =Moment order (positive integer)
Moment Generating Function
Here,
- =Real parameter in neighborhood of 0
Why MGFs Matter
If exists in a neighborhood of , it uniquely determines the distribution. All moments can be recovered:
Furthermore, if and are independent, — the convolution becomes multiplication.
Quantile Function and Inverse CDF
DfQuantile Function
The quantile function (inverse CDF) of is:
It satisfies and .
Probability Integral Transform
If has continuous CDF , then . Conversely, if and is any CDF, then has CDF . This is the foundation of inverse transform sampling for random variate generation.
Worked Example: Exponential Distribution
Example: Full Analysis of Exp($\lambda$)
Let with for .
CDF: for .
Mean: (integration by parts).
Second moment: (two applications of integration by parts).
Variance: .
MGF: for .
Memoryless property: .
Hazard rate: (constant).
This shows the exponential distribution is the continuous analogue of the geometric distribution: both are memoryless with constant hazard rates.
Worked Example: Beta Distribution
Example: Beta$(\alpha, \beta)$ on [0,1]
Let with for , where .
Mean: .
Variance: .
Special cases:
- is symmetric about for all
- As with fixed, the distribution concentrates at
The Beta distribution is the conjugate prior for the Binomial likelihood in Bayesian inference.
Worked Example: Change of Variables
Example: Linear Transformation
Let have PDF and let with . Then:
Application: If , then :
This is the standard normal PDF — the normalization constant emerges naturally from the transformation.
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)")
Key Takeaways
Summary: Continuous Random Variables
- PDF with ; probability is area under the curve:
- CDF: ; satisfies where is continuous
- for any exact value — probability is only meaningful over intervals
- Expectation: (law of the unconscious statistician)
- Variance: (same formula as discrete case)
- MGF: uniquely determines the distribution and converts convolution to multiplication
- Probability integral transform: — the basis for random variate generation
- Change of variables: for