intermediate 25 minutes

Random Variables

Understand random variables and probability distributions. Learn about discrete vs continuous variables, PMF, PDF, CDF, and expected value.

On This Page
Advertisement

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.

Random Variables

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).

Discrete Examples
  • 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).

Continuous Examples
  • 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.

PMF Definition

P(X=x)=f(x)P(X = x) = f(x)

Properties:

  1. f(x)0f(x) \geq 0 for all x
  2. all xf(x)=1\sum_{\text{all } x} f(x) = 1
PMF: Roll a Die

X = number on a fair die

xP(X = x)
11/6
21/6
31/6
41/6
51/6
61/6

Sum: 1/6 × 6 = 1 ✓

PMF: Number of Heads in 2 Flips

X = number of heads when flipping 2 coins

Possible outcomes: HH, HT, TH, TT

xOutcomesP(X = x)
0TT1/4
1HT, TH2/4 = 1/2
2HH1/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.

PDF Definition

P(aXb)=abf(x)dxP(a \leq X \leq b) = \int_a^b f(x) \, dx

Properties:

  1. f(x)0f(x) \geq 0 for all x
  2. f(x)dx=1\int_{-\infty}^{\infty} f(x) \, dx = 1
  3. P(X=x)=0P(X = x) = 0 for any single point
PDF Example

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.

CDF Definition

F(x)=P(Xx)F(x) = P(X \leq x)

For discrete: F(x)=kxP(X=k)F(x) = \sum_{k \leq x} P(X = k)

For continuous: F(x)=xf(t)dtF(x) = \int_{-\infty}^{x} f(t) \, dt

CDF Properties

  1. F(x) is non-decreasing
  2. limxF(x)=0\lim_{x \to -\infty} F(x) = 0
  3. limxF(x)=1\lim_{x \to \infty} F(x) = 1
  4. P(a<Xb)=F(b)F(a)P(a < X \leq b) = F(b) - F(a)
CDF: Die Roll

X = number on a die

xP(X = x)F(x) = P(X ≤ x)
11/61/6
21/62/6
31/63/6 = 1/2
41/64/6
51/65/6
61/66/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.

Expected Value

Discrete: E(X)=μ=xxP(X=x)E(X) = \mu = \sum_{x} x \cdot P(X = x)

Continuous: E(X)=μ=xf(x)dxE(X) = \mu = \int_{-\infty}^{\infty} x \cdot f(x) \, dx

Expected Value: Die Roll

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

Expected Value Properties
  1. E(c)=cE(c) = c (constant)
  2. E(cX)=cE(X)E(cX) = c \cdot E(X)
  3. E(X+Y)=E(X)+E(Y)E(X + Y) = E(X) + E(Y) (always true!)
  4. E(XY)=E(X)E(Y)E(X - Y) = E(X) - E(Y)
  5. E(aX+b)=aE(X)+bE(aX + b) = a \cdot E(X) + b

Variance

Variance measures how spread out the distribution is around the mean.

Variance

Var(X)=σ2=E[(Xμ)2]=E(X2)[E(X)]2Var(X) = \sigma^2 = E[(X - \mu)^2] = E(X^2) - [E(X)]^2

Standard deviation: σ=Var(X)\sigma = \sqrt{Var(X)}

Variance: Die Roll

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

Variance Properties
  1. Var(c)=0Var(c) = 0 (constant has no variance)
  2. Var(cX)=c2Var(X)Var(cX) = c^2 \cdot Var(X)
  3. Var(X+c)=Var(X)Var(X + c) = Var(X) (shifting doesn’t change spread)
  4. Var(aX+b)=a2Var(X)Var(aX + b) = a^2 \cdot Var(X)

For independent X and Y: 5. Var(X+Y)=Var(X)+Var(Y)Var(X + Y) = Var(X) + Var(Y) 6. Var(XY)=Var(X)+Var(Y)Var(X - Y) = Var(X) + Var(Y) (adds, not subtracts!)


Summary Table

ConceptDiscreteContinuous
Probability functionPMF: P(X = x)PDF: f(x)
P(single value)Can be non-zeroAlways 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:

Advertisement

Was this lesson helpful?

Help us improve by sharing your feedback or spreading the word.