Expected value E(X) = 65.0 XP
9 Introduction to random variables
What are random variables, and how can we describe their centre and spread using expected value and variance?
A trainer enters a battle with three possible outcomes:
- Win: 100 XP (50% probability)
- Draw: 50 XP (30% probability)
- Loss: 0 XP (20% probability)
How much XP do you expect to gain per battle? How risky or unpredictable is this outcome?
9.1 What is a random variable?
A random variable is a quantity whose value depends on the outcome of a random event. We don’t know what value it will take before the event happens, but we can describe the probabilities of each possible outcome.
In the Pokémon example above, the XP reward is a random variable: it takes different values (100, 50, or 0) depending on whether we win, draw, or lose.
OR example: the probability that the battle gives at least 50 XP is
\[P(X = 100 \text{ or } X = 50) = P(X = 100) + P(X = 50) = 0.5 + 0.3 = 0.8.\]
AND example: Suppose you fight two independent battles. Let \(X_1\) and \(X_2\) be the XP from each. The probability that you get 200 XP is
\[P(X_1 = 100 \text{ and } X_2 = 100) = P(X₁ = 100) \times P(X₂ = 100) = 0.5 \times 0.5 = 0.25.\]
9.2 Expected value: the long-run average
The expected value \(E(X)\) answers the question: “What do I expect, on average, over many repetitions?” It’s calculated as:
\[E(X) = \sum_x x \times P(x)\]
where \(x\) ranges over all possible values and \(P(x)\) is the probability of each value.
Intuitively, if you fought this battle infinitely many times, the average XP per battle would be close to \(E(X)\).
For the Pokémon battle above:
\[E(X) = 100 \times 0.5 + 50 \times 0.3 + 0 \times 0.2 = 50 + 15 + 0 = 65 \text{ XP}\]
On average, you gain 65 XP per battle. This is the long-run average, even though you never gain exactly 65 XP in a single battle.
9.3 Variance: measuring the spread
The variance Var(X) measures the spread of the outcomes around the expected value:
\[\text{Var}(X) = \sum (x - E(X))^2 \cdot P(x)\]
The standard deviation is the square root:
\[SD(X) = \sqrt{\text{Var}(X)}.\]
Intuitively, high variance means outcomes vary widely from the mean. Low variance means outcomes are consistent and predictable. In practice, variance matters: you might prefer a worse outcome if it is predictable. For instance, I prefer walking to the university to riding the metro, even though it’s longer, because I know how long it’ll take.
For the Pokémon battle:
\[\text{Var}(X) = (100 - 65)^2 \times 0.5 + (50 - 65)^2 \times 0.3 + (0 - 65)^2 \times 0.2\] \[= 35^2 \times 0.5 + (-15)^2 \times 0.3 + (-65)^2 \times 0.2\] \[= 1225 \times 0.5 + 225 \times 0.3 + 4225 \times 0.2\] \[= 612.5 + 67.5 + 845 = 1525\]
So \(SD(X) = \sqrt{1525} \approx 39\) XP. This tells us that outcomes typically deviate from the mean by about 39 XP.
Variance Var(X) = 1525.0
Standard Deviation SD(X) = 39.05 XP
Suppose you fight 10 battles in a row. Your average XP might be 50 or 75, depending on your luck. But fight 1,000 battles, and the Law of Large Numbers (LLN) guarantees your average XP converges to E(X) = 65.
The LLN requires two conditions:
- The probabilities stay the same (each battle has the same 50/30/20 outcome distribution)
- The battles are independent (one battle’s result doesn’t affect the next)
As you repeat the process more and more times, the average of all your outcomes converges to the expected value. This is why insurance companies, banks and anyone dealing with random events rely on E(X). With enough repetitions, empirical probabilities approach the theoretical ones.
The expected value \(E(X)\) is a parameter given by the probability distribution. It’s fixed, but usually unknown.
The sample (or empirical) mean \(\bar{x}\) is computed from observed data and varies from sample to sample.
Just because one battle gives 100 XP doesn’t mean \(E(X) = 100\). You need many battles to estimate \(E(X)\). Similarly, \(\text{Var}(X)\) is the theoretical variance, while the sample (or empirical) variance \(s^2\) estimates it from the data.
9.4 Transformations of random variables
Changing the rules of the game changes \(E(X)\) and \(\text{Var}(X)\).
If every XP reward gets a +10 bonus:
\[E(X + c) = E(X) + c\] \[\text{Var}(X + c) = \text{Var}(X)\]
The expected value becomes \(65 + 10 = 75\) XP. The variance stays at 1525 because adding a fixed amount to every outcome doesn’t change the spread.
If all XP rewards are doubled (say, a tournament bonus):
\[E(aX) = a \times E(X)\] \[\text{Var}(aX) = a^2 \times \text{Var}(X)\]
The expected value becomes \(2 \times 65 = 130\) XP and variance becomes \(2^2 \cdot 1525 = 6100\). The variance grows by the square of the multiplier: double the rewards, and the unpredictability quadruples.
Original battle:
E(X) = 65.0 XP, Var(X) = 1525.0
With +10 XP bonus per battle:
E(X + 10) = 75.0 XP, Var(X + 10) = 1525.0
With 2x multiplier (tournament day):
E(2X) = 130.0 XP, Var(2X) = 6100.0
9.5 Putting it all together: insurance example
Suppose an insurance company offers “Pokémon trainer protection” for $20 per month. If you get injured during training, the company pays out $500. Injuries occur in 5% of claims. What’s the company’s expected payout per policy? Is this a profitable product at $20 per month?
Probability model for payout X:
- Pay $500 with probability 0.05 (injury)
- Pay $0 with probability 0.95 (no injury)
Expected payout: \[E(X) = 500 \times 0.05 + 0 \times 0.95 = 25 \text{ dollars}\]
The company receives $20 but expects to pay $25, so it loses $5 per policy on average. This would be unprofitable.
Variance: \[\text{Var}(X) = (500 - 25)^2 \times 0.05 + (0 - 25)^2 \times 0.95 = 475^2 \times 0.05 + 25^2 \times 0.95\] \[= 225,625 \times 0.05 + 625 \times 0.95 = 11,281.25 + 593.75 = 11,875\]
\(SD(X) \approx 109\) dollars. This high variance reflects significant uncertainty in any single payout, which is why insurance companies sell many policies. The Law of Large Numbers keeps their actual payouts close to the expected value.
Now apply transformations: If the company triples the premium to $60 and doubles payouts to $1000:
- New expected payout: \(2 \cdot 25 = 50\) dollars per policy (they now collect $60, profit of $10)
- New variance: \(4 \cdot 11,875 = 47,500\) (spread increases)
Original insurance product:
Premium: $20
E(X) = $25.00 (company loss: $5.00 per policy)
SD(X) = $108.97
After tripling premium and doubling payouts:
Premium: $60
E(X) = $50.00 (company profit: $10.00 per policy)
SD(X) = $217.94
Insurance companies love large numbers because the actual average payout over many policies approaches \(E(X)\) by the Law of Large Numbers. This is why selling 10,000 policies is much less risky than selling one policy.