Why Apply a Function Before Averaging?
A random variable can describe a quantity that is not itself the final quantity of interest. A score may be squared for a scoring rule, or a number of late days may determine a fee through several price tiers. In each situation, the original random variable \(X\) has a known probability distribution, while the quantity we want to average is a function of it, written \(g(X)\).
The important calculation is to apply \(g\) to each possible value of \(X\), then weight that transformed value by the probability of the original value. This often gives the expected quantity directly, without first working out the probability distribution of \(g(X)\). The order matters: in general, averaging the original values first and then applying \(g\) does not produce the expected transformed value.
Here \(g(X)\) is itself a random variable: its value depends on the value taken by \(X\). The expectation formula uses the probabilities of \(X\), not a new list of probabilities for \(g(X)\). If several values of \(X\) lead to the same output under \(g\), each original value still contributes its own weighted term.
How the Direct Formula Works
The formula follows by grouping outcomes according to the value of \(X\). Consider first a finite set of underlying outcomes \(\omega\), each with probability \(P(\omega)\), and suppose \(X\) takes the value \(x\) on some of those outcomes. The expected value of \(g(X)\), calculated across the underlying outcomes, is the sum of \(g(X(\omega))P(\omega)\). Group the terms with the same value \(X(\omega)=x\). Within that group, \(g(X(\omega))=g(x)\) is constant, so it can be factored out:
The last equality uses the definition of \(P(X=x)\): it is the total probability of all outcomes for which \(X=x\). For a countable collection of outcomes, the same grouping is valid when the absolute weighted sum is finite. This establishes why the direct method accounts for every outcome while requiring only the support and probabilities of \(X\).
A useful practical distinction is between transforming values and transforming probabilities. To find \(E[g(X)]\), transform each possible value \(x\) into \(g(x)\), but keep its probability \(P(X=x)\) attached to that original value. Combine probabilities only if you choose to construct a separate distribution for \(g(X)\); that extra step is not needed for the expectation.
Worked Example: Expected Squared Score
Suppose a hypothetical quiz score \(X\), measured in points, has the following probability distribution. Find the expected squared score \(E[X^2]\), and compare it with the square of the expected score.
| Score \(x\) (points) | Probability \(P(X=x)\) | Squared score \(x^2\) (points squared) |
|---|---|---|
| 0 | 0.10 | 0 |
| 1 | 0.20 | 1 |
| 2 | 0.40 | 4 |
| 3 | 0.30 | 9 |
First, the probabilities sum to \(0.10+0.20+0.40+0.30=1.00\), as required. To find the expected squared score, use \(g(x)=x^2\) in the direct formula:
For comparison, the expected score is
Squaring that expected score gives \((E[X])^2=(1.90)^2=3.61\text{ points}^2\), which differs from \(E[X^2]=4.50\text{ points}^2\). The two calculations answer different questions: one squares the average score, while the other averages the squared score for each possible result. In particular, the expected squared score is not found by squaring the expected score.
Functions With Tiers and Repeated Outputs
Some functions are not given by a single arithmetic expression. A tiered fee, for example, assigns one amount to a range of values and another amount to a different range. The same direct formula still applies: identify the output \(g(x)\) for every possible input, multiply it by the input’s probability, and add.
This approach also works when several different input values produce the same fee. There is no need to combine their probabilities first. Keeping the original values visible can make it easier to check that each possible case has been included once.
Worked Example: Expected Fee Under a Tiered Schedule
Suppose a hypothetical service charges a late fee based on \(X\), the number of days a returned item is overdue. The number of overdue days has this distribution:
| Overdue days \(x\) | Probability \(P(X=x)\) | Fee \(g(x)\) |
|---|---|---|
| 0 | 0.50 | $0 |
| 1 | 0.20 | $5 |
| 2 | 0.15 | $5 |
| 3 | 0.10 | $12 |
| 4 | 0.05 | $12 |
The fee schedule is $0 for no overdue days, $5 for one or two days, and $12 for three or four days. The probabilities sum to \(0.50+0.20+0.15+0.10+0.05=1.00\). Apply the fee schedule to each possible \(x\) and weight the fee by \(P(X=x)\):
The expected fee is $3.55 per returned item under this hypothetical distribution. This is a probability-weighted average across possible cases, not a claim that any one item must incur a fee of exactly $3.55. Although the one- and two-day cases both produce a $5 fee, their separate contributions are included using their own probabilities.
One could combine the probabilities for the two cases with a $5 fee, and likewise for the $12 fee, to make a distribution of fees. But for this expected value, doing so is unnecessary: the direct sum already includes every case and gives the same result.
Worked Example: Expected Distance From a Target
Suppose a hypothetical assessment score \(X\), in points, can be 0, 1, 2, 3, or 4, with probabilities 0.10, 0.20, 0.30, 0.25, and 0.15, respectively. A report measures each result by its absolute distance from a target of 2 points, so \(g(x)=|x-2|\). Find the expected distance from the target.
The probabilities total \(0.10+0.20+0.30+0.25+0.15=1.00\). Applying \(g\) to each original score gives distances \(2,1,0,1,2\) points. Use the probabilities attached to those original scores:
The scores 0 and 4 both produce a distance of 2 points, and scores 1 and 3 both produce a distance of 1 point. The calculation nevertheless uses the probability of each original score in its own term. The expected distance is 0.95 points; it is not obtained by first averaging the scores and then finding the distance of that average from 2.
Choosing the Right Calculation
When a problem asks for the expectation of a transformed quantity, translate the words into a function before doing arithmetic. For a squared score, \(g(x)=x^2\). For a fee schedule, \(g(x)\) is the amount charged at input \(x\). For distance from a target \(c\), \(g(x)=|x-c|\). Then use the probability distribution of the original variable \(X\) to calculate the weighted sum.
Record the support \(S\) of \(X\), along with \(P(X=x)\) for each value.
Write down what \(g(x)\) is for every possible input, using the units and rules in the problem.
Multiply each transformed value \(g(x)\) by its original probability \(P(X=x)\), then add the terms.
Verify that the probabilities total 1, that every support value appears, and that the answer has the units of \(g(X)\).
This procedure presumes that the distribution supplied is a valid probability distribution and that the function is defined on every possible value of \(X\). For a finite support, the expectation is a finite sum. For a countably infinite support, check that the weighted sum is finite if a finite expected value is requested. These checks matter especially when \(g(x)\) grows quickly as \(x\) grows.
Common Mistakes and Why They Matter
- Applying the function after averaging. Using \(g(E[X])\) in place of \(E[g(X)]\) changes the calculation. Apply \(g\) to each possible input first, then take the probability-weighted sum.
- Transforming probabilities instead of values. A probability such as \(P(X=x)\) stays attached to the original input \(x\). It is the value \(x\), not its probability, that is changed to \(g(x)\).
- Omitting repeated outputs or counting them incorrectly. If different inputs have the same function value, each input contributes \(g(x)P(X=x)\). Check the original support to ensure no case is dropped.
- Ignoring units. If \(X\) is measured in points and \(g(x)=x^2\), the result is in points squared. If \(g(x)\) is a fee, the expectation is in the currency of that fee.
- Assuming an expected value must be a possible observed output. An expectation is a weighted average; it need not equal any single value that can occur.
A useful final check is to state what the computed number means in context. For example, “the expected squared score is 4.50 points squared” describes an average of squared scores under the specified distribution. It does not describe an individual score, nor is it interchangeable with the square of the expected score.
Check Your Understanding
Try these questions using the direct weighted-sum formula.
- A discrete random variable \(X\) takes the values 1 and 3 with probabilities 0.70 and 0.30. If \(g(x)=x^2\), calculate \(E[g(X)]\).
- In your own words, why can several distinct values of \(X\) contribute to the same transformed value without first combining their probabilities?
- A fee is $2 when \(X=0\), $7 when \(X=1\), and $7 when \(X=2\). The corresponding probabilities are 0.40, 0.35, and 0.25. Write and evaluate the direct sum for the expected fee.
- Explain the difference between \(E[X^2]\) and \((E[X])^2\). Which calculation averages the squared individual values?
- If \(X\) is measured in minutes and \(g(x)=|x-5|\), what are the units of \(E[g(X)]\), and what quantity does it summarize?