WordGPT
← Math: from algebra to machine learning

Probability and statistics · Part 3 of 5

Random variables and distributions

Learn what random variables are, how PMFs, CDFs and PDFs describe them, and how to compute probabilities from a distribution.

A coin flip gives you heads or tails; a die gives you 1 through 6; the temperature tomorrow is some real number. To do math with uncertain outcomes, we need to attach numbers to them and describe which numbers are more or less likely. That is exactly what a random variable and its distribution do.

Once a random variable has a distribution, questions like "how likely is at least 4 heads in 5 flips?" or "what is the chance the temperature lands between 2 and 5 degrees?" become straightforward calculations. This lesson builds that machinery; the next lesson uses it to define the average behavior (expectation) and spread (variance) of a random variable.

What a random variable is

A random variable is a variable whose value is the numerical result of a random experiment. It is neither a formula nor a mystery object: it is just a rule that assigns a number to each outcome.

For example, flip two coins and let be the number of heads. The outcomes are HH, HT, TH, TT, and takes the values respectively. We write for the event "both coins are heads".

A discrete random variable takes a countable list of values (like ). A continuous random variable can take any value in an interval, like a measured temperature. The two types are described with slightly different tools, covered below.

Bar chart with values 0, 1, 2 on the horizontal axis and heights 0.25, 0.5, 0.25, the probabilities of 0, 1, and 2 heads in two coin flips.00.20.40.2500.510.252
The PMF of the number of heads in two fair coin flips: each of the four outcomes is equally likely, so the middle values are more probable because more outcomes map to them.

Example 1. Listing the values of a random variable Roll one fair die and let be the number shown. What values can take, and what is ?

The die shows one of , so .

Each face is equally likely, so

Check: the six probabilities add up to , as they must.

Probability mass functions (discrete case)

For a discrete random variable , the probability mass function (PMF) is a function with

A PMF must satisfy two rules:

  • for every ,
  • (the probabilities of all possible values cover everything that can happen).

Any table or formula meeting these two rules is a valid distribution. Probabilities of events follow by adding up the PMF over the event: for example, , and in general

that is, you add for every value the variable can take that is at most 3. If the possible values include or negative numbers, they count too.

Bar chart of p(x) = x/10 for x = 1 to 4, with heights 0.1, 0.2, 0.3 and 0.4 summing to 1.00.10.20.30.40.110.220.330.44
The PMF p(x) = x/10 from the worked example: the bars rise linearly and their heights sum to exactly 1, as a PMF must.

Example 2. Finding a missing constant in a PMF A random variable takes values with . Find .

The probabilities must sum to 1:

So , , , . Each is nonnegative and they sum to 1, so this is a valid PMF.

Cumulative distribution functions

Both discrete and continuous random variables have a cumulative distribution function (CDF):

The CDF answers "what is the chance the value is at most ?". It is always nondecreasing, starts at and ends at as goes from to .

For a discrete variable, is the running sum of the PMF over all values up to . Two useful consequences:

So once you know , every "between" or "at least" question is a subtraction away.

Interactive bar chart of the binomial PMF, binomial(n,k) p^k (1-p)^(n-k), for k from 0 to n, with sliders for n and p, initially n = 5 and p = 0.5.00.10.20.30.031200.15610.31320.31330.15640.0312506070809010
The binomial distribution for n trials with success probability p. Drag p toward 0 or 1 and watch the mass pile up at one end; increase n and see it spread out.

Example 3. Using a CDF to find a probability Flip 3 fair coins and let be the number of heads. Its CDF gives . Compute and then .

There are equally likely outcomes.

Then "at least 2 heads" is the complement of "at most 1 head":

Check by direct counting: outcomes with 2 or 3 heads are HHT, HTH, THH, HHH — 4 of 8, which is . ✓

The binomial distribution, a workhorse example

Many experiments consist of independent trials, each succeeding with probability . The number of successes has the binomial distribution:

The binomial coefficient counts how many ways successes can be placed among the trials; is the probability of any one such arrangement.

You already have the tools to recognize this situation: independent trials with constant success probability — the same setup as the coin-flip tree from earlier lessons, now compressed into one formula.

Bar chart of binomial probabilities for n = 4, p = 0.7: heights 0.0081, 0.0756, 0.2646, 0.4116 and 0.2401 for k = 0 through 4.00.10.20.30.40.008100.075610.26520.41230.244
The five binomial probabilities for the free-throw example (n = 4, p = 0.7). The bar at k = 3 is the answer 0.4116, and all five bars together sum to 1.

Example 4. A binomial probability A basketball player makes each free throw with probability . She takes 4 shots. What is the probability she makes exactly 3?

This is binomial with , , .

Check: computing all five binomial probabilities gives , so the model is consistent.

Continuous random variables and density functions

A continuous random variable can take any value in an interval, so the chance of hitting one exact value is : . Instead we describe it with a probability density function (PDF) , where probabilities come from areas:

A PDF must satisfy:

  • ,
  • (total area under the curve is 1).

The CDF is , and by the fundamental theorem of calculus, is the derivative of .

The simplest continuous distribution is the uniform one on : on the interval and elsewhere. Probabilities are just length of the subinterval divided by length of the whole interval.

Plot of the constant density 1/10 from x = 0 to 10, with the region between x = 2 and x = 5 shaded; the shaded area equals 0.3.024681000.050.10.15f(x) = 1/10
The uniform density f(x) = 1/10 on [0, 10]. The shaded area from 2 to 5 has width 3 and height 1/10, so its area — the probability — is 3/10.

Example 5. A uniform random variable A bus arrives at a uniformly random time between 0 and 10 minutes after you reach the stop. What is the probability it arrives between minutes 2 and 5?

The density is on .

So the probability is . Check: the interval has length 3 out of a total length of 10, and . ✓

A practical workflow

When a problem mentions a random quantity, work in this order:

  1. Identify the variable. What number is being recorded? (Number of successes, waiting time, measurement.)
  2. Decide discrete or continuous. Counted things are discrete; measured things are usually continuous.
  3. Write down the distribution. For counts of independent trials with success probability , use the binomial PMF. For a value spread evenly over an interval, use the uniform density. Otherwise, the PMF or PDF may be given directly.
  4. Convert the question into a probability statement. "At least 3" is ; "between 2 and 5" is .
  5. Compute by summing the PMF or integrating the PDF, using complements and the CDF when they shorten the work.

The distribution is the complete description of the random variable: everything downstream — expectations, variances, approximations — is computed from it, which is exactly where the next lesson goes.

Example 6. Putting the workflow together Flip a fair coin 5 times. Let be the number of heads. Find .

counts successes in 5 independent trials with , so is binomial with , .

"At least 4" means or :

Check: , and counting directly, the outcomes with 4 or 5 heads number out of . ✓

Common mistakes

  • Treating for a continuous variable as a positive number — it is ; only intervals like have positive probability.
  • Forgetting that a PMF or PDF must total 1, e.g. leaving an unknown constant like unsolved instead of setting the sum or integral equal to 1.
  • Confusing the PMF with the CDF: is the probability of exactly 2, while is the probability of 2 or less.
  • Using the binomial formula when trials are not independent or changes between trials — the formula requires both conditions.
  • Computing as instead of ; the complement of "at least " is "at most ".

Practice

  1. A random variable takes values with PMF . Find .
  2. Roll a fair six-sided die and let be the number shown. Compute .
  3. Flip a fair coin 4 times and let be the number of heads. Compute .
  4. Flip a fair coin 5 times and let be the number of heads. Compute .
  5. A spinner lands uniformly at random at a point in the interval . Compute .
Answers
  1. , because must equal 1.
  2. , since the favorable outcomes are 4 of the 6 equally likely faces.
  3. , since .
  4. , since .
  5. , because for a uniform distribution on the probability is the interval length divided by .

Now that a distribution tells you every probability, the next lesson on Expectation and variance shows how to summarize a whole distribution with two numbers: its center and its spread.

Part of the free WordGPT Learn section. WordGPT is an AI writing workspace for documents, resumes, websites and study.