Quiz 2

Week 2.1: Functions of Random Variables

1178 words
6 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Week 2.1: Functions of Random Variables > **Prerequisites:** Joint PMF ([Week 1.1: Joint Probability Mass Function (Joint PMF)](/notes/01-foundation-bsma1004-stats-2-week01-01-joint-pmf)), Conditional Distributions ([Week 1.3: Conditional Distributions](/notes/01-foundation-bsma1004-stats-2-week01-03-conditional-d...

Week 2.1: Functions of Random Variables

Prerequisites: Joint PMF (Week 1.1: Joint Probability Mass Function (Joint PMF)), Conditional Distributions (Week 1.3: Conditional Distributions) Cross-links: BSMA1002 (Stats 1) — transformations of RVs Core question: Given the distribution of XX, what is the distribution of Y=g(X)Y = g(X)?

1. Intuition: The "Push-Forward" Problem

We know the probability of every value of XX. If we apply a function gg, the probability "flows" from XX to Y=g(X)Y = g(X). The question: how does the PMF of YY relate to the PMF of XX?
  • One-to-one functions: Each XX value maps to a unique YY value (e.g., Y=X+5Y = X + 5, Y=2XY = 2^X). Probability transfers directly.
  • Many-to-one functions: Multiple XX values map to the same YY value (e.g., Y=X2Y = X^2, Y=(X5)2Y = (X-5)^2). We must add the probabilities of all XX values that lead to the same YY.

2. General Method: The Table Method

Algorithm (PMF of Y=g(X)Y = g(X))
  1. List all possible values of XX with their probabilities.
  2. Compute y=g(x)y = g(x) for each xx.
  3. Group by yy: for each distinct yy, sum the probabilities of all xx that map to it.
  4. The result is fY(y)f_Y(y). Formula:
fY(y)=P(g(X)=y)=x:g(x)=yfX(x).f_Y(y) = \mathbb{P}(g(X) = y) = \sum_{x: g(x) = y} f_X(x).

3. One-to-One Functions

A function is one-to-one (injective) if g(x1)=g(x2)    x1=x2g(x_1) = g(x_2) \implies x_1 = x_2. Monotonic functions (strictly increasing or decreasing) are one-to-one.
Key result: If gg is one-to-one and Y=g(X)Y = g(X), then
>fY(g(x))=fX(x)or equivalentlyfY(y)=fX(g1(y)).>> f_Y(g(x)) = f_X(x) \quad \text{or equivalently} \quad f_Y(y) = f_X(g^{-1}(y)). >
The PMF shape "shifts" but probability mass is preserved exactly.

Example: Uniform {0,,10}\{0,\dots,10\}, Y=X5Y = X - 5

xxfX(x)f_X(x)y=x5y = x-5
01/11-5
11/11-4
21/11-3
31/11-2
41/11-1
51/110
61/111
71/112
81/113
91/114
101/115
So YUniform{5,4,,5}Y \sim \text{Uniform}\{-5, -4, \dots, 5\}, each with probability 1/111/11.

Example: Binomial(10, 0.5), Y=2XY = 2^X

Each xx maps uniquely to 2x2^x. So fY(2x)=fX(x)f_Y(2^x) = f_X(x). The PMF of YY looks "stretched" — values like 1,2,4,8,,10241, 2, 4, 8, \dots, 1024 each have the same probability as the corresponding xx.

4. Many-to-One Functions

When multiple xx values map to the same yy, we add probabilities.

Example: XUniform{0,,10}X \sim \text{Uniform}\{0,\dots,10\}, Y=(X5)2Y = (X-5)^2

xxfX(x)f_X(x)y=(x5)2y = (x-5)^2
01/1125
11/1116
21/119
31/114
41/111
51/110
61/111
71/114
81/119
91/1116
101/1125
Grouping by yy:
yyfY(y)f_Y(y)Calculation
01/11Only x=5x=5
12/11x=4,6x=4,6
42/11x=3,7x=3,7
92/11x=2,8x=2,8
162/11x=1,9x=1,9
252/11x=0,10x=0,10

Example: Clipped Function

Let XUniform{5,4,,5}X \sim \text{Uniform}\{-5, -4, \dots, 5\} and
g(x)={x,x>00,x0.g(x) = \begin{cases} x, & x > 0 \\ 0, & x \leq 0. \end{cases}
Find fY(y)f_Y(y). Solution: Values x0x \leq 0 (5,4,,0-5,-4,\dots,0) all map to y=0y=0. Each has probability 1/111/11, so:
fY(0)=611(for x=5,4,3,2,1,0).f_Y(0) = \frac{6}{11} \quad (\text{for } x=-5,-4,-3,-2,-1,0).
Values x>0x > 0 (1,2,3,4,51,2,3,4,5) map to themselves:
fY(1)=fY(2)=fY(3)=fY(4)=fY(5)=111.f_Y(1) = f_Y(2) = f_Y(3) = f_Y(4) = f_Y(5) = \frac{1}{11}.
Check: 6/11+5(1/11)=16/11 + 5(1/11) = 1. ✓

5. Functions of Multiple RVs

For Z=g(X1,,Xn)Z = g(X_1, \dots, X_n) with joint PMF fX1Xnf_{X_1\dots X_n}:
>fZ(z)=P(g(X1,,Xn)=z)=(x1,,xn):g(x1,,xn)=zfX1Xn(x1,,xn).>> f_Z(z) = \mathbb{P}(g(X_1,\dots,X_n) = z) = \sum_{(x_1,\dots,x_n): g(x_1,\dots,x_n) = z} f_{X_1\dots X_n}(x_1,\dots,x_n). >
The table method works for small problems. For larger ones, we use contours (sets of (x,y)(x,y) with g(x,y)=zg(x,y) = z).

Example: Sum of Two Dice

X,YUniform{1,,6}X,Y \sim \text{Uniform}\{1,\dots,6\} independent, Z=X+YZ = X + Y. Range: Z{2,3,,12}Z \in \{2,3,\dots,12\}. Counting contour lines:
zzPairs (x,y)(x,y)CountfZ(z)f_Z(z)
2(1,1)11/36
3(1,2),(2,1)22/36
4(1,3),(2,2),(3,1)33/36
5(1,4),(2,3),(3,2),(4,1)44/36
6(1,5),(2,4),(3,3),(4,2),(5,1)55/36
7(1,6),(2,5),(3,4),(4,3),(5,2),(6,1)66/36
8(2,6),(3,5),(4,4),(5,3),(6,2)55/36
9(3,6),(4,5),(5,4),(6,3)44/36
10(4,6),(5,5),(6,4)33/36
11(5,6),(6,5)22/36
12(6,6)11/36

Example: Max of Two Dice

X,YUniform{1,,6}X,Y \sim \text{Uniform}\{1,\dots,6\} independent, W=max(X,Y)W = \max(X,Y). W=wW = w when one die shows ww and the other shows w\leq w, excluding the case where both are <w< w:
fW(w)=2w136.f_W(w) = \frac{2w-1}{36}.
ww123456
fW(w)f_W(w)1/363/365/367/369/3611/36

6. Mermaid: Decision Flow for Finding fg(X)f_{g(X)}

(Diagram)

7. Practice Questions

Q1 (Easy)

XUniform{1,2,3,4}X \sim \text{Uniform}\{1,2,3,4\}, Y=3X2Y = 3X - 2. Find fYf_Y.
Full Solution
One-to-one (linear). YY takes values 1,4,7,101,4,7,10, each with probability 1/41/4.
fY(1)=fY(4)=fY(7)=fY(10)=1/4f_Y(1) = f_Y(4) = f_Y(7) = f_Y(10) = 1/4.

Q2 (Medium)

XUniform{3,2,1,0,1,2,3}X \sim \text{Uniform}\{-3,-2,-1,0,1,2,3\}, Y=XY = |X|. Find fYf_Y.
Full Solution
Many-to-one. Mapping:
Y=0Y=0: X=0X=0 (1 value) → fY(0)=1/7f_Y(0) = 1/7 Y=1Y=1: X=1,1X=-1,1 (2 values) → fY(1)=2/7f_Y(1) = 2/7 Y=2Y=2: X=2,2X=-2,2 (2 values) → fY(2)=2/7f_Y(2) = 2/7 Y=3Y=3: X=3,3X=-3,3 (2 values) → fY(3)=2/7f_Y(3) = 2/7
Check: 1/7+2/7+2/7+2/7=11/7 + 2/7 + 2/7 + 2/7 = 1. ✓

Q3 (Hard)

Let XBinomial(5,0.4)X \sim \text{Binomial}(5, 0.4). Find the PMF of Y=X2Y = X^2.
Full Solution
fX(x)=(5x)(0.4)x(0.6)5xf_X(x) = \binom{5}{x} (0.4)^x (0.6)^{5-x} for x=0,1,2,3,4,5x=0,1,2,3,4,5.
Compute:
  • x=0y=0x=0 \to y=0: fX(0)=(0.6)5=0.07776f_X(0) = (0.6)^5 = 0.07776
  • x=1y=1x=1 \to y=1: fX(1)=5(0.4)(0.6)4=0.2592f_X(1) = 5(0.4)(0.6)^4 = 0.2592
  • x=2y=4x=2 \to y=4: fX(2)=10(0.4)2(0.6)3=0.3456f_X(2) = 10(0.4)^2(0.6)^3 = 0.3456
  • x=3y=9x=3 \to y=9: fX(3)=10(0.4)3(0.6)2=0.2304f_X(3) = 10(0.4)^3(0.6)^2 = 0.2304
  • x=4y=16x=4 \to y=16: fX(4)=5(0.4)4(0.6)=0.0768f_X(4) = 5(0.4)^4(0.6) = 0.0768
  • x=5y=25x=5 \to y=25: fX(5)=(0.4)5=0.01024f_X(5) = (0.4)^5 = 0.01024
This is one-to-one on {0,1,2,3,4,5}\{0,1,2,3,4,5\}, so fY(y)=fX(y)f_Y(y) = f_X(\sqrt{y}) for y{0,1,4,9,16,25}y \in \{0,1,4,9,16,25\}.

Q4 (Exam-style — Max)

Two fair dice are rolled. Find the PMF of W=max(X,Y)W = \max(X,Y) using the contour method.
Full Solution
W=wW = w when (X,Y)(X,Y) is in the set {(x,y):max(x,y)=w}\{(x,y): \max(x,y)=w\}. This means: either X=wX=w and YwY \leq w, or Y=wY=w and XwX \leq w, but subtract the overlap (w,w)(w,w) counted twice.
Count of favourable outcomes: ww (for X=w,Y=1..wX=w, Y=1..w) +w+ w (for Y=w,X=1..wY=w, X=1..w) 1- 1 (double-count (w,w)(w,w)) =2w1= 2w-1.
So fW(w)=2w136f_W(w) = \frac{2w-1}{36} for w=1,,6w=1,\dots,6.
ww123456
fW(w)f_W(w)1/363/365/367/369/3611/36

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.