Discrete Random Variables — PMF, CDF, and Properties
2530 words
13 min read
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
# Discrete Random Variables — PMF, CDF, and Properties ## 🎯 Learning Objectives After completing this topic, you will be able to: - Define **random variable** and distinguish **discrete** from **continuous** - Construct and interpret a **probability mass function (PMF)** - Construct and interpret a **cumulative dis...

Discrete Random Variables — PMF, CDF, and Properties
🎯 Learning Objectives
After completing this topic, you will be able to:
- Define random variable and distinguish discrete from continuous
- Construct and interpret a probability mass function (PMF)
- Construct and interpret a cumulative distribution function (CDF)
- Compute expected value E(X) and variance Var(X) for discrete random variables
- Apply these concepts to real-world problems
📋 Prerequisites
- Probability Intro (11-probability-intro) — events and probability
- Counting Fundamentals (08-counting-fundamentals) — counting outcomes
- Data Types & Scales (01-data-types-scales) — discrete vs continuous data
📖 Core Content
16.1 Intuition: From Events to Numbers
So far, we've worked with events ("roll an even number"). Random variables transform outcomes into numbers, making them easier to work with mathematically.
Definition: A random variable (RV) is a function that assigns a numerical value to each outcome of a random experiment.
- Discrete random variable: Takes on a countable number of distinct values (e.g., number of heads in 3 coin flips)
- Continuous random variable: Takes on any value in an interval (e.g., height of a person)
Everyday analogy: Think of a random variable as a "measurement" on a random process. Before the experiment, we don't know what number we'll get. Afterward, we have a specific value. 🔑 Key Insight: Random variables turn probability into a mathematical system where we can compute averages, variances, and make predictions.
16.2 Examples of Random Variables
| Experiment | Random Variable | Type | Possible Values |
|---|---|---|---|
| Flip 3 coins | X = # of heads | Discrete | {0, 1, 2, 3} |
| Roll a die | X = number shown | Discrete | {1, 2, 3, 4, 5, 6} |
| Measure height | X = height (cm) | Continuous | (0, ∞) |
| Count customers | X = # of customers/hour | Discrete | {0, 1, 2, ...} |
16.3 Probability Mass Function (PMF)
16.3.1 Definition
The probability mass function p(x) gives the probability that a discrete random variable X equals a specific value x:
Properties:
- 0≤p(x)≤1 for all x
- ∑all xp(x)=1 (probabilities sum to 1)
16.3.2 Example: Sum of Two Dice
Let X = sum when rolling two fair dice.
| x | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| p(x) | 1/36 | 2/36 | 3/36 | 4/36 | 5/36 | 6/36 | 5/36 | 4/36 | 3/36 | 2/36 | 1/36 |
Check: sum = 1+2+3+4+5+6+5+4+3+2+1=36 ✓
16.4 Cumulative Distribution Function (CDF)
16.4.1 Definition
The cumulative distribution function F(x) gives the probability that X is less than or equal to a value:
Properties:
- F(x) is non-decreasing (as x increases, F(x) never decreases)
- limx→−∞F(x)=0
- limx→+∞F(x)=1
- P(a<X≤b)=F(b)−F(a)
16.4.2 Example: Sum of Two Dice
| x | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| F(x) | 1/36 | 3/36 | 6/36 | 10/36 | 15/36 | 21/36 | 26/36 | 30/36 | 33/36 | 35/36 | 1 |
F(5)=P(X≤5)=1/36+2/36+3/36+4/36=10/36
16.5 Expected Value of a Discrete RV
16.5.1 Intuition
The expected value E(X) is the long-run average of the random variable — what you'd expect to get on average over many repetitions.
16.5.2 Definition
E(X)=μX=all x∑x⋅P(X=x)=∑x⋅p(x)16.5.3 Example
Roll a fair die: X=number shown
Interpretation: If you roll a fair die many times, the average will be about 3.5.
16.6 Variance of a Discrete RV
16.6.1 Definition
Var(X)=σX2=E[(X−μ)2]=∑(x−μ)2⋅p(x)Computational formula:
Where E(X2)=∑x2⋅p(x)
16.6.2 Example: Roll a Fair Die
Step 1: μ=3.5
Step 2: E(X2)=12(61)+22(61)+...+62(61) =(1+4+9+16+25+36)/6=91/6≈15.167
Step 3: Var(X)=15.167−3.52=15.167−12.25=2.917
Step 4: σ=2.917≈1.708
16.7 Properties of Expected Value and Variance
| Property | Formula |
|---|---|
| Expected value of constant | E(c)=c |
| Linearity of expectation | E(aX+b)=aE(X)+b |
| Variance of constant | Var(c)=0 |
| Variance linear transformation | Var(aX+b)=a2Var(X) |
| Standard deviation | σX=Var(X) |
16.8 Worked Examples
Example 1: Constructing a PMF (Easy)
Scenario: A bag has 3 red and 5 blue chips. Draw 2 without replacement. Let X = number of red chips drawn.
Find the PMF of X.
Solution:
Possible values: X = 0, 1, 2
P(X=0)=P(both blue)=C(8,2)C(5,2)=2810=145
P(X=2)=P(both red)=C(8,2)C(3,2)=283
P(X=1)=1−P(X=0)−P(X=2)=1−145−283=2828−10−3=2815
PMF:
Check: 2810+2815+283=2828=1 ✓
Example 2: Expected Value in a Game (Medium)
Scenario: A game costs ₹10 to play. You roll a die:
- If even: you win ₹5
- If odd: you win nothing
- If the number is 6: you win ₹20 (including the even win) Find the expected net gain. Solution: Let X = net gain (winnings - cost).
| Outcome | Net Gain X | P(X = x) |
|---|---|---|
| 1 (odd) | 0 - 10 = -10 | 1/6 |
| 3 (odd) | 0 - 10 = -10 | 1/6 |
| 5 (odd) | 0 - 10 = -10 | 1/6 |
| 2,4 (even, not 6) | 5 - 10 = -5 | 2/6 |
| 6 (even, special) | 20 - 10 = 10 | 1/6 |
E(X)=(−10)(3/6)+(−5)(2/6)+(10)(1/6)=−30/6−10/6+10/6=−30/6=−5
So the expected net gain is -₹5 per game. Not a good game to play!
Example 3: PMF and CDF (Harder)
Scenario: Let X = number of heads in 3 coin flips.
a) Find the PMF b) Find the CDF c) Find P(1≤X≤2)
Solution:
a) PMF: X can be 0, 1, 2, 3.
P(X=0)=(1/2)3=1/8 P(X=3)=(1/2)3=1/8 P(X=1)=3×(1/2)3=3/8 (THH, HTH, HHT) P(X=2)=3×(1/2)3=3/8
| x | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| p(x) | 1/8 | 3/8 | 3/8 | 1/8 |
b) CDF:
F(0)=1/8 F(1)=1/8+3/8=4/8=1/2 F(2)=1/8+3/8+3/8=7/8 F(3)=1
c) P(1≤X≤2): Using PMF: p(1)+p(2)=3/8+3/8=3/4 Using CDF: F(2)−F(0)=7/8−1/8=6/8=3/4 ✓
16.9 Edge Cases & Gotchas
Expected Value May Not Be a Possible Value
E(die roll)=3.5, but you can never roll 3.5. The expected value is a long-run average, not the "most likely" value.
Variance Is Always Non-Negative
Var(X)≥0 always. Var(X)=0 only if X is constant (no randomness).
PMF vs PDF
Don't confuse PMF (for discrete) with PDF (for continuous). A PMF gives P(X=x), which can be >0. A PDF gives density, and P(X=x)=0 for continuous variables.
16.10 Why This Matters
Random variables are the foundation of all statistical modeling:
- Week 10: Formal properties of expectation and variance
- Weeks 11-12: Specific distributions (Binomial, Poisson, Normal, etc.)
- BSMA1004 (Stats 2): Sampling distributions are random variables
- BSCS2004 (ML Foundations): Loss functions and risk are expectations
📐 Key Formulas / Concepts
| Concept | Formula | Notes |
|---|---|---|
| PMF | p(x)=P(X=x) | ∑p(x)=1 |
| CDF | F(x)=P(X≤x) | Non-decreasing, ranges [0,1] |
| Expected Value | E(X)=∑x⋅p(x) | Long-run average |
| Expected Value of Function | E(g(X))=∑g(x)⋅p(x) | For any function g |
| Variance | Var(X)=∑(x−μ)2p(x) | Expected squared deviation |
| Computational Variance | Var(X)=E(X2)−[E(X)]2 | Easier calculation |
| Linearity | E(aX+b)=aE(X)+b | Expectation is linear |
| Variance scaling | Var(aX+b)=a2Var(X) | Variance scales by a2 |
⚠️ Common Pitfalls
Pitfall 1: Confusing E(X2) with [E(X)]2
The mistake: Thinking E(X2)=[E(X)]2.
Why it happens: Notation is subtle.
Example: X = {1, 2, 3} equally likely. E(X)=2, [E(X)]2=4 E(X2)=(12+22+32)/3=14/3≈4.67
They're different! Their difference IS the variance.
Pitfall 2: Thinking Expected Value Is the Most Likely Value
The mistake: Saying "the expected number of heads in 3 flips is 1.5" and expecting to see 1.5 heads.
Correction: Expected value is a long-run average, not a prediction for a single trial.
Pitfall 3: Forgetting That PMF Probabilities Must Sum to 1
The mistake: Writing a PMF where probabilities don't sum to 1.
How to check: Always verify ∑p(x)=1 as a sanity check.
📝 Practice Questions
</details> > **Q2: Expected Value** > > </strong> > > X has PMF: $p(1)=0.2$, $p(2)=0.3$, $p(3)=0.4$, $p(4)=0.1$. Find $E(X)$. > > <details> <strong>Solution</strong> > > $E(X) = 1(0.2) + 2(0.3) + 3(0.4) + 4(0.1) = 0.2 + 0.6 + 1.2 + 0.4 = 2.4$ > > $\boxed{E(X) = 2.4}$ </details> > **Q3: Variance** > > </strong> > > Using Q2's distribution, find $Var(X)$. > > <details> <strong>Solution</strong> > > $E(X^2) = 1^2(0.2) + 2^2(0.3) + 3^2(0.4) + 4^2(0.1) = 0.2 + 1.2 + 3.6 + 1.6 = 6.6$ > > $Var(X) = 6.6 - 2.4^2 = 6.6 - 5.76 = 0.84$ > > $\boxed{Var(X) = 0.84}$ </details> > **Q4: CDF** > > </strong> > > X has PMF: $p(0)=0.1$, $p(1)=0.3$, $p(2)=0.2$, $p(3)=0.1$, $p(4)=0.3$. > > Find $F(2)$ and $P(1 \leq X \leq 3)$. > > <details> <strong>Solution</strong> > > $F(2) = p(0) + p(1) + p(2) = 0.1 + 0.3 + 0.2 = 0.6$ > > $P(1 \leq X \leq 3) = p(1) + p(2) + p(3) = 0.3 + 0.2 + 0.1 = 0.6$ > > Or: $F(3) - F(0) = (0.6+0.1) - 0.1 = 0.6$ ✓ > > $\boxed{F(2)=0.6,\ P(1\leq X\leq3)=0.6}$ </details> > **Q5: Linear Transformation** > > </strong> > > If $E(X) = 5$ and $Var(X) = 4$, find $E(3X + 2)$ and $Var(3X + 2)$. > > <details> <strong>Solution</strong> > > $E(3X + 2) = 3E(X) + 2 = 3(5) + 2 = 17$ > > $Var(3X + 2) = 3^2 Var(X) = 9 \times 4 = 36$ > > $\boxed{E = 17,\ Var = 36}$ </details> > **Q6: Application — Insurance** > > </strong> > > An insurance policy costs ₹500. With probability 0.001, the policy pays ₹200,000. With probability 0.01, it pays ₹50,000. Otherwise, it pays nothing. Find the expected value to the insurance company (their profit). > > <details> <strong>Solution</strong> > > Let X = company's profit. > ></strong>Q1: PMF Construction<details> <strong>Solution</strong>A bag has 4 red, 3 green chips. Draw 2 without replacement. X = # of red chips. Find PMF.P(X=0)=C(7,2)C(3,2)=213=71P(X=2)=C(7,2)C(4,2)=216=72P(X=1)=1−71−72=74p(0)=71, p(1)=74, p(2)=72
| Event | Profit (X) | P(X) |
|---|---|---|
| No claim | 500 | 1 - 0.001 - 0.01 = 0.989 |
| Small claim | 500 - 50,000 = -49,500 | 0.01 |
| Large claim | 500 - 200,000 = -199,500 | 0.001 |
</details> > **Q7: Fair Game** > > </strong> > > A game costs c rupees to play. You draw a card: if it's a heart, you win ₹20; if it's an ace (but not hearts), you win ₹10; otherwise, nothing. Find c so the game is fair ($E(\text{net gain}) = 0$). > > <details> <strong>Solution</strong> > > Deck: 52 cards. > > - Heart: 13 cards (incl. Ace of hearts). Win ₹20. > - Non-heart ace: 3 cards (Ace of spades, clubs, diamonds). Win ₹10. > - Other: 52 - 13 - 3 = 36 cards. Win ₹0. > > $E(\text{winnings}) = 20(\frac{13}{52}) + 10(\frac{3}{52}) + 0(\frac{36}{52}) = \frac{260}{52} + \frac{30}{52} = \frac{290}{52} \approx 5.577$ > > To make net gain = 0: $c = E(\text{winnings}) \approx 5.58$ > > So the game should cost about ₹5.58 to play. > > $\boxed{c \approx 5.58}$ </details> > **Q8: PMF Properties** > > Which of the following could be a valid PMF? > > a) $p(1)=0.3$, $p(2)=0.5$, $p(3)=0.2$ b) $p(1)=0.4$, $p(2)=0.4$, $p(3)=0.4$ c) $p(1)=0.5$, $p(2)=0.3$, $p(3)=0.3$ > > <details> <strong>Solution</strong> > > a) Sum = 0.3 + 0.5 + 0.2 = 1.0, each between 0 and 1 → **Valid** ✓ > > b) Sum = 0.4 + 0.4 + 0.4 = 1.2 ≠ 1 → **Invalid** > > c) Sum = 0.5 + 0.3 + 0.3 = 1.1 ≠ 1 → **Invalid** > > Only (a) is a valid PMF. </details> > **Q9: Law of the Unconscious Statistician** > > X has PMF: $p(1)=0.2$, $p(2)=0.5$, $p(3)=0.3$. Find $E(X^2 + 2X)$. > > <details> <strong>Solution</strong> > > **Method 1:** $E(X^2 + 2X) = E(X^2) + 2E(X)$ (linearity) > > $E(X) = 1(0.2) + 2(0.5) + 3(0.3) = 0.2 + 1.0 + 0.9 = 2.1$ $E(X^2) = 1(0.2) + 4(0.5) + 9(0.3) = 0.2 + 2.0 + 2.7 = 4.9$ > > $E(X^2 + 2X) = 4.9 + 2(2.1) = 4.9 + 4.2 = 9.1$ > > **Method 2:** Direct computation $E(X^2 + 2X) = \sum (x^2 + 2x)p(x)$ $= (1+2)(0.2) + (4+4)(0.5) + (9+6)(0.3)$ $= 3(0.2) + 8(0.5) + 15(0.3) = 0.6 + 4.0 + 4.5 = 9.1$ ✓ > > $\boxed{9.1}$ </details> > **Q10: Expected Value in Decision Making** > > A store must decide how many cakes to bake. Each cake costs ₹50 to make and sells for ₹150. Unsold cakes are donated (no salvage value). Daily demand has PMF: > >E(X)=500(0.989)+(−49,500)(0.01)+(−199,500)(0.001) =494.5−495−199.5=−200The company expects to lose ₹200 per policy! They should raise the premium.E(X)=−200
| Demand | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| p(d) | 0.1 | 0.3 | 0.4 | 0.2 |
</details> * * * ## 🔗 Cross-References - **Next topic:** [Continuous Random Variables](/notes/01-foundation-bsma1002-stats-1-week09-16-continuous-random-variables) — the continuous analogue - **Week 10:** Expectation and Variance (deeper dive) - **Week 11 (Distributions):** Bernoulli, Binomial, Poisson, Geometric - **Week 12 (Distributions):** Uniform, Exponential, Normal - **BSMA1004 (Stats 2):** Sampling distributions, central limit theorem [Join Discord](https://discord.gg/gE2m4Qrdqv) [Previous**Bayes' Theorem**](/notes/01-foundation-bsma1002-stats-1-week08-14-bayes-theorem)[Next**Continuous Random Variables**](/notes/01-foundation-bsma1002-stats-1-week09-16-continuous-random-variables)<details> <strong>Solution</strong>How many cakes should they bake to maximize expected profit?Bake 1 cake:
- If demand ≥ 1 (prob 0.9): profit = 150 - 50 = 100
- If demand = 0 (prob 0.1): profit = -50
- E=100(0.9)+(−50)(0.1)=90−5=85
Bake 2 cakes:
- Demand 0: profit = -100 (0.1)
- Demand 1: profit = 150 - 100 = 50 (0.3)
- Demand ≥ 2: profit = 300 - 100 = 200 (0.6)
- E=−100(0.1)+50(0.3)+200(0.6)=−10+15+120=125
Bake 3 cakes:
- Demand 0: profit = -150 (0.1)
- Demand 1: profit = 150 - 150 = 0 (0.3)
- Demand 2: profit = 300 - 150 = 150 (0.4)
- Demand 3: profit = 450 - 150 = 300 (0.2)
- E=−150(0.1)+0(0.3)+150(0.4)+300(0.2)=−15+0+60+60=105
Best: Bake 2 cakes for expected profit of ₹125.Bake 2 cakes, expected profit ₹125