PGD01C01
Module 5 · Probability Theory

Functions of Random Variables and Random Variable Generation

Core Titles
Key headlines and terms for quick recall
  • Transformation Y=g(X)Y = g(X)
  • Discrete case: P(Y=y)=∑x:g(x)=yP(X=x)P(Y = y) = \sum_{x : g(x) = y} P(X = x)
  • Continuous, monotonic gg: fY(y)=fX(g−1(y))∣dg−1dy∣f_Y(y) = f_X(g^{-1}(y)) \left| \dfrac{d g^{-1}}{dy} \right|
  • Inverse Transform Sampling X=F−1(U)X = F^{-1}(U) with U∼Uniform(0,1)U \sim \text{Uniform}(0,1)
  • Common transformations: linear, square, exponential
Basic Idea
What it is, why it matters, how it works

Why transform RVs?

We model with simple RVs (e.g., uniform, normal) and then transform them to get the distribution we need. Examples:

  • Standardising Z=(X−μ)/σZ = (X - \mu)/\sigma.
  • Generating samples from any distribution from uniform random numbers.
  • Variance-stabilising transformations.

Discrete case

For Y=g(X)Y = g(X) with XX discrete: P(Y=y)=∑x:g(x)=yP(X=x).P(Y = y) = \sum_{x : g(x) = y} P(X = x).

Continuous case (monotonic gg)

If gg is differentiable and strictly monotonic with inverse g−1g^{-1}: fY(y)=fX(g−1(y))∣ddyg−1(y)∣.f_Y(y) = f_X\big(g^{-1}(y)\big) \left| \frac{d}{dy} g^{-1}(y) \right|.

For non-monotonic gg, split the domain into monotonic pieces and add contributions.

Linear transformation

Y=aX+bY = aX + b (a≠0a \ne 0): fY(y)=1∣a∣fX ⁣(y−ba).f_Y(y) = \frac{1}{|a|} f_X\!\left( \frac{y - b}{a} \right).

If X∼N(μ,σ2)X \sim N(\mu, \sigma^2) then Y∼N(aμ+b,a2σ2)Y \sim N(a\mu + b, a^2 \sigma^2).

Inverse-transform sampling

Goal: generate samples from any distribution with CDF FF.

Method.

  1. Sample U∼Uniform(0,1)U \sim \text{Uniform}(0, 1).
  2. Compute X=F−1(U)X = F^{-1}(U).

Then XX has CDF FF, since P(X≤x)=P(F−1(U)≤x)=P(U≤F(x))=F(x)P(X \le x) = P(F^{-1}(U) \le x) = P(U \le F(x)) = F(x).

Example. Exponential(λ\lambda): F(x)=1−e−λxF(x) = 1 - e^{-\lambda x}, so F−1(u)=−1λln⁡(1−u)F^{-1}(u) = -\dfrac{1}{\lambda} \ln(1 - u). Generate UU, return −ln⁡(1−U)/λ-\ln(1 - U)/\lambda.

Why this matters in Data Science

Monte Carlo simulation, parametric bootstrap, random sampling from any distribution, generative models.

Mind Map
Visual structure of the concept
FUNCTIONS OF RANDOM VARIABLES
├── Y = g(X)
├── Discrete
│   └── P(Y=y) = Σ_{x: g(x)=y} P(X=x)
├── Continuous (monotonic g)
│   └── f_Y(y) = f_X(g⁻¹(y)) · |d g⁻¹/dy|
├── Linear  Y = aX + b
│   └── f_Y(y) = (1/|a|) f_X((y−b)/a)
└── Inverse-Transform Sampling
    ├── U ~ Uniform(0,1)
    ├── X = F⁻¹(U)
    └── X has CDF F
Exam Q&A
Part A (2 marks) and Part B (20 marks) style questions

Part A (2 marks each)

Q1. State the change-of-variable formula for continuous monotonic transformation. fY(y)=fX(g−1(y))∣dg−1dy∣f_Y(y) = f_X(g^{-1}(y)) \left| \dfrac{d g^{-1}}{dy} \right|.

Q2. If X∼N(μ,σ2)X \sim N(\mu, \sigma^2), find the distribution of Y=aX+bY = aX + b. Y∼N(aμ+b, a2σ2)Y \sim N(a\mu + b, \, a^2\sigma^2).

Q3. What is inverse-transform sampling? A technique to sample from distribution with CDF FF: take U∼Uniform(0,1)U \sim \text{Uniform}(0, 1) and set X=F−1(U)X = F^{-1}(U).

Q4. Generate an exponential sample. For Exp(λ\lambda), X=−ln⁡(1−U)/λX = -\ln(1 - U)/\lambda with U∼Uniform(0,1)U \sim \text{Uniform}(0,1).


Part B (20 marks)

Q. Derive the change-of-variable formula for a continuous random variable. Explain the inverse-transform sampling method with proof. Show how to generate samples from Exp(λ\lambda) using a uniform RV.

Change-of-variable formula.

Let XX have density fXf_X and let gg be a strictly monotonic, differentiable function with inverse g−1g^{-1}. Define Y=g(X)Y = g(X). The CDF of YY:

Case gg increasing: FY(y)=P(Y≤y)=P(g(X)≤y)=P(X≤g−1(y))=FX(g−1(y))F_Y(y) = P(Y \le y) = P(g(X) \le y) = P(X \le g^{-1}(y)) = F_X(g^{-1}(y)).

Differentiating both sides w.r.t. yy using the chain rule: fY(y)=fX(g−1(y))⋅ddyg−1(y)f_Y(y) = f_X(g^{-1}(y)) \cdot \dfrac{d}{dy} g^{-1}(y).

Case gg decreasing: the inequality flips, giving a minus sign. Combining: fY(y)=fX(g−1(y))∣ddyg−1(y)∣.\boxed{f_Y(y) = f_X(g^{-1}(y)) \left| \dfrac{d}{dy} g^{-1}(y) \right|.}

Inverse-transform sampling.

Theorem. If FF is a continuous strictly increasing CDF and U∼Uniform(0,1)U \sim \text{Uniform}(0, 1), then X=F−1(U)X = F^{-1}(U) has CDF FF.

Proof. For any xx, P(X≤x)=P(F−1(U)≤x)=P(U≤F(x))=F(x)P(X \le x) = P(F^{-1}(U) \le x) = P(U \le F(x)) = F(x) (the last step uses U∼Uniform(0,1)U \sim \text{Uniform}(0,1)). Hence XX has CDF FF. ∎

Generating Exp(λ\lambda).

CDF: F(x)=1−e−λxF(x) = 1 - e^{-\lambda x}, x≥0x \ge 0.

Invert: set u=1−e−λxu = 1 - e^{-\lambda x} ⇒ x=−1λln⁡(1−u)x = -\dfrac{1}{\lambda}\ln(1 - u).

Algorithm.

  1. Draw U∼Uniform(0,1)U \sim \text{Uniform}(0, 1).
  2. Return X=−1λln⁡(1−U)X = -\dfrac{1}{\lambda}\ln(1 - U).

Then X∼Exp(λ)X \sim \text{Exp}(\lambda). (Equivalently X=−1λln⁡UX = -\dfrac{1}{\lambda}\ln U works because 1−U1 - U is also uniform on (0,1)(0,1).)