Tutorials › Stochastic Processes › Expectation from Densities and the LOTUS Formula

Random Variables, Expectation and Conditional Expectation · Tutorial 8 of 994

Expectation from Densities and the LOTUS Formula

Use the density of a continuous random variable to calculate expectations directly, without finding the distribution of the transformed variable.

Intermediate 10 min read

What You'll Learn

  • State the LOTUS formula and the conditions under which it gives a finite or infinite expectation.
  • Compute expectations by integrating a function against a probability density.
  • Handle indicator functions and functions that are unbounded near an endpoint.
  • Check when a signed expectation is undefined because both positive and negative parts diverge.
  • Identify why omitting the density or using a symmetric improper integral can give a wrong answer.

Expectation by Integrating Against a Density

When a random variable \(X\) has a density, the expectation of a function \(g(X)\) can often be calculated directly from that density. There is no need first to derive the probability distribution of the new random variable \(g(X)\). This direct calculation is called the Law of the Unconscious Statistician, or LOTUS. Its practical simplicity depends on a precise condition: the integral must be interpreted correctly, and for a finite signed expectation it must be absolutely integrable.

Work on a probability space \((\Omega,\mathcal{F},\mathbb{P})\). A real-valued random variable \(X\) has density \(f\) with respect to Lebesgue measure if \(f(x)\ge 0\), \(\int_{\mathbb{R}} f(x)\,dx=1\), and, for every Borel set \(A\subseteq\mathbb{R}\), \(\mathbb{P}(X\in A)=\int_A f(x)\,dx\). A function \(g:\mathbb{R}\to\mathbb{R}\) is measurable if its inverse images of Borel sets are measurable; this ensures \(g(X)\) is a random variable and the integrals below are defined.

Theorem (LOTUS for a density): If \(X\) has density \(f\) and \(g\) is measurable and nonnegative, then \(\mathbb{E}[g(X)]=\int_{\mathbb{R}} g(x)f(x)\,dx\), with either side allowed to be \(+\infty\). If \(g\) can have either sign, the same formula gives a finite expectation exactly when \(\int_{\mathbb{R}} |g(x)|f(x)\,dx<\infty\). If both \(\int g^+(x)f(x)\,dx\) and \(\int g^-(x)f(x)\,dx\) are infinite, where \(g^+=\max(g,0)\) and \(g^-=\max(-g,0)\), the expectation is undefined.

The integral is over the real line, but only the support of \(X\), where \(f\) is nonzero, contributes. If \(g\) is nonnegative, an infinite integral means the expectation is \(+\infty\). If \(g\) is signed, absolute integrability is the condition that makes the positive and negative contributions finite and their difference well-defined. In applications, the integral may be evaluated as an ordinary improper integral when the usual integrability conditions justify doing so.

Proof. For a Borel set \(A\), the definition of a density gives \(\mathbb{E}[\mathbf{1}_{\{X\in A\}}]=\mathbb{P}(X\in A)=\int_A f(x)\,dx\). Thus, if \(s=\sum_{k=1}^m a_k\mathbf{1}_{A_k}\) is a nonnegative simple function with disjoint measurable sets \(A_k\) and coefficients \(a_k\ge0\), linearity for a finite sum gives \(\mathbb{E}[s(X)]=\sum_{k=1}^m a_k\mathbb{P}(X\in A_k)=\int_{\mathbb{R}}s(x)f(x)\,dx\). For any nonnegative measurable \(g\), choose nonnegative simple functions \(s_n\) increasing pointwise to \(g\). The monotone convergence theorem states that the integral of an increasing sequence of nonnegative measurable functions converges to the integral of its pointwise limit. Applying it on the probability space to \(s_n(X)\), and on the real line with measure \(f(x)\,dx\) to \(s_n(x)\), gives \(\mathbb{E}[g(X)]=\lim_n\mathbb{E}[s_n(X)]=\lim_n\int s_n(x)f(x)\,dx=\int g(x)f(x)\,dx\), including the possibility \(+\infty\). The monotone convergence theorem is a standard result of Lebesgue integration; its measure-theoretic proof is beyond this tutorial. For signed \(g\), apply the nonnegative result separately to \(g^+\) and \(g^-\). The expectation is the difference of these two expectations when at least one is finite; it is finite exactly when both are finite, equivalently when \(\int |g|f<\infty\). If both are infinite, their difference is not defined. \(\square\)

Using the Formula

The calculation has three basic steps: identify a valid density, substitute the function of interest into the integrand, and evaluate over the support. The integrand is \(g(x)f(x)\), not just \(g(x)\). A useful special case is an indicator: taking \(g(x)=\mathbf{1}_{A}(x)\) gives \(\mathbb{P}(X\in A)=\int_A f(x)\,dx\). Thus event probabilities can be obtained by integrating the density over the event’s values.

Worked Example: A Function of a Uniform Random Variable

Let \(X\) have density \(f(x)=\tfrac13\) for \(0\le x\le3\), and \(f(x)=0\) otherwise. Find \(\mathbb{E}[(X-1)^2]\) directly from the density.

First check the density: \(\int_0^3\tfrac13\,dx=\tfrac13(3-0)=1\). LOTUS gives

$$ \begin{aligned} \mathbb{E}[(X-1)^2] &=\int_0^3 (x-1)^2\,\frac13\,dx\\ &=\frac13\left[\frac{x^3}{3}-x^2+x\right]_0^3\\ &=\frac13\left((9-9+3)-(0-0+0)\right)=1. \end{aligned} $$

Check by expanding the integrand. Direct integration gives \(\mathbb{E}[X]=\tfrac13[\tfrac{x^2}{2}]_0^3=\tfrac32\) and \(\mathbb{E}[X^2]=\tfrac13[\tfrac{x^3}{3}]_0^3=3\). Since \((X-1)^2=X^2-2X+1\), the same integral is \(3-2(\tfrac32)+1=1\), agreeing with the direct calculation.

Nothing in LOTUS requires \(g\) to be one-to-one or continuous. It can be piecewise-defined or an indicator, provided it is measurable and the expectation is interpreted under the stated integrability conditions. In particular, discontinuities at individual points do not cause difficulty for a density: a single point has probability zero, so changing \(g\) at that point does not change the expectation.

Worked Example: An Exponential Function Under an Exponential Density

Let \(X\) have density \(f(x)=2e^{-2x}\) for \(x\ge0\), and zero otherwise. Find \(\mathbb{E}[e^{-X}]\).

The density is normalized because \(\int_0^\infty 2e^{-2x}\,dx=[-e^{-2x}]_0^\infty=0-(-1)=1\). The function \(e^{-x}\) is nonnegative, so LOTUS applies without a separate signed-integrability condition:

$$ \begin{aligned} \mathbb{E}[e^{-X}] &=\int_0^\infty e^{-x}2e^{-2x}\,dx\\ &=2\int_0^\infty e^{-3x}\,dx\\ &=2\left[-\frac13e^{-3x}\right]_0^\infty =2\left(0+\frac13\right)=\frac23. \end{aligned} $$

Check. The antiderivative of \(2e^{-3x}\) is \(-\tfrac23e^{-3x}\). Its value at infinity is \(0\), and its value at \(0\) is \(-\tfrac23\), so the integral is \(0-(-\tfrac23)=\tfrac23\), as computed above.

Unbounded Functions and Integrability

The function \(g\) need not be bounded for LOTUS to apply. The integral itself determines whether its expectation is finite. For a nonnegative \(g\), one can first integrate away from a problematic endpoint and then take a limit. If that limit is finite, the expectation is finite; if it diverges, the expectation is infinite. For a signed function, it is not enough for positive and negative areas to appear to cancel in a symmetric calculation. The positive and negative parts must be considered separately.

Worked Example: An Unbounded Function with Finite Expectation

Let \(X\) have density \(f(x)=2x\) for \(0<x<1\), and zero otherwise. Find \(\mathbb{E}[X^{-1/2}]\), defining \(g(0)\) arbitrarily since \(\mathbb{P}(X=0)=0\).

Check the density: \(\int_0^1 2x\,dx=[x^2]_0^1=1\). The function grows without bound as \(x\) decreases to zero, but it is nonnegative. LOTUS gives the improper integral

$$ \begin{aligned} \mathbb{E}[X^{-1/2}] &=\int_0^1 x^{-1/2}2x\,dx\\ &=\lim_{\varepsilon\downarrow0}\int_\varepsilon^1 2x^{1/2}\,dx\\ &=\lim_{\varepsilon\downarrow0}\frac43(1-\varepsilon^{3/2}) =\frac43. \end{aligned} $$

Check. For every \(0<\varepsilon<1\), the truncated expectation is \(\tfrac43(1-\varepsilon^{3/2})\). As \(\varepsilon\) decreases to zero, \(\varepsilon^{3/2}\) tends to zero, so the truncated values converge to \(\tfrac43\). The singularity therefore does not make the expectation infinite.

A Common Mistake: Dropping the Density

For the uniform density in the first example, a wrong calculation is \(\mathbb{E}[(X-1)^2]=\int_0^3(x-1)^2\,dx=3\). This omits the factor \(f(x)=\tfrac13\), so it is not an integral with respect to the probability law of \(X\). The correction is to use the full integrand \((x-1)^2f(x)\): the integral is \(\tfrac13(3)=1\). More generally, a density is a weight in the expectation formula; it cannot be discarded just because the integration limits match the support.

A second warning is that a symmetric improper integral is not a definition of expectation. For example, let \(X\) have the Cauchy density \(f(x)=\tfrac{1}{\pi(1+x^2)}\) on \(\mathbb{R}\). For every \(R>0\), symmetry gives \(\int_{-R}^R x f(x)\,dx=0\). But the positive part has integral \(\int_0^\infty \tfrac{x}{\pi(1+x^2)}\,dx=\lim_{R\to\infty}\tfrac{1}{2\pi}\log(1+R^2)=\infty\), and the negative part has the same infinite integral by symmetry. Thus \(\mathbb{E}[X]\) is undefined: the symmetric value \(0\) results from cancelling two divergent contributions and is not an expectation.

LOTUS matters because many quantities of interest are functions of observed measurements: costs, indicators, losses, or nonlinear scores. Integrating the function against the original density can avoid a separate derivation of the law of \(g(X)\), especially when that transformed law has several branches or atoms. The formula does not remove the need to check measurability and integrability, but it gives a direct route once those conditions are understood.

Check Your Understanding

For each question, identify the relevant density and state whether the expectation is finite before evaluating it.

  1. If \(X\) is uniform on \([0,2]\), write a LOTUS integral for \(\mathbb{E}[|X-1|]\) and evaluate it.
  2. If \(X\) has density \(f(x)=3x^2\) on \(0<x<1\), what integral gives \(\mathbb{E}[\mathbf{1}_{\{X>1/2\}}]\)? Evaluate it.
  3. For the density \(f(x)=2x\) on \(0<x<1\), does \(\mathbb{E}[X^{-1}]\) exist as a finite number? Check the integral near zero.
  4. State the condition on \(\int |g(x)|f(x)\,dx\) that guarantees a finite expectation when \(g\) can be signed.
  5. Why does a symmetric improper integral of \(x\) against the Cauchy density not establish that \(\mathbb{E}[X]=0\)?