Evaluate the Function on the Original Scale
A function of a random variable can be piecewise-defined, turn around, or assign the same output to several different inputs. None of those features requires finding the distribution of the transformed variable first. The direct approach is to evaluate the function at each possible input and average those values using the original distribution of \(X\).
This is the practical use of the Law of the Unconscious Statistician (LOTUS). In this tutorial, the emphasis is on how to apply it when the function has branches or is many-to-one. The key is to split the calculation where the function changes form, while keeping the probabilities or density attached to the original values of \(X\).
The measurability condition ensures that \(g(X)\) is a random variable. The integrability condition ensures that its positive and negative contributions do not both diverge, leaving an undefined cancellation. If \(g(X)\) is nonnegative, its expectation can also be defined as an extended value, possibly \(+\infty\); the examples below have finite expectations.
Splitting a Piecewise Function
Suppose the real line is divided into measurable pieces \(B_1,B_2,\ldots\), and \(g\) has a possibly different formula \(g_j\) on each piece \(B_j\). Each branch is evaluated at the original input \(x\), and its contribution is integrated or summed only over the part of the original law lying in that piece.
Proof. Since the sets \(B_j\) partition the real line, for every \(x\), \(g(x)=\sum_{j\geq1}g_j(x)\mathbf{1}_{B_j}(x)\), with only one nonzero term. The absolute integrability assumption gives $$ \sum_{j\geq1}E\!\left[|g_j(X)|\mathbf{1}_{\{X\in B_j\}}\right] =E[|g(X)|]<\infty. $$ Thus the series of branch contributions is absolutely integrable. Countable additivity of the integral, applied to these disjoint pieces, gives the asserted sum of expectations. For a density, writing the expectation as an integral against \(f(x)\,dx\) gives the stated branch integrals; for a discrete law, writing it as a sum over support points gives the stated branch sums. \(\square\)
For a density, a breakpoint is simply an integration boundary. The values at the breakpoints themselves do not affect the integral when those points have probability zero. For a discrete law, however, a breakpoint may be a support point with positive probability, so its branch assignment must be respected.
Worked Example: A Piecewise Function Under a Uniform Law
Let \(X\sim\operatorname{Uniform}(0,3)\), so its density is \(f(x)=1/3\) for \(0\leq x\leq3\). Define \(g(x)=x\) for \(0\leq x<1\), \(g(x)=2\) for \(1\leq x<2\), and \(g(x)=4-x\) for \(2\leq x\leq3\). Calculate \(E[g(X)]\) directly.
Each branch uses the density of \(X\) on its original interval:
The last branch integral is \( (12-9/2)-(8-2)=3/2\). The function rises on the first interval, is constant on the second, and falls on the third; the expectation calculation does not require treating those as separate distributions of \(g(X)\).
Absolute-Value and Many-to-One Functions
The absolute-value function is a basic many-to-one function: \(x\) and \(-x\) have the same absolute value. Under LOTUS, the values at both inputs contribute according to the probabilities those inputs receive under the law of \(X\). For a continuous law, one can split the original integral at zero, where the formula for \(|x|\) changes.
Derivation. Pointwise, \(|x|=-x\) when \(x<0\), and \(|x|=x\) when \(x\geq0\). The two sets form a measurable partition, and \(E[|X|]<\infty\) gives the integrability needed to split the expectation. Applying LOTUS to each set yields the formula. The point \(x=0\) contributes zero, whether included with the nonnegative or negative part. \(\square\)
Worked Example: Absolute Value of a Discrete Random Variable
Suppose \(X\) has support \(\{-2,-1,1,2\}\), with probabilities \(0.10, 0.20, 0.30, 0.40\), respectively. Take \(g(x)=|x|\). Directly from the law of \(X\),
The inputs \(-1\) and \(1\) both produce output \(1\), while \(-2\) and \(2\) both produce output \(2\). Their probability contributions are all retained in the direct sum. No inverse-function calculation is needed.
The same principle applies to any many-to-one function, not just absolute value. If different input values lead to one output, the expectation still weights each input by its probability under the original law. For a continuous law, the integral over the entire input axis accounts for every branch automatically.
Worked Example: A Nonmonotone Function Under a Continuous Law
Let \(X\) be uniform on \([-1,2]\), with density \(1/3\) on that interval, and set \(g(x)=|x|\). This function maps inputs on opposite sides of zero to the same nonnegative output. Split at zero and calculate from the density of \(X\):
The input interval has total length \(3\), and the density \(1/3\) accounts for that normalization. The negative-side contribution is \(1/6\), and the positive-side contribution is \(2/3\); together they give \(5/6\).
Using LOTUS for a Mixed Law
A mixed distribution can place positive probability at specific points while also assigning probability across a continuous range. A piecewise or many-to-one function acts on both parts of the law. The atoms are evaluated individually; the continuous part is integrated using its density. Neither component should be dropped.
Worked Example: A Many-to-One Function Under a Mixed Law
Let \(X\) have probability \(1/4\) at \(0\), probability \(1/4\) at \(2\), and probability \(1/2\) distributed uniformly on \([0,2]\). The continuous component therefore has density \(1/4\) on \([0,2]\), since its total mass is \((1/4)(2)=1/2\). Let \(g(x)=(x-1)^2\). Calculate its expectation from the components of the original law.
At the two atoms, \(g(0)=1\) and \(g(2)=1\), so their combined contribution is \(1/4+1/4=1/2\). For the continuous component,
Therefore \(E[g(X)]=1/2+1/6=2/3\). The function is many-to-one on the continuous component as well: inputs on opposite sides of \(1\) can have the same squared distance from \(1\). Integrating over the original interval already accounts for both sides.
Why This Direct Method Matters
A direct LOTUS calculation keeps the original probability model visible. It is often shorter than deriving a distribution for \(g(X)\), especially when \(g\) has several branches or the law of \(X\) is mixed. The method also reduces opportunities for errors involving branch weights, inverse values, or transformed supports.
A frequent mistake is to treat the transformed output as though each different input contributes only once. For example, seeing that both \(x\) and \(-x\) map to \(|x|\), a calculation might integrate over only the positive inputs and omit the negative-side probability. That is not what LOTUS says: it averages \(g(x)\) over the whole original law. The correction is to sum over all support points in a discrete problem or integrate over the full input support in a continuous problem, splitting into regions only to use the right formula for \(g\).
- Discrete law: evaluate \(g(x)\) at each support point and multiply by its mass.
- Continuous law: integrate \(g(x)f(x)\) over the original support, splitting at changes of formula when helpful.
- Mixed law: add the atom contributions and the continuous integral.
- Many-to-one map: keep every input’s contribution; identical outputs do not erase probability mass.
Before calculating, check that \(g\) is measurable and that the expectation exists under the assumptions of the problem. Then identify the original support and any breakpoints, apply the appropriate branch formula, and check that the probability masses or density have been used on the correct regions.
Check Your Understanding
For each question, use the law of the original random variable rather than deriving the distribution of its transformation.
- If \(X\sim\operatorname{Uniform}(-2,1)\), write the LOTUS integral for \(E[|X|]\) split at zero. What is its value?
- A discrete variable has \(P(X=-1)=0.4\) and \(P(X=1)=0.6\). Calculate \(E[X^2]\) directly from its mass function.
- Why must a continuous LOTUS calculation for a piecewise function use the density of \(X\) on each branch’s input interval?
- A function maps two distinct support points of a discrete \(X\) to the same output. Should one of their probability contributions be discarded? Explain.
- What condition on \(g(X)\) ensures that \(E[g(X)]\) is a finite, well-defined expectation?