Random Variables & Expected Value
Probability & Statistics Fundamentals
Chapter 5 · Random Variables & Expected Value
Every chapter so far has asked about the probability of a specific event. This chapter asks a slightly different question: given a whole range of numeric outcomes, each with its own probability, what's a single number that fairly summarizes the whole situation? That number is the expected value, and it's the mathematical foundation of essentially every risk, cost, and budgeting calculation built on top of uncertainty.
Random Variables & Probability Distributions
A random variable (conventionally written as a capital letter, like X) assigns a number to every outcome in a sample space. Its probability distribution (or probability mass function, for a discrete variable) lists every possible value it can take, together with the probability of each.
X = the value shown. Every value 1 through 6 has probability 1/6 — a genuinely uniform distribution.
Expected Value
The expected value E[X] is the probability-weighted average of every possible outcome:
E[X] = Σ x · P(X = x) — sum over every possible value x
For the die: E[X] = (1+2+3+4+5+6)/6 = 21/6 = 3.5.
Worked Example: Expected Weekly Incident Cost
A service's weekly incident cost, X, has this distribution:
| Outcome (cost) | Probability | Scenario |
|---|---|---|
| $0 | 0.70 | No incident |
| $500 | 0.20 | Minor incident |
| $5,000 | 0.08 | Major incident |
| $50,000 | 0.02 | Catastrophic incident |
(Probabilities sum to exactly 1.0, as any valid distribution must — Chapter 2's own certainty axiom.)
| Term | Calculation |
|---|---|
| 0 × 0.70 | 0 |
| 500 × 0.20 | 100 |
| 5,000 × 0.08 | 400 |
| 50,000 × 0.02 | 1,000 |
E[X] = 0 + 100 + 400 + 1,000 = $1,500 — the expected weekly incident cost, useful directly for budgeting a reserve fund or setting an insurance premium, exactly the reasoning behind Technical Support's own backup1/incident1 material approached from a numeric angle.
Variance & Standard Deviation of a Random Variable
Expected value alone hides something important: how spread out the possible outcomes actually are. Variance measures that spread directly, for a known distribution — a genuinely different calculation from Chapter 9's own variance, which is computed from real, already-collected sample data rather than a theoretical distribution.
Var(X) = E[X²] − (E[X])², and SD(X) = √Var(X)
For the incident-cost example: E[X²] = 0²(0.70) + 500²(0.20) + 5,000²(0.08) + 50,000²(0.02) = 0 + 50,000 + 2,000,000 + 50,000,000 = 52,050,000.
| Quantity | Value |
|---|---|
| Var(X) | 52,050,000 − 1,500² = 49,800,000 |
| SD(X) | √49,800,000 ≈ $7,057 |
Random Variables & Expected Value in Code
Hands-On Exercises
A company's monthly new-signups count, X, has the distribution: P(X=100) = 0.5, P(X=200) = 0.3, P(X=500) = 0.2. Confirm the probabilities sum to 1, then compute E[X].
A feature-flag rollout has three possible cost outcomes: no issues (probability 0.85, cost $0), a minor rollback (probability 0.12, cost $2,000), a major outage (probability 0.03, cost $80,000). Compute E[X], Var(X), and SD(X). Given how large the standard deviation is relative to the mean, what does this chapter's own finding suggest about relying on the expected value alone to decide whether the rollout is "safe enough"?
Using this chapter's own incident-cost example (E[X] = $1,500 per week), explain in your own words why "the expected cost over the next 1,000 weeks is $1,500,000" is a reasonable statement to make, even though no single week is ever likely to cost exactly $1,500. Ground your answer in this chapter's own "long-run average, not a single prediction" distinction.
Chapter 5 Quick Reference
- Random variable: assigns a number to every outcome; its distribution lists every value with its probability, summing to exactly 1
- Expected value:
E[X] = Σ x · P(X=x)— a probability-weighted average, and a long-run average, not a prediction of any single outcome - Variance of a random variable:
Var(X) = E[X²] − (E[X])²; standard deviation is its square root — distinct from Chapter 9's own sample-based variance, computed from real collected data rather than a known distribution - A large standard deviation relative to the mean signals a risky, skewed distribution — expected value alone can badly understate real risk
- Next chapter: The binomial distribution