Lite / Independent Engineering Research / 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'.
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).
Predict
A fair die is rolled. You win the number shown, doubled, plus 1. What is your expected winnings?
- 7
- 8
- 3.5
- 6
Guess first, then reveal
E[2X + 1] = 2E[X] + 1 = 2 × 3.5 + 1 = 8. Expectation is linear, so you never need to list all six outcomes again.
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.
What the interactive shows (text version)
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.
Watch (optional)
Watch for: 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.
“Binomial distributions | Probabilities of probabilities, part 1” by 3Blue1Brown (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
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
Intuitive
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.
Technical
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).
Mathematical
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.
Applied
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.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
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?
Reflect
Why is it useful that expectation is linear even when the variables are not independent?
Write your answer on paper or in your own notes. Lite never stores what you write.