School/✦ Research Engineer/Week 10
Random variables, expectation and variance
A rover's camera finds its landmark 7 times in 10. Is that a good camera or a lucky day? First we need a number for 'how much does this wobble'.
About 40 min · 3 goals · Checked by automated tests
1.Why should I care?
Every estimator you meet this term, from an average to a Kalman filter, is a function of random variables. Their expectation tells you where an estimate lands on average; their variance tells you how far it scatters. Get these two numbers right and you can predict how well a robot will know where it is before you build it.
- ◇ Define a random variable and its probability mass function.
- ◇ Compute the expectation E[X] and variance Var(X) of a discrete random variable.
- ◇ Use linearity: E[aX + b] = aE[X] + b and Var(aX + b) = a²Var(X).
2.Discover
In the Code Lab, simulate 10,000 rolls of a fair die. Compute the mean and the variance of your rolls, then of 2·roll + 1. Compare with 3.5, 35/12 ≈ 2.92, 8 and 4 × 35/12 ≈ 11.67.
Can't use the interactive? Read a description instead
The Code Lab activity can be done with a calculator: list the six die faces with probability 1/6 each, compute Σx/6 = 3.5 and Σx²/6 − 3.5² = 35/12, then repeat for 2x + 1 to get 8 and 4 × 35/12.
3.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
What is the variance of 3X + 5, where X is one roll of a fair die (Var(X) = 35/12)?
4.Predict
A fair die is rolled. You win the number shown, doubled, plus 1. What is your expected winnings?
Guess first. Being wrong here is how the surprise works.
5.Understand
A random variable is a number from chance
A random variable X assigns a number to each outcome of an experiment: the number of sightings in 10 tries, the error of one range reading. A discrete X has a probability mass function p(x) = P(X = x), with every p(x) ≥ 0 and Σ p(x) = 1.
Expectation: the balance point
E[X] = Σ x·p(x). It is the long-run average over many repeats, not necessarily a value X can take (a die never shows 3.5). Expectation is linear: E[aX + bY + c] = aE[X] + bE[Y] + c, even if X and Y are dependent.
Variance: the typical squared wobble
Var(X) = E[(X − μ)²] = E[X²] − (E[X])², and the standard deviation σ = √Var(X) has the same units as X. Shifting X does not change its spread, scaling does: Var(aX + b) = a²·Var(X). For independent X and Y, Var(X + Y) = Var(X) + Var(Y): variances add, standard deviations do not.
Explain it another way
Expectation is where a see-saw holding all the outcomes (weighted by probability) would balance. Variance is how far, on average, the weights sit from that pivot, measured in squared distance so left and right do not cancel.
For a discrete random variable, E[g(X)] = Σ g(x)p(x). Variance is the second central moment. Independence lets the cross term 2Cov(X, Y) vanish in Var(X + Y) = Var(X) + Var(Y) + 2Cov(X, Y).
Die: E[X] = (1+…+6)/6 = 3.5; E[X²] = 91/6; Var(X) = 91/6 − 12.25 = 35/12 ≈ 2.917. Sum of two dice: E = 7, Var = 35/6. The mean of n independent copies has variance σ²/n.
A rover's total odometry error over 100 steps is the sum of 100 step errors. If each has variance 0.01 m² and they are independent, the total has variance 1 m², σ = 1 m: errors grow like √n, not n, unless there is a bias.
Worked example 1
X takes values 0, 1, 2, 3 with probabilities 0.1, 0.2, 0.3, 0.4. Find E[X] and Var(X).
E[X] = 0 + 0.2 + 0.6 + 1.2 = 2.0. E[X²] = 0 + 0.2 + 1.2 + 3.6 = 5.0. Var(X) = 5.0 − 2.0² = 1.0, so σ = 1.
Worked example 2
Each of 25 independent wheel steps has error with σ = 2 cm and mean 0. What is the σ of the total error?
Variances add: 25 × 4 = 100 cm², so σ_total = 10 cm. (Not 25 × 2 = 50 cm: independent errors partly cancel.)
Common mix-ups
- The expected value is the most likely value.
✓ It is the long-run average. A die's expectation, 3.5, is impossible on any single roll. - Independent errors add up linearly.
✓ Their variances add, so σ grows like √n. Only biases add linearly.
6.Watch
→ Watch how a single unknown success rate produces a whole distribution of possible counts, and why more data narrows it.
Builds the binomial distribution from a real question about ratings, then asks how sure we can be of an underlying success rate: the bridge from probability to estimation.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2 · a fresh version every time
A drone's number of failed sensor checks per flight, X, takes values 0, 1, 2, 3 with probabilities 0.4, 0.3, 0.2, 0.1. What is E[X]?
Practice 3
Two independent sensors each have error σ = 3 mm. What is the σ of the sum of their errors?
Practice 4
One reading has σ = 6 cm. What is the σ of the mean of 9 independent readings, in cm?
Practice 5
Which statement is true for ANY two random variables X and Y?
8.Apply it
A rover takes 400 steps. Each step's odometry error has mean 0.5 cm (slip bias) and σ = 1 cm. Find the expected total error and its σ. Which term dominates, and what does that tell you about fixing biases first?
9.Reflect
Concepts: Probability distributions