Why Integrate the Function Against the Density?
A random variable \(X\) may have a simple density even when the quantity of interest is a nonlinear function of it. For example, if \(X\) is a waiting time, we might want the expected discount factor \(e^{-X}\); if \(X\) is a measurement error, we might want the expected squared error \(X^2\). In each case, the target is \(E[g(X)]\), not necessarily \(E[X]\).
For a continuous random variable, the Law of the Unconscious Statistician (LOTUS) gives a direct calculation: integrate \(g(x)\) against the density of \(X\). This avoids first finding the distribution of \(g(X)\). The integral must still use the support of \(X\), and it must exist in the relevant sense.
The function \(g\) must be measurable so that \(g(X)\) is a random variable and the integral is defined. The absolute-integrability condition is the standard guarantee of a finite expectation for signed functions. For nonnegative \(g\), no finiteness assumption is needed to write LOTUS, but the answer may be infinite.
The Continuous LOTUS Formula
A density \(f\) satisfies \(P(X\in A)=\int_A f(x)\,dx\) for every Borel set \(A\). LOTUS applies this density representation to a function of \(X\). It does not say to integrate over the values that \(g(X)\) can take using \(f\); \(f\) is the density of \(X\), so the integration variable is \(x\).
Proof. First take \(g\) to be the indicator of a Borel set \(A\). The definition of the density gives $$ E[\mathbf{1}_{\{X\in A\}}]=P(X\in A)=\int_{\mathbb{R}}\mathbf{1}_{\{x\in A\}}f(x)\,dx. $$ By adding these identities with nonnegative coefficients, the formula holds for every nonnegative simple Borel function \(s\). For any nonnegative Borel \(g\), there is an increasing sequence of nonnegative simple Borel functions \(s_k\) with \(s_k(x)\uparrow g(x)\) for each \(x\). The monotone convergence theorem gives $$ E[g(X)]=\lim_{k\to\infty}E[s_k(X)] =\lim_{k\to\infty}\int_{\mathbb{R}}s_k(x)f(x)\,dx =\int_{\mathbb{R}}g(x)f(x)\,dx. $$ For signed \(g\) with finite \(\int |g|f\), apply the nonnegative result to \(g^+=\max(g,0)\) and \(g^-=\max(-g,0)\). Both integrals are finite because \(g^++g^-=|g|\), so subtracting them gives the stated formula for \(g=g^+-g^-\). \(\square\)
Support and Integrability
In applications, a density is often zero outside a particular interval or region. If \(f(x)=0\) almost everywhere outside a Borel set \(S\), the integral can be restricted to \(S\). This is a statement about where the density places probability, not about the range of \(g\). Endpoints do not affect a density integral because individual points have Lebesgue measure zero.
Proof. By LOTUS, \(E[g(X)]=\int_{\mathbb{R}}g(x)f(x)\,dx\) for nonnegative \(g\). Since \(f=0\) almost everywhere on \(\mathbb{R}\setminus S\), the integral over that complement is zero, leaving the integral over \(S\). For signed \(g\), the same argument applied to \(|g|\) shows that \(\int_{\mathbb{R}}|g|f=\int_S|g|f\). Thus finiteness of the latter is exactly the absolute-integrability condition in LOTUS, and restricting the signed integral to \(S\) gives the result. \(\square\)
This criterion is useful before doing algebra: it can show whether a proposed expectation is finite, even if the integral has no convenient closed form. It also prevents a common error: an integral that looks well behaved over a few values of \(x\) may still diverge near a boundary or in a tail.
Worked Calculations
Worked Example: A Squared Uniform Random Variable
Let \(X\sim \operatorname{Uniform}(0,2)\), with density \(f(x)=\tfrac12\) for \(0\le x\le2\) and zero elsewhere. Find \(E[X^2]\).
The function \(g(x)=x^2\) is nonnegative, and the density is supported on \([0,2]\). First check the density is normalized: $$ \int_0^2\frac12\,dx=\frac12(2)=1. $$ Then apply LOTUS: $$ E[X^2]=\int_0^2x^2\frac12\,dx =\frac12\left[\frac{x^3}{3}\right]_0^2 =\frac12\cdot\frac{8}{3} =\frac{4}{3}. $$
The answer is \(4/3\), not \(8/3\): the factor \(1/2\) from the density must be included. The calculation also uses the support of \(X\), \([0,2]\), rather than the range \([0,4]\) of \(X^2\).
Worked Example: An Exponential Discount Factor
Let \(X\) have an exponential distribution with rate \(2\), so \(f(x)=2e^{-2x}\) for \(x\ge0\) and zero for \(x<0\). Find \(E[e^{-X}]\).
The function \(g(x)=e^{-x}\) is nonnegative, and on the support \(x\ge0\) it is at most \(1\). Thus its expectation is finite. LOTUS gives $$ E[e^{-X}] =\int_0^\infty e^{-x}2e^{-2x}\,dx =2\int_0^\infty e^{-3x}\,dx. $$
For \(b>0\), \(\int_0^\infty e^{-bx}\,dx=1/b\), since the antiderivative is \(-e^{-bx}/b\) and \(e^{-bx}\to0\) as \(x\to\infty\). Therefore $$ E[e^{-X}]=2\left(\frac13\right)=\frac23. $$
As a check, \(0<e^{-X}\le1\), so an expectation of \(2/3\) is within the possible range.
Worked Example: A Normal Exponential Function
Let \(X\sim N(0,1)\), with density \(f(x)=\frac{1}{\sqrt{2\pi}}e^{-x^2/2}\). For a fixed real number \(t\), find \(E[e^{tX}]\) and check that it is finite.
The integrand is nonnegative. Completing the square gives $$ -\frac{x^2}{2}+tx =-\frac{(x-t)^2}{2}+\frac{t^2}{2}. $$ Hence $$ E[e^{tX}] =\int_{-\infty}^{\infty}e^{tx}\frac{1}{\sqrt{2\pi}}e^{-x^2/2}\,dx =e^{t^2/2}\int_{-\infty}^{\infty}\frac{1}{\sqrt{2\pi}}e^{-(x-t)^2/2}\,dx. $$
The last integral is \(1\): after the substitution \(u=x-t\), it is the integral of the standard normal density over the real line. Thus $$ E[e^{tX}]=e^{t^2/2}, $$ which is finite for every real \(t\). This calculation illustrates that an unbounded function \(g\) can still have a finite expectation; finiteness depends on its integral against the density.
Worked Example: A Function on a Bounded Support
Let \(X\sim\operatorname{Uniform}(-1,1)\), and take \(g(x)=1/(1+x^2)\). Find \(E[g(X)]\).
The density is \(1/2\) on \([-1,1]\), and \(g\) is bounded there by \(1\), so the expectation is finite. Applying LOTUS, $$ E\left[\frac{1}{1+X^2}\right] =\frac12\int_{-1}^1\frac{1}{1+x^2}\,dx =\frac12\left[\arctan(x)\right]_{-1}^{1} =\frac12\left(\frac{\pi}{4}-\left(-\frac{\pi}{4}\right)\right) =\frac{\pi}{4}. $$
The result is approximately \(0.785\), which is between the minimum \(1/2\) and maximum \(1\) of \(g\) on the support.
Common Mistakes and Why LOTUS Matters
LOTUS matters because many statistical quantities are expectations of functions: squared error, transformed measurements, and nonlinear scores are common examples. The density of \(X\) often makes their expectations accessible even when describing the full distribution of \(g(X)\) would require additional work.
- Integrating over the wrong variable. In \(\int g(x)f(x)\,dx\), \(x\) is a value of \(X\). The integral is not taken over the range of \(g(X)\) using \(f\).
- Forgetting the density factor. The integral is not usually just \(\int g(x)\,dx\). For the uniform example, omitting the factor \(1/2\) would incorrectly double the answer.
- Ignoring the support. A density that is zero outside its support contributes no probability there. Use the support of \(X\) to set the integration limits.
- Assuming every integral is finite. For a signed function, check \(\int |g(x)|f(x)\,dx<\infty\) before claiming a finite expectation. For a nonnegative function, the expectation may be \(+\infty\).
Check Your Understanding
Try each question by identifying the support, writing the LOTUS integral, and checking any needed finiteness condition.
- If \(X\sim\operatorname{Uniform}(0,3)\), write the integral for \(E[\sqrt{X}]\) and evaluate it.
- If \(X\) has density \(3x^2\) on \(0\le x\le1\), is \(E[1/X]\) finite? Justify your answer by writing the relevant integral.
- For an exponential random variable with rate \(1\), write and evaluate the LOTUS integral for \(E[Xe^{-X}]\).
- Explain why the density of \(X\), rather than the range of \(g(X)\), appears in the integral for \(E[g(X)]\).
- State the condition that guarantees a finite expectation when \(g\) can take both positive and negative values.