• Practice
  • About 17 min
  • 5 practice questions

Random variables, inverse images and their types

Define a random variable as a function on a sample space, find its values and the inverse image of each value, and tell discrete random variables from continuous ones.

If something looks wrong, please tell us.

By the end of this lesson you can

  • Explain why a random variable is a function from a sample space S to the real numbers ℝ.
  • List the values of a random variable and the number of sample points in each inverse image.
  • Build random variables for coins, dice, draws from an urn and simple games.
  • Decide whether a random variable is discrete (counting) or continuous (measuring).

The outcomes of a random experiment are often not numbers: a coin shows H or T, a ball drawn from a bag is red or blue. To calculate averages and spreads we need numbers, so we attach a real number to every outcome, for example 1 to a head and 0 to a tail. That rule of attaching numbers is called a random variable, and it is the starting point of this whole chapter.

What a random variable is

A random variable X is a function from the sample space S into the real numbers ℝ, X : S → ℝ, such that the inverse image of every point, subset or interval of ℝ is an event in S, so that a probability can be assigned to it. Capital letters X, Y, Z name random variables; small letters x, y, z name their possible values. If ω is a sample point, X(ω) is a real number. The range set is R_X = {X(ω) : ω ∈ S}.

For a value x, the set of sample points that X sends to x is the inverse image of x, written X⁻¹(x) = {ω ∈ S : X(ω) = x}. It is an event, and counting its points is the first step towards finding probabilities.

From outcomes to numbers to probabilities

  1. Sample space S All outcomes of the experiment.
  2. Random variable X Attach a real number X(ω) to each outcome.
  3. Inverse images Group the outcomes that give each value x.
  4. Probabilities P(X = x) = probability of the event X⁻¹(x).

Worked example 1: heads minus tails

A coin is tossed three times and X = (number of heads) − (number of tails). The 8 outcomes are HHH, HHT, HTH, THH, HTT, THT, TTH, TTT. Three heads gives 3 − 0 = 3; two heads gives 2 − 1 = 1; one head gives 1 − 2 = −1; no head gives −3. So X takes the values −3, −1, 1, 3. The inverse image of 1 is {HHT, HTH, THH}.

Value of X−3−113Total
Number of points in inverse image13318

Worked example 2: the larger number on two dice

Two dice are rolled; S has 36 ordered pairs (a, b) with a, b ∈ {1, …, 6}. Let X = the larger of a and b (if they are equal, that common number). X takes the values 1 to 6. The inverse image of 3 is {(1, 3), (2, 3), (3, 3), (3, 1), (3, 2)}, which has 5 points. In general the pairs whose larger number is k are those with both numbers at most k (k² pairs) minus those with both at most k − 1 ((k − 1)² pairs), giving k² − (k − 1)² = 2k − 1 points.

Value of X123456Total
Points in inverse image135791136

Worked example 3: drawing from an urn, and a game

An urn holds 5 red and 3 blue balls and 2 balls are drawn at random, so there are ⁸C₂ = 28 equally likely samples. (i) Let X = number of red balls drawn. X = 2 in ⁵C₂ = 10 samples, X = 1 in ⁵C₁ × ³C₁ = 15 samples, and X = 0 in ³C₂ = 3 samples; 10 + 15 + 3 = 28. (ii) Now suppose a player wins ₹10 for each red ball and loses ₹5 for each blue ball, and Y is the amount won. Two red: Y = 2 × 10 = 20. One of each: Y = 10 − 5 = 5. Two blue: Y = 2 × (−5) = −10. So Y takes the values 20, 5 and −10 with 10, 15 and 3 points in their inverse images. The same sample space carries many different random variables.

Types of random variable

We study two types. A discrete random variable has a countable range: it can take only a finite or a countably infinite list of values, each with positive probability, the probabilities adding up to 1. Discrete variables usually count something. A continuous random variable can take any value in an interval of real numbers, and P(X = x) = 0 for every single value x. Continuous variables usually measure something.

Discrete or continuous?

  • Discrete (counting) Range is finite or countably infinite.
    • Number of heads in 3 tosses: 0, 1, 2, 3
    • Number of tosses until the first head: 1, 2, 3, …
    • Customers arriving at a counter in an hour: 0, 1, 2, …
  • Continuous (measuring) Range is an interval of real numbers.
    • Lifetime of a bulb: any value in [0, ∞)
    • Distance from the centre of a disc of radius r to a random point: [0, r]
    • Time taken to complete a phone call
A discrete variable can even be defined on a continuous sample space, for example X(ω) = 1 for every ω in [0, 1].

Notice the example "tosses until the first head": the sample space is {H, TH, TTH, TTTH, …} and X takes the values 1, 2, 3, … without end. It is still discrete, because those values can be listed.

Key takeaways: a random variable is a function X : S → ℝ. Its inverse image X⁻¹(x) is the event "X = x", and counting the points in inverse images is how we begin to find probabilities. Discrete random variables take a list of values (counting); continuous ones take every value in an interval (measuring) and give probability 0 to each single value.

Check your understanding

  1. 1. Two dice are rolled and X is the sum of the numbers shown. How many points are there in the inverse image of 9?

    1. 3
    2. 4
    3. 5
    4. 6
    Show answer

    Answer: B. The pairs with sum 9 are (3, 6), (4, 5), (5, 4) and (6, 3), so the inverse image of 9 has 4 points.

  2. 2. Which of these is a continuous random variable?

    1. The number of students absent from a class today
    2. The time taken by a runner to finish a 100 m race
    3. The number of heads in 10 tosses of a coin
    4. The number of cars passing a signal in an hour
    Show answer

    Answer: B. Time is measured and can take any value in an interval, so it is continuous. The other three count things and take only whole-number values, so they are discrete.

  3. 3. Two balls are drawn from an urn with 4 white and 2 black balls. A player wins ₹10 for each black ball and loses ₹5 for each white ball. Which set gives all the values of the amount won?

    1. {20, 10, 0}
    2. {10, 5, −5}
    3. {20, 5, −10}
    4. {20, −5, −10}
    Show answer

    Answer: C. Two black balls: 2 × 10 = 20. One black and one white: 10 − 5 = 5. Two white: 2 × (−5) = −10. So the values are 20, 5 and −10.

  4. 4. A coin is tossed 4 times and X is the number of heads. How many points are in the inverse image of 2?

    1. 4
    2. 2
    3. 8
    4. 6
    Show answer

    Answer: D. The inverse image of 2 consists of the outcomes with exactly 2 heads among 4 tosses. Choosing the positions of the 2 heads gives ⁴C₂ = 6 outcomes.

  5. 5. Which statement describes a random variable correctly?

    1. A function from the sample space to the real numbers
    2. A number that changes every time it is measured
    3. A function from the real numbers to the sample space
    4. The probability of an event
    Show answer

    Answer: A. A random variable X : S → ℝ assigns a real number to every sample point, so that the inverse image of each value or interval is an event to which a probability can be given.

Privacy · Terms · Refunds · Delivery