Expected value as the long-run mean · Statistics & Data… | StemPy Lab
Course 4.1·Lesson 2 of 3
Expected value as the long-run mean
The expected value E(X) of a random variable is its mean in the long run. We find it from a table by weighting each value by its probability, and we watch a simulation of many days settle at it. It need not be a value that X can take.
about 30 min
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
find the expected value of a random variable from its table;
explain the expected value as the mean of a very long run;
use expected values to plan, for example a total over many days.
The mean of the survey
Go back to the made-up class survey. The total number of brothers and sisters of the 40 students is
0×8+1×18+2×10+3×4=50.
So their mean is 4050=1.25.
Now split the fraction into four parts: 0×408+1×4018+2×4010+3×404. Each fraction is a probability from the table. So the mean is each value times its probability, all added up.
The expected value
For any random variable, this weighted sum is called the expected value or the mean of X:
E(X)=∑xP(X=x).
The Greek letter μ (mu) is another name for it. For the survey, E(X)=0×0.2+1×0.45+2×0.25+3×0.1=1.25.
The expected value is not a value you expect to see. No student has 1.25 brothers and sisters. It is the mean in the long run: pick student after student, with replacement, and the mean of their answers settles near 1.25.
A made-up delivery van
A made-up delivery van sends back X parcels a day that it could not deliver. The firm's records give this table.
x
0
1
2
3
P(X=x)
0.5
0.3
0.15
0.05
So E(X)=0+0.3+0.3+0.15=0.75 parcels a day. On most days the van sends back none at all, since 0 is the most likely value. Still, over 200 days the firm should plan for about 200×0.75=150 parcels.
That last step uses a useful fact. The expected value of a total is the total of the expected values. So 30 days have an expected total of 30×0.75=22.5 parcels.
You should find that with 10 days the band is wide, from about 0.19 to about 1.31 parcels. With 10000 days it is only about 0.018 either side of 0.75.
Watch a simulation settle
The program below simulates 10000 days of the van with Python's random module. It prints the mean of the first 10, 100, 1000 and 10000 days, and draws the running mean.
A line graph of the running mean of 10000 simulated days of a made-up delivery van, with the number of days on a logarithmic axis from 1 to 10000. The line jumps about for the first few days, then settles close to a red dashed line at 0.75 parcels a day.
This is the law of large numbers, which you met in the chapter on probability rules. There it was about a share of successes. Here it is about the mean of any random variable.
Using an expected value to decide
A made-up phone shop sells a repair plan for a year. Its records say that in a year a phone needs no repair with probability 0.85. It needs a small repair costing 2000 rupees with probability 0.1, and a big repair costing 8000 rupees with probability 0.05. The expected repair cost per phone is
0×0.85+2000×0.1+8000×0.05=600rupees.
If the plan costs 900 rupees, the shop gains about 300 rupees a plan on average over many plans. A single customer may still gain a lot. The expected value describes the long run, not one phone. The fair games of the chapter on probability rules use the same idea.
Your turn
The usual mistakes
Taking the plain average of the values. The values are weighted by their probabilities. The plain average of 0, 1, 2 and 3 is 1.5, not 0.75.
Thinking the expected value is the most likely value. The van's most likely value is 0, but its expected value is 0.75.
Rounding the expected value to a whole number.0.75 parcels a day is right. It is a long-run mean.
Expecting a short run to match. Ten days can give a mean far from E(X).
Remember these
E(X)=∑xP(X=x), the mean in the long run.
It need not be a value that X can take.
The expected value of a total is the total of the expected values.
A simulation of many trials settles near E(X).
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
X takes the values 1, 2 and 3 with probabilities 0.2, 0.5 and 0.3. Find E(X).
The answer to question 1 is not a whole number, but X is a count. Is that a mistake?
With the X of question 1, what total do you expect over 50 independent days?
A table has P(X=0)=0.4, P(X=1)=0.1 and P(X=4)=0.5. Which value is the most likely, and what is E(X)?
A simulation of the van gives a mean of 1.1 parcels a day after 8 days. Is the program wrong?
References
OpenStax, Introductory Statistics, Chapter 4, section on the mean or expected value and the standard deviation.
Enroll free in Random Variables and Expected Value
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.