Random Variables
Understand random variables and probability distributions. Learn about discrete vs continuous variables, PMF, PDF, CDF, and expected value.
On This Page
What is a Random Variable?
A random variable is a numerical outcome of a random process. It assigns a number to each possible outcome in a sample space.
Experiment: Roll a die
Random variables:
- X = the number showing (1, 2, 3, 4, 5, or 6)
- Y = 1 if even, 0 if odd
- Z = X² (the square of the number)
Types of Random Variables
Discrete Random Variables
Takes on countable values (often integers).
- Number of heads in 10 coin flips (0, 1, 2, …, 10)
- Number of customers per hour (0, 1, 2, …)
- Number of defects in a batch (0, 1, 2, …)
- Number of siblings (0, 1, 2, 3, …)
Continuous Random Variables
Takes on any value in an interval (uncountably infinite).
- Height of a person (any value in a range)
- Time until an event occurs
- Temperature readings
- Weight, distance, duration
Probability Mass Function (PMF)
For discrete random variables, the PMF gives the probability of each value.
Properties:
- for all x
X = number on a fair die
| x | P(X = x) |
|---|---|
| 1 | 1/6 |
| 2 | 1/6 |
| 3 | 1/6 |
| 4 | 1/6 |
| 5 | 1/6 |
| 6 | 1/6 |
Sum: 1/6 × 6 = 1 ✓
X = number of heads when flipping 2 coins
Possible outcomes: HH, HT, TH, TT
| x | Outcomes | P(X = x) |
|---|---|---|
| 0 | TT | 1/4 |
| 1 | HT, TH | 2/4 = 1/2 |
| 2 | HH | 1/4 |
Sum: 1/4 + 1/2 + 1/4 = 1 ✓
Probability Density Function (PDF)
For continuous random variables, probabilities are defined for intervals, not individual points.
Properties:
- for all x
- for any single point
X is uniform on [0, 2], meaning f(x) = 0.5 for 0 ≤ x ≤ 2.
What’s P(0.5 ≤ X ≤ 1.5)?
Area under curve from 0.5 to 1.5: = 0.5 × (1.5 - 0.5) = 0.5 × 1 = 0.5
Cumulative Distribution Function (CDF)
The CDF gives the probability that X is less than or equal to some value.
For discrete:
For continuous:
CDF Properties
- F(x) is non-decreasing
X = number on a die
| x | P(X = x) | F(x) = P(X ≤ x) |
|---|---|---|
| 1 | 1/6 | 1/6 |
| 2 | 1/6 | 2/6 |
| 3 | 1/6 | 3/6 = 1/2 |
| 4 | 1/6 | 4/6 |
| 5 | 1/6 | 5/6 |
| 6 | 1/6 | 6/6 = 1 |
P(X ≤ 4) = F(4) = 4/6 = 2/3
Expected Value (Mean)
The expected value is the long-run average value of the random variable.
Discrete:
Continuous:
X = number on a fair die
E(X) = 1(1/6) + 2(1/6) + 3(1/6) + 4(1/6) + 5(1/6) + 6(1/6)
E(X) = (1 + 2 + 3 + 4 + 5 + 6)/6 = 21/6 = 3.5
Note: You can never roll exactly 3.5, but over many rolls, the average approaches 3.5.
Properties of Expected Value
- (constant)
- (always true!)
Variance
Variance measures how spread out the distribution is around the mean.
Standard deviation:
We know E(X) = 3.5
First find E(X²): E(X²) = 1²(1/6) + 2²(1/6) + 3²(1/6) + 4²(1/6) + 5²(1/6) + 6²(1/6) E(X²) = (1 + 4 + 9 + 16 + 25 + 36)/6 = 91/6 ≈ 15.17
Var(X) = E(X²) - [E(X)]² Var(X) = 91/6 - (3.5)² = 91/6 - 12.25 ≈ 2.92
SD(X) = √2.92 ≈ 1.71
Properties of Variance
- (constant has no variance)
- (shifting doesn’t change spread)
For independent X and Y: 5. 6. (adds, not subtracts!)
Summary Table
| Concept | Discrete | Continuous |
|---|---|---|
| Probability function | PMF: P(X = x) | PDF: f(x) |
| P(single value) | Can be non-zero | Always 0 |
| Sum/Integral | ∑ P(X = x) = 1 | ∫ f(x)dx = 1 |
| E(X) | ∑ x·P(X = x) | ∫ x·f(x)dx |
| Var(X) | E(X²) - [E(X)]² | E(X²) - [E(X)]² |
Summary
In this lesson, you learned:
- Random variables assign numbers to random outcomes
- Discrete RVs have countable values; continuous RVs have any value in an interval
- PMF gives probabilities for discrete RVs; PDF for continuous
- CDF F(x) = P(X ≤ x) for both types
- Expected value E(X) is the long-run average
- Variance Var(X) measures spread around the mean
- E(X + Y) = E(X) + E(Y) always
- Var(X + Y) = Var(X) + Var(Y) for independent RVs
Practice Problems
1. X has PMF: P(X = 1) = 0.3, P(X = 2) = 0.5, P(X = 3) = 0.2 Find E(X).
2. For the same X, find Var(X).
3. If E(X) = 10 and Var(X) = 4, find E(3X + 5) and Var(3X + 5).
4. X is uniform on [0, 10]. What’s P(2 ≤ X ≤ 7)?
5. Why is P(X = 5.0000) = 0 for a continuous RV, even if 5 is a possible value?
Click to see answers
1. E(X) = 1(0.3) + 2(0.5) + 3(0.2) = 0.3 + 1.0 + 0.6 = 1.9
2. E(X²) = 1²(0.3) + 2²(0.5) + 3²(0.2) = 0.3 + 2.0 + 1.8 = 4.1
Var(X) = E(X²) - [E(X)]² = 4.1 - 1.9² = 4.1 - 3.61 = 0.49
3. E(3X + 5) = 3·E(X) + 5 = 3(10) + 5 = 35 Var(3X + 5) = 3²·Var(X) = 9(4) = 36
4. For uniform [0, 10], f(x) = 1/10 P(2 ≤ X ≤ 7) = (7-2)/10 = 0.5
5. For continuous RVs, probability equals area under the PDF. A single point has width 0, so area = 0. Probabilities only exist for intervals, not points.
Next Steps
Now explore specific distributions:
- Binomial Distribution - Discrete success/failure trials
- Normal Distribution - The bell curve
- Discrete Distributions - Binomial, Poisson, more
Was this lesson helpful?
Help us improve by sharing your feedback or spreading the word.