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(g1(y))dg1dyf_Y(y) = f_X(g^{-1}(y)) \left| \dfrac{d g^{-1}}{dy} \right|
  • Inverse Transform Sampling X=F1(U)X = F^{-1}(U) with UUniform(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 g1g^{-1}: fY(y)=fX(g1(y))ddyg1(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 (a0a \ne 0): fY(y)=1afX ⁣(yba).f_Y(y) = \frac{1}{|a|} f_X\!\left( \frac{y - b}{a} \right).

If XN(μ,σ2)X \sim N(\mu, \sigma^2) then YN(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 UUniform(0,1)U \sim \text{Uniform}(0, 1).
  2. Compute X=F1(U)X = F^{-1}(U).

Then XX has CDF FF, since P(Xx)=P(F1(U)x)=P(UF(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)=1eλxF(x) = 1 - e^{-\lambda x}, so F1(u)=1λln(1u)F^{-1}(u) = -\dfrac{1}{\lambda} \ln(1 - u). Generate UU, return ln(1U)/λ-\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(g1(y))dg1dyf_Y(y) = f_X(g^{-1}(y)) \left| \dfrac{d g^{-1}}{dy} \right|.

Q2. If XN(μ,σ2)X \sim N(\mu, \sigma^2), find the distribution of Y=aX+bY = aX + b. YN(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 UUniform(0,1)U \sim \text{Uniform}(0, 1) and set X=F1(U)X = F^{-1}(U).

Q4. Generate an exponential sample. For Exp(λ\lambda), X=ln(1U)/λX = -\ln(1 - U)/\lambda with UUniform(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 g1g^{-1}. Define Y=g(X)Y = g(X). The CDF of YY:

Case gg increasing: FY(y)=P(Yy)=P(g(X)y)=P(Xg1(y))=FX(g1(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(g1(y))ddyg1(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(g1(y))ddyg1(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 UUniform(0,1)U \sim \text{Uniform}(0, 1), then X=F1(U)X = F^{-1}(U) has CDF FF.

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

Generating Exp(λ\lambda).

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

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

Algorithm.

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

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