Learn
Lesson · Discrete Probability · Random variables

Random Variables

A random variable is a function from the sample space to the reals. Its distribution collects the probabilities of its values, and it is neither random nor a variable.

X : S → ℝ a FUNCTION on outcomes P(X = k) = P({s ∈ S : X(s) = k}) Σ_k P(X = k) = 1 the distribution sums to 1 Different X can share a distribution.
A function, not a variable

Core ideas

What this lesson establishes

Random variables let one sample space answer many questions, by attaching different numbers to the same outcomes.

1

It is a function

X(s) is a number for each outcome s. Nothing about it is random; the randomness is in which s occurs.

2

The distribution is a summary

P(X = k) for each value k. It discards which outcomes gave that value, which is usually exactly what you want.

3

Different variables can share a distribution

The number of heads in three flips and the number of tails have the same distribution and are different functions.

The material

Random variables and distributions

The definition, the distribution, and how several variables interact.

Definition · Random variable

A random variable on a sample space S is a function X : S → ℝ — a function in the sense of “Functions”, in Sets, Relations, and Functions, one value for each element of the domain S. The event X = k is {s ∈ S : X(s) = k}, and P(X = k) is its probability.

The name is doubly misleading, as is traditional. X is a function and it is completely determined; what varies is which outcome occurs. Reading X as a function on outcomes removes most of the confusion this topic causes.

Definition · Probability distribution

The distribution of a discrete random variable X is the list of pairs (k, P(X = k)) over the values X takes. The probabilities are non-negative and sum to 1.

Example · Sum of two dice

S is the 36 pairs and X(a,b) = a + b. Then P(X = 2) = 1/36, P(X = 7) = 6/36, and so on. The distribution is the familiar triangle: 1,2,3,4,5,6,5,4,3,2,1 over 36.

k 2 3 4 5 6 7 8 9 10 11 12 pairs 1 2 3 4 5 6 5 4 3 2 1 P(X = k) 1/36 2/36 3/36 4/36 5/36 6/36 5/36 4/36 3/36 2/36 1/36 The pairs row sums to 36, so the probabilities sum to 36/36 = 1 ✓

Indicator variables

Definition · Indicator

For an event A, the indicator I_A is the random variable equal to 1 when A occurs and 0 otherwise. Its distribution is P(I_A = 1) = P(A).

Indicators look trivial and are the single most useful tool in “Linearity of Expectation”. Any count can be written as a sum of indicators, and expectation adds over sums regardless of dependence.

Several variables together

Definition · Joint distribution and independence

The joint distribution of X and Y is P(X = a, Y = b) for all a, b. They are independent when P(X = a, Y = b) = P(X = a)P(Y = b) for every pair.

Example · Dependent by construction

Roll two dice; let X be the first die and Y the sum. These are dependent: P(Y = 2 | X = 3) = 0 while P(Y = 2) = 1/36. Knowing X restricts Y sharply.

Functions of random variables are random variables: X², X + Y and max(X, Y) are all functions on S. Their distributions are computed by collecting the outcomes, which is the only method available and is usually enough.

Interactive

Distribution, expectation, variance

Definition first, formula second

Distribution
P(X = k)E[X]

Method

Working with a random variable

Define the function before computing anything about it.

1

Say what X(s) is for each outcome

"The number of heads", "the sum", "1 if it rains". A random variable with no stated rule is not defined.

2

Collect the outcomes by value

P(X = k) is the probability of the set of outcomes giving k. This is Combinatorics and Counting's counting again.

3

Check the distribution sums to 1

Every outcome contributes to exactly one value, so the probabilities must total 1. A free check that catches missed cases.

4

For several variables, build the joint table

Independence is a statement about every entry of it, not about a summary.

Random variables

Score 0 / 0

Three coins, two variables

S = {HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}, each 1/8.

X = number of heads Y = 1 if the first flip is heads, else 0 outcome HHH HHT HTH HTT THH THT TTH TTT X 3 2 2 1 2 1 1 0 Y 1 1 1 1 0 0 0 0 Distribution of X: P(0)=1/8 P(1)=3/8 P(2)=3/8 P(3)=1/8 sum 1 ✓ Distribution of Y: P(0)=1/2 P(1)=1/2 sum 1 ✓ Independent? P(X=3, Y=1) = 1/8 P(X=3)P(Y=1) = (1/8)(1/2) = 1/16 NOT equal ⟹ dependent, as expected: Y is part of X.

Y is an indicator, and X is the sum of three such indicators — one per flip. That decomposition is what “Linearity of Expectation” exploits, and it works even though the indicators here are visibly not independent of X.

Common mistakes

1
Treating X as random rather than as a functionX is fixed. Which outcome occurs is what varies, and keeping that straight makes joint distributions readable.
2
Confusing the value with the eventX = 3 is an event — a set of outcomes. P(X = 3) is the probability of that set.
3
Assuming variables on the same space are independentThe first die and the sum live on one sample space and are strongly dependent. Independence must be checked on the joint distribution.

Check your understanding

✓
Finish when you can build a distribution from a sample space unaided.

Roll two dice and let X be the larger of the two values. Write the distribution of X and check it sums to 1. P(X = k) is (2k − 1)/36, and deriving that is the exercise.

Note: Random variables are how one probability space answers many questions: the 36 dice outcomes support the sum, the maximum, the difference, and any other function you care to define, each with its own distribution.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.