Expectation of a Function Without Finding Its Distribution
A function of a discrete random variable is itself a random variable: if \(X\) records a count, then \(X^2\), \(2^X\), or a cost \(g(X)\) all vary from outcome to outcome. One approach is to find the probability mass function of \(g(X)\) and then calculate its expectation. The law of the unconscious statistician (LOTUS) gives a more direct route: weight \(g(x)\) by the probability that \(X=x\), and sum over the possible values of \(X\).
The word “unconscious” is a reminder that the formula does not require us to work out the distribution of the transformed variable first. It does not mean that existence conditions can be ignored. For an infinite support, the series must be handled with appropriate care.
For finite support, the sum is always finite and the formula needs no additional integrability condition. For countably infinite support, the absolute-summability condition ensures that positive and negative contributions cannot produce an invalid cancellation. In particular, if \(g\) takes both signs and the absolute sum is infinite, the expectation may be undefined; one must not treat a conditionally rearranged series as its value.
Why the Formula Works
Write \(Y=g(X)\). For any value \(y\) attained by \(Y\), its probability is the total probability of the \(X\)-values that map to it: $$ P(Y=y)=\sum_{\{x\in S:g(x)=y\}}p_X(x). $$ The discrete expectation of \(Y\) sums \(yP(Y=y)\) over its possible values. When \(E|Y|<\infty\), these terms can be regrouped by the corresponding \(x\)-values, giving the discrete LOTUS formula. The following justification makes the conditions for that regrouping explicit.
Proof. First suppose \(g\geq 0\). The possible values \(y\) of \(Y=g(X)\) are countable, and for each such \(y\), $$ P(Y=y)=\sum_{\{x\in S:g(x)=y\}}p_X(x). $$ By the definition of expectation for a nonnegative discrete random variable and the rule for summing nonnegative terms, we may write $$ E[Y]=\sum_y yP(Y=y) =\sum_y\sum_{\{x\in S:g(x)=y\}}g(x)p_X(x) =\sum_{x\in S}g(x)p_X(x). $$ All terms are nonnegative, so this equality is valid even if the sum is infinite.
Now suppose \(g\) can take either sign and \(\sum_{x\in S}|g(x)|p_X(x)<\infty\). Apply the nonnegative result to \(g^+(x)=\max(g(x),0)\) and \(g^-(x)=\max(-g(x),0)\). Both expectations are finite because $$ \sum_{x\in S}g^+(x)p_X(x)\leq\sum_{x\in S}|g(x)|p_X(x)<\infty, \qquad \sum_{x\in S}g^-(x)p_X(x)\leq\sum_{x\in S}|g(x)|p_X(x)<\infty. $$ Thus \(E[g(X)]=E[g^+(X)]-E[g^-(X)]\) is well-defined. Subtracting the two nonnegative LOTUS formulas gives $$ E[g(X)] =\sum_{x\in S}\bigl(g^+(x)-g^-(x)\bigr)p_X(x) =\sum_{x\in S}g(x)p_X(x). $$ Absolute summability justifies this signed sum. \(\square\)
Using LOTUS in Calculations
The practical procedure is short: identify the support and mass function, substitute \(g(x)\) into the weighted sum, and check convergence if the support is infinite. Keeping the argument \(x\) visible helps prevent a common error: LOTUS uses \(g(x)\), not \(g(E[X])\).
Worked Example: A Nonlinear Function on Finite Support
Suppose \(X\) has the following distribution. Find \(E[(X-1)^2]\), and compare it with \((E[X]-1)^2\).
| \(x\) | \(-1\) | \(0\) | \(2\) | \(4\) |
|---|---|---|---|---|
| \(p_X(x)\) | \(0.2\) | \(0.1\) | \(0.4\) | \(0.3\) |
The probabilities sum to \(0.2+0.1+0.4+0.3=1\), so this is a valid probability mass function. Apply LOTUS with \(g(x)=(x-1)^2\): $$ E[(X-1)^2] =0.2(-1-1)^2+0.1(0-1)^2+0.4(2-1)^2+0.3(4-1)^2. $$ The four contributions are \(0.2(4)=0.8\), \(0.1(1)=0.1\), \(0.4(1)=0.4\), and \(0.3(9)=2.7\). Therefore $$ E[(X-1)^2]=0.8+0.1+0.4+2.7=4. $$ For comparison, \(E[X]=(-1)(0.2)+0(0.1)+2(0.4)+4(0.3)=-0.2+0+0.8+1.2=1.8\), so \((E[X]-1)^2=(1.8-1)^2=0.64\). The two answers differ: the expectation of a nonlinear function is not generally that function evaluated at the expectation.
Worked Example: Squaring a Poisson Random Variable
Let \(X\sim\operatorname{Poisson}(2)\), so \(P(X=k)=e^{-2}2^k/k!\) for \(k=0,1,2,\ldots\). Find \(E[X^2]\) directly from the mass function.
LOTUS gives $$ E[X^2]=\sum_{k=0}^{\infty}k^2e^{-2}\frac{2^k}{k!}. $$ The \(k=0\) term is zero. For \(k\geq1\), use \(k^2=k(k-1)+k\); the \(k=1\) contribution from \(k(k-1)\) is also zero. Hence $$ E[X^2] =e^{-2}\sum_{k=2}^{\infty}k(k-1)\frac{2^k}{k!} +e^{-2}\sum_{k=1}^{\infty}k\frac{2^k}{k!}. $$ In the first sum, \(k(k-1)/k!=1/(k-2)!\). With \(j=k-2\), it becomes $$ e^{-2}\sum_{j=0}^{\infty}\frac{2^{j+2}}{j!} =4e^{-2}\sum_{j=0}^{\infty}\frac{2^j}{j!} =4. $$ In the second sum, \(k/k!=1/(k-1)!\). With \(j=k-1\), it becomes $$ e^{-2}\sum_{j=0}^{\infty}\frac{2^{j+1}}{j!} =2e^{-2}\sum_{j=0}^{\infty}\frac{2^j}{j!} =2. $$ Here \(\sum_{j=0}^{\infty}2^j/j!=e^2\). Combining the two finite contributions gives \(E[X^2]=4+2=6\). The series converge, as is also confirmed by these finite evaluations.
Worked Example: An Exponential Function of a Geometric Variable
Let \(X\) have the geometric distribution on \(0,1,2,\ldots\) with \(P(X=k)=(1-q)q^k\), where \(0<q<1\). For \(q=1/3\), calculate \(E[2^X]\) and check that it is finite.
Using LOTUS, $$ E[2^X]=\sum_{k=0}^{\infty}2^k(1-q)q^k =(1-q)\sum_{k=0}^{\infty}(2q)^k. $$ For \(q=1/3\), \(1-q=2/3\) and \(2q=2/3\). Since this geometric series has ratio \(2/3<1\), $$ E[2^X]=\frac{2}{3}\sum_{k=0}^{\infty}\left(\frac{2}{3}\right)^k =\frac{2}{3}\cdot\frac{1}{1-2/3}=2. $$ More generally, the same calculation is finite when \(2q<1\), in which case it equals \((1-q)/(1-2q)\). If \(q=1/2\), the summands are all \(1/2\), so the series diverges and \(E[2^X]=\infty\). If \(q>1/2\), its terms do not even tend to zero, so the expectation is again infinite. This illustrates why convergence must be checked for an infinite support.
Common Mistakes and Why LOTUS Matters
LOTUS is useful whenever the quantity of interest is a transformation of a variable—such as a squared measurement, a nonlinear loss, or an exponential penalty—and the original mass function is already known. It can be simpler to sum over \(X\)'s support than to construct the distribution of \(g(X)\). The function may map different \(x\)-values to the same output; the direct sum still accounts for every possible input value with its own probability.
- Substituting the mean into the function. In general, \(E[g(X)]\neq g(E[X])\). The finite-support example gives \(4\) versus \(0.64\). Compute the weighted values \(g(x)p_X(x)\) instead.
- Forgetting the probability weights. The formula is not an unweighted sum of \(g(x)\). Each value is multiplied by \(p_X(x)\).
- Assuming every infinite sum converges. Check nonnegative sums for divergence, and for signed \(g\) check \(\sum_x|g(x)|p_X(x)<\infty\) before using an ordinary finite expectation.
- Computing a transformed mass function unnecessarily. LOTUS requires the support and probabilities of \(X\), not a separate table for \(g(X)\).
A reliable final check is to inspect the terms. Are they \(g(x)p_X(x)\)? Do the probabilities cover the full support? If the support is infinite, does the series have a valid finite or nonnegative extended value? These checks address both the arithmetic and the meaning of the result.
Check Your Understanding
For each question, pay attention to the support, the function being averaged, and whether the relevant series is finite.
- If \(X\) has finite support, what expression does LOTUS give for \(E[g(X)]\)?
- For the finite distribution in the first worked example, why is \(E[(X-1)^2]\) not equal to \((E[X]-1)^2\)?
- For \(P(X=k)=(1-q)q^k\) on \(k=0,1,\ldots\), for which values of \(q\) is \(E[2^X]\) finite?
- What condition on \(\sum_x |g(x)|p_X(x)\) guarantees that a signed \(g(X)\) has a finite expectation under LOTUS?
- Why does the discrete LOTUS formula not require finding the probability mass function of \(g(X)\) first?