Why Work Directly With the Function?
For a nonlinear function \(g\), it is often simpler to calculate \(E[g(X)]\) from the distribution of \(X\) than to first derive the distribution of \(g(X)\). This is the practical use of the Law of the Unconscious Statistician (LOTUS): the expectation is calculated by integrating or summing \(g(x)\) against the distribution of \(X\). The details that matter most are the function, the support, and whether the resulting integral or sum is finite.
These checks are especially important for squares, absolute values, exponentials, and reciprocals. A square can magnify the tails of a distribution; an absolute value may require splitting the calculation where its inside changes sign; an exponential can grow quickly; and a reciprocal can become unbounded near zero. A correct setup must account for both the distribution and the behavior of the function on its support.
For a distribution with both a discrete and a continuous part, the expectation includes both contributions: sum \(g(x)\) times the probability at each atom, and integrate \(g(x)\) against the density of the continuous part. In every case, only values in the support contribute. But the function must still be defined with probability one, and the absolute-value expectation must be finite for a finite expectation.
A Practical Check for Existence
The absolute value in the condition \(E[|g(X)|]<\infty\) is essential. It rules out a formal calculation in which positive and negative infinite contributions are treated as if they cancel. When \(E[|g(X)|]<\infty\), both the positive and negative parts have finite expectation, so their difference is well-defined.
Proof. Write \(g=g^+-g^-\), where \(g^+(x)=\max\{g(x),0\}\) and \(g^-(x)=\max\{-g(x),0\}\). Both functions are nonnegative, and \(|g|=g^++g^-\). By the definition of the integral of a nonnegative function, \(E[|g(X)|]=E[g^+(X)]+E[g^-(X)]\). This sum is finite exactly when both terms are finite. In that case the expectation of \(g(X)\) is defined as their difference, and LOTUS applied to the positive and negative parts gives
Conversely, a finite expectation requires both positive and negative parts to have finite expectation; their sum, \(E[|g(X)|]\), is therefore finite. This proves the criterion. \(\square\)
Worked Calculations
For a density, the calculation is an integral over the support, not automatically over the whole real line. If the integrand changes form, split at the point where it does. For a mass function, sum over the possible values. In either case, check the absolute-value condition rather than assuming that a written integral is finite.
Worked Example: Squaring a Uniform Random Variable
Let \(X\sim\operatorname{Uniform}(-1,2)\), with density \(f(x)=1/3\) for \(-1\leq x\leq2\) and zero otherwise. Find \(E[X^2]\).
Use LOTUS with \(g(x)=x^2\), integrating over the support:
Existence is immediate here: \(|X^2|\leq4\) on the support, so \(E[|X^2|]\leq4<\infty\). The calculation uses the distribution of \(X\) directly; it does not require finding the distribution of \(X^2\).
Worked Example: An Absolute Deviation Under an Exponential Distribution
Let \(X\) have the exponential density \(f(x)=e^{-x}\) for \(x\geq0\), and \(f(x)=0\) otherwise. Calculate \(E[|X-1|]\).
The expression inside the absolute value changes sign at \(x=1\), so split the integral there:
For the first integral, \(\frac{d}{dx}(xe^{-x})=(1-x)e^{-x}\), giving
For the second, set \(y=x-1\), so \(x=y+1\), \(dx=dy\), and \(e^{-x}=e^{-1}e^{-y}\). Thus
The last integral equals \(1\), by integration by parts: \(\int_0^b ye^{-y}\,dy=1-(b+1)e^{-b}\), and \((b+1)e^{-b}\to0\) as \(b\to\infty\). Therefore \(E[|X-1|]=2/e\). This is finite; indeed, \(|X-1|\leq X+1\), and \(E[X]=1\) for this exponential density, so \(E[|X-1|]\leq2\).
Worked Example: The Exponential of a Normal Random Variable
Let \(X\sim N(\mu,\sigma^2)\), where \(\mu\) is real and \(\sigma>0\). Find \(E[e^X]\).
Apply LOTUS using the normal density. Completing the square in the exponent gives
Consequently,
The remaining integrand is a normal density with mean \(\mu+\sigma^2\) and variance \(\sigma^2\), so its integral is \(1\). This also establishes existence: the absolute-value integrand is \(e^x\), and its integral is the finite value just obtained.
Worked Example: A Reciprocal That Exists and One That Does Not
First let \(X\sim\operatorname{Uniform}(1,2)\). Since \(1/x\) is defined and bounded on this support, the reciprocal expectation is finite. Direct LOTUS gives
Now instead let \(X\sim\operatorname{Uniform}(0,1)\). Here \(P(X=0)=0\), so \(1/X\) is defined with probability one, but
To see the divergence directly, for \(0<a<1\), \(\int_a^1 dx/x=-\ln a\), which increases without bound as \(a\) decreases to zero. Thus \(E[1/X]\) is not finite. Having no probability mass at zero does not suffice: values arbitrarily close to zero can still make the reciprocal expectation diverge.
Common Mistakes and a Reliable Workflow
The examples suggest a short routine for nonlinear expectations. It keeps the calculation focused on the original distribution and makes support or existence errors easier to catch.
Identify \(g(x)\), then record the support and density or mass function of \(X\). Check that \(g(X)\) is defined with probability one.
Use \(\sum_i g(x_i)p_i\) for a discrete variable or \(\int g(x)f(x)\,dx\) for a density. Include both parts when the distribution has atoms and a continuous component.
Examine the sum or integral of \(|g(x)|\) against the distribution. For piecewise functions, split at each point where the formula changes.
Use finite sums, antiderivatives, or justified improper integrals. Check the sign and, where possible, compare the answer with a simple bound.
- Using the wrong support: integrating a density outside its support can add nonexistent probability. Set the limits from the distribution, not from the function’s domain alone.
- Ignoring a sign change: \(|x-a|\) is not one formula over the whole real line. Split at \(x=a\) wherever the distribution assigns probability on both sides.
- Treating an improper integral as automatically finite: a reciprocal near zero or a rapidly growing exponential may produce an infinite integral. Evaluate the behavior at the boundary or in the tails.
- Letting positive and negative infinities cancel: an expectation with both parts infinite is not defined by subtracting them. Check \(E[|g(X)|]\) before reporting a finite expectation.
Check Your Understanding
For each question, set up the direct LOTUS calculation and consider whether the expectation is finite.
- If \(X\sim\operatorname{Uniform}(0,3)\), what integral gives \(E[X^2]\), and what is its value?
- For \(X\sim\operatorname{Uniform}(-2,2)\), at what point must the integral for \(E[|X|]\) be split?
- If \(X\) has density \(f(x)=2x\) on \(0<x<1\), does \(E[1/X]\) exist as a finite expectation? Explain using the absolute-value integral.
- Why is \(E[e^X]\) under a normal distribution a direct LOTUS calculation, rather than an expectation that requires first finding the distribution of \(e^X\)?
- What condition prevents positive and negative infinite contributions from being treated as a finite expectation?