Lecture: Random Variables
Lecture script · about 15–20 minutes spoken · Week 6
Opening
Think about a nurse in an emergency room planning tonight's staff. Nobody knows how many patients will walk through the door in the next hour. Chance will decide that number. Still, the nurse can plan, because the count has a typical value and a typical swing. A delivery driver plans a route the same way, around how long it usually takes and how much that time varies.
That is this week in a sentence. We take a number that chance sets, and we learn to say what it's worth on average and how far it tends to wander.
In Weeks 1 through 4 you described data you already had. Last week, in Week 5, you put a number on chance itself. Today we join those two halves. Your Week 3 tools, the mean and the standard deviation, come back, but now they describe a chance process instead of a list. Next week, in Week 7, Binomial & Normal Models, you'll meet two ready-made distributions that the rest of the course leans on.
We'll take six ideas in order: random variables, probability distributions, expected value, variance and standard deviation, shifting and rescaling, and density curves. Our examples come from dice, the calendar, and the penguins you've known since Week 1.
1. Random variables: put a number on a chance outcome
Hold a die before you roll it. You can't say which face will land on top. But you can say it'll be 1, 2, 3, 4, 5, or 6. The face is a number, and chance picks it.
That's the first idea. A random variable is a number whose value is set by the outcome of a chance process, such as the face that lands on top when you roll a die. We give it a capital letter. Call the face of one die X.
Random variables come in two kinds, and you already know the split from Week 1. A discrete random variable is a random variable whose possible values can be listed with gaps between them, such as the sum of two dice or the number of days in a month. A continuous random variable is a random variable that can take any value in a range, such as the body mass of a penguin picked at random.
Here are the four we'll use all week. The face of one die is discrete. The sum of two dice, which runs from 2 to 12, is discrete. Pick a month at random from a common year, and its number of days can only be 28, 30, or 31, so that's discrete too. Now pick a penguin at random from the 342 birds with a recorded body mass. Its mass could be anything from 2,700 grams to 6,300 grams, any value in between. That one is continuous.
Here's a trap. People often decide by looking for decimals. Whole numbers feel discrete, and decimals feel continuous. But the penguin file records mass in whole grams, and mass is still continuous. The real test is this: can you list the possible values, with gaps between them? If you can, it's discrete.
Pause and try this. The number of days in a randomly picked month is always a whole number. Is that why it's discrete, or is there a better reason?
Hold your answer for a second before you go on.
Here's the answer. The better reason is that you can list its values, 28, 30, and 31, with gaps between them. Being a whole number isn't the test; being listable is.
2. Probability distributions: check that the table is legitimate
Knowing the possible values is only half the story. You also need to know how likely each one is.
That description has a name. A probability distribution is a list or rule that gives every possible value of a random variable together with its probability.
A legitimate probability distribution is a probability distribution in which every probability is between 0 and 1 and the probabilities of all the possible values add to exactly 1. Those two checks come straight from last week.
Try them on the die. Each face has a probability of 1 out of 6. Each of those sits between 0 and 1. And six of them add to exactly 1. So the die's table passes.
Now the sum of two dice. Last week you counted the 36 equally likely ways two dice can land. Group them by total. A total of 2 happens 1 way, a total of 3 happens 2 ways, and so on up to 6 ways for a total of 7. Then the count falls back to 1 way for a total of 12. Add all the ways and you get 36, so the probabilities add to 36 out of 36, which is 1. You can read chances straight off that table. A total of 10 or more takes 3 plus 2 plus 1 ways, which is 6 out of 36, or 1 out of 6.
The table has a shape, too. Picture a bar for each total. The bars climb to a peak at 7 and fall away evenly, so the shape is symmetric. The die's bars, by contrast, are all the same height.
The months pass the checks as well. February has 28 days, four months have 30, and seven months have 31. So the chances are 1 out of 12, 4 out of 12, and 7 out of 12, which add to 12 out of 12.
Here's how a table can fail. Suppose someone miscounts and lists eight 31-day months. Then the chances add to 13 out of 12. Each entry still looks like a fine probability. Only the total gives the mistake away.
Pause and try this. In that miscounted month table, which of the two checks fails, and which one still passes?
Go through each check in turn.
Here's the answer. The total check fails, because 13 out of 12 is more than 1. The other check still passes, since every single entry sits between 0 and 1. That's why you always add the column.
3. Expected value: the long-run average, not the next result
Imagine rolling one die thousands of times and keeping a running average. At first it jumps around. Then it settles, the same way the share of sixes settled in last week's law of large numbers. The number it settles near is the die's expected value.
Here's the definition. The expected value is the probability-weighted average of a random variable's values, found by multiplying each value by its probability and adding the products; it is the long-run average over many repetitions and need not be a possible value. We write it as E of X. It's also called the mean of the distribution, the Greek letter mu.
For the die, multiply each face by 1 out of 6 and add. That's the same as adding the faces, 1 through 6, which gives 21, and 21 divided by 6 is 3.5, so the long-run average roll is 3.5.
Now stop and think about that number. No die has a face showing 3.5. That's the classic mistake of the week. People read the expected value as a forecast for the next try. It isn't. It's what the results average out to over many tries.
The sum of two dice works the same way. Multiply each total by its number of ways, add those products to get 252, and divide by 36. The expected total is 7. Two dice give a long-run average twice as big as one die's 3.5, because each die adds about 3.5 on average.
The calendar gives a friendly example. Weight 28 days by 1 out of 12, 30 days by 4 out of 12, and 31 days by 7 out of 12. The 12 months together hold 365 days, so the expected length is 365 divided by 12, about 30.42 days. No month has 30.42 days. But a person budgeting by the month is right on average, and wrong for every single month.
Pause and try this. A friend says, "The expected value of the die is 3.5, so on my next roll I should get about 3.5." What would you tell them?
Think about what the number actually describes.
Here's the answer. The next roll will show a whole face, from 1 to 6, never 3.5. The 3.5 describes the average of many rolls, so it's a promise about the long run and says nothing certain about one roll.
4. Variance and standard deviation: measure how far results typically land
Two games can have the same expected value and still feel completely different: one pays close to its average every time, and the other swings from nothing to a lot. You need a measure of spread, and you built one in Week 3.
Var(X) is the variance of a random variable X: multiply each squared deviation from the mean by its probability and add the products; it is measured in squared units. SD(X) is the standard deviation of a random variable X, the square root of Var(X); it describes how far the variable's value typically lands from its mean, in the variable's own units. The standard deviation also goes by the Greek letter sigma.
Walk it through on the die. The mean is 3.5. Each face sits some distance from it, from 2.5 below up to 2.5 above. Square those six distances and they add to 17.5. Every face has a probability of 1 out of 6, so the variance is 17.5 times 1 out of 6. That's 35 over 12, about 2.9167 square units. The square root brings us back to plain units: about 1.71.
They're exactly Week 3's population variance and standard deviation of the six faces. In Week 3 they described a list. Now they describe a process you can repeat forever. A single roll typically lands about 1.71 away from 3.5.
For two dice the same steps give a variance of 35 over 6, about 5.83, and a standard deviation of about 2.4152. In plain words, a two-dice total typically lands about 2.4 away from 7. The months are much calmer. Their standard deviation is only about 0.86 days.
There's one trap here, and it comes straight from Week 3. In Week 3 you divided by one less than the count for a sample. If you do that with the six faces, you get 3.5, which is the sample variance. But a probability distribution describes the whole process, like a population. So you weight by the probabilities, and you never divide by one less.
Pause and try this. Someone reports the die's variance as 3.5. What did they most likely do, and what's the right value?
Run back through the two Week 3 formulas.
Here's the answer. They used the sample rule and divided 17.5 by one less than six. A probability distribution weights by the probabilities instead, so the variance is 35 over 12, about 2.9167 square units.
5. Shifting and rescaling: predict the new mean and SD
Sometimes you measure the same random thing on a new scale, from a new starting point or in new units. You don't have to rebuild the whole distribution. Two short rules do the work.
The first is shifting: adding the same constant to every value of a random variable; it moves the mean by that constant and leaves the standard deviation unchanged. The second is rescaling: multiplying every value of a random variable by the same positive constant; it multiplies both the mean and the standard deviation by that constant.
Why does a shift leave the spread alone? Picture beads on a string. Slide the whole string 7 places to the left. Every bead moves, but the gaps between the beads stay exactly the same. The standard deviation measures those gaps.
Try it. Take the two-dice total and subtract 7, so you're measuring how far a roll lands from 7. The mean moves from 7 to 0. The standard deviation stays about 2.4152.
Now the calendar. Count how many days a month runs past 30. February gives minus 2, the 30-day months give 0, and the 31-day months give 1. Average those with their chances and you get 5 over 12, about 0.42 days. The rule agrees: the old mean, 365 over 12, minus 30, is also 5 over 12. The standard deviation stays at about 0.86 days.
For a rescale, switch from days to hours by multiplying by 24. The month lengths become 672, 720, and 744 hours. The expected value becomes 24 times 365 over 12, which is 730 hours. And the standard deviation becomes 24 times as big, about 20.69 hours. Once again the average, 730 hours, is a length no actual month has.
Pause and try this. If you shift the month lengths by subtracting 30, what happens to the standard deviation of about 0.86 days, and why?
Picture the beads on the string.
Here's the answer. It stays about 0.86 days. Subtracting 30 slides every value by the same amount, so the distances between values, which are what the standard deviation measures, don't change.
6. Density curves: probability becomes area
Now go back to the penguin. Its body mass can be any number in a range, so there's no list of values to put in a table. Week 2 gives us a way in. Remember the histogram of the 342 body masses? Make the bins narrower and narrower, and the tops of the bars blur into a smooth curve.
That curve has a name. A density curve is a smooth curve that models a continuous random variable. It never dips below the horizontal axis, the total area under it is 1, and the area above a range of values is the probability of landing in that range.
Two facts follow from "probability is area". The whole area is 1, because the variable has to land somewhere. And any single exact value has probability 0, because a single point has no width, and so no area.
The simplest density curve is flat. Picture a spinner that can stop anywhere on a dial marked from 0 to 6, every spot equally likely. Its curve is a flat line at a height of 1 out of 6. The whole region is a rectangle 6 wide and 1 out of 6 tall, so its area is 1. The chance the pointer stops between 2 and 3.5 is a smaller rectangle, 1.5 wide, so its area is 0.25. About one spin in 4 lands there. And the chance it stops at exactly 3 is 0.
The penguin curve keeps the mild right skew you saw in Week 2, with a longer tail toward the heavy birds. About half of its area lies between the first quartile, 3,550 grams, and the third quartile, 4,750 grams. About half lies below the median, 4,050 grams. And the chance that a penguin weighs exactly 4,000 grams, to every last decimal, is 0.
One more caution: the height of the curve is not a probability. Only area is.
Pause and try this. A classmate says, "The chance a penguin weighs exactly 4,000 grams is 0, so no penguin weighs 4,000 grams." What's wrong with that?
Think about a range versus a single point.
Here's the answer. The zero belongs to a single point on a smooth curve, which has no width. Masses near 4,000 grams are common, so the useful question asks about a range, and a range has real area and a real chance.
Closing
Let's gather the week. A random variable is a number that chance sets, discrete if you can list its values with gaps and continuous if it can land anywhere in a range.
A probability distribution lists every value with its chance, and it's legitimate when each chance is between 0 and 1 and they all add to 1.
The expected value weights each value by its chance and adds. It's a long-run average, like 3.5 for a die or 7 for two dice, and it doesn't have to be a value you can roll.
The variance and standard deviation measure spread; for the die they're about 2.9167 square units and about 1.71.
A shift moves the mean and leaves the spread. A rescale stretches both.
And for a continuous variable, probability is area under a density curve, with zero chance for any single exact value.
Next in this module come the Readings & Resources page, the lecture tutorial, the practice set, and the quiz. Then next week, in Week 7, Binomial & Normal Models, you'll meet a ready-made distribution for counting successes, and a smooth curve you'll lean on for the rest of the course.
Built with The Course Maker · samples.thecoursemaker.com