# Law of the unconscious statistician

In probability theory and statistics, the law of the unconscious statistician, or LOTUS, is a theorem which expresses the expected value of a function g(X) of a random variable X in terms of g and the probability distribution of X.
The form of the law depends on the type of random variable X in question. If the distribution of X is discrete and one knows its probability mass function p$_X$, then the expected value of g(X) is $\operatorname {E} [g(X)]=\sum _{x}g(x)p_{X}(x),\,$ where the sum is over all possible values x of X. If instead the distribution of X is continuous with probability density function f$_X$, then the expected value of g(X) is $\operatorname {E} [g(X)]=\int _{-\infty }^{\infty }g(x)f_{X}(x)\,\mathrm {d} x$
Both of these special cases can be expressed in terms of the cumulative probability distribution function F$_X$ of X, with the expected value of g(X) now given by the Lebesgue–Stieltjes integral $\operatorname {E} [g(X)]=\int _{-\infty }^{\infty }g(x)\,\mathrm {d} F_{X}(x).$
In even greater generality, X could be a random element in any measurable space, in which case the law is given in terms of measure theory and the Lebesgue integral. In this setting, there is no need to restrict the context to probability measures, and the law becomes a general theorem of mathematical analysis on Lebesgue integration relative to a pushforward measure.

## Etymology

This proposition is (sometimes) known as the law of the unconscious statistician because of a purported tendency to think of the aforementioned law as the very definition of the expected value of a function g(X) and a random variable X, rather than (more formally) as a consequence of the true definition of expected value. The naming is sometimes attributed to Sheldon Ross' textbook Introduction to Probability Models, although he removed the reference in later editions. Many statistics textbooks do present the result as the definition of expected value.

## Joint distributions

A similar property holds for joint distributions, or equivalently, for random vectors. For discrete random variables X and Y, a function of two variables g, and joint probability mass function $p_{X,Y}(x,y)$: $\operatorname {E} [g(X,Y)]=\sum _{y}\sum _{x}g(x,y)p_{X,Y}(x,y)$ In the absolutely continuous case, with $f_{X,Y}(x,y)$ being the joint probability density function, $\operatorname {E} [g(X,Y)]=\int _{-\infty }^{\infty }\int _{-\infty }^{\infty }g(x,y)f_{X,Y}(x,y)\,\mathrm {d} x\,\mathrm {d} y$

## Special cases

A number of special cases are given here. In the simplest case, where the random variable X takes on countably many values (so that its distribution is discrete), the proof is particularly simple, and holds without modification if X is a discrete random vector or even a discrete random element.
The case of a continuous random variable is more subtle, since the proof in generality requires subtle forms of the change-of-variables formula for integration. However, in the framework of measure theory, the discrete case generalizes straightforwardly to general (not necessarily discrete) random elements, and the case of a continuous random variable is then a special case by making use of the Radon–Nikodym theorem.

### Discrete case

Suppose that X is a random variable which takes on only finitely or countably many different values x$_1$, x$_2$, ..., with probabilities p$_1$, p$_2$, .... Then for any function g of these values, the random variable g(X) has values g(x$_1$), g(x$_2$), ..., although some of these may coincide with each other. For example, this is the case if X can take on both values 1 and −1 and g(x) = x$^2$.
Let y$_1$, y$_2$, ... enumerate the possible distinct values of $g(X)$, and for each i let I$_i$ denote the collection of all j with g(x$_j$) = y$_i$. Then, according to the definition of expected value, there is $\operatorname {E} [g(X)]=\sum _{i}y_{i}p_{g(X)}(y_{i}).$
Since a $y_{i}$ can be the image of multiple, distinct $x_{j}$, it holds that $p_{g(X)}(y_{i})=\sum _{j\in I_{i}}p_{X}(x_{j}).$
Then the expected value can be rewritten as $\sum _{i}y_{i}p_{g(X)}(y_{i})=\sum _{i}y_{i}\sum _{j\in I_{i}}p_{X}(x_{j})=\sum _{i}\sum _{j\in I_{i}}g(x_{j})p_{X}(x_{j})=\sum _{x}g(x)p_{X}(x).$ This equality relates the average of the outputs of g(X) as weighted by the probabilities of the outputs themselves to the average of the outputs of g(X) as weighted by the probabilities of the outputs of X.
If X takes on only finitely many possible values, the above is fully rigorous. However, if X takes on countably many values, the last equality given does not always hold, as seen by the Riemann series theorem. Because of this, it is necessary to assume the absolute convergence of the sums in question.

### Continuous case

Suppose that X is a random variable whose distribution has a continuous density f. If g is a general function, then the probability that g(X) is valued in a set of real numbers K equals the probability that X is valued in g$^{−1}$(K), which is given by $\int _{g^{-1}(K)}f(x)\,\mathrm {d} x.$ Under various conditions on g, the change-of-variables formula for integration can be applied to relate this to an integral over K, and hence to identify the density of g(X) in terms of the density of X. In the simplest case, if g is differentiable with nowhere-vanishing derivative, then the above integral can be written as $\int _{K}f(g^{-1}(y))(g^{-1})'(y)\,\mathrm {d} y,$ thereby identifying g(X) as possessing the density f (g$^{−1}$(y))(g$^{−1}$)′(y). The expected value of g(X) is then identified as $\int _{-\infty }^{\infty }yf(g^{-1}(y))(g^{-1})'(y)\,\mathrm {d} y=\int _{-\infty }^{\infty }g(x)f(x)\,\mathrm {d} x,$ where the equality follows by another use of the change-of-variables formula for integration. This shows that the expected value of g(X) is encoded entirely by the function g and the density f of X.
The assumption that g is differentiable with nonvanishing derivative, which is necessary for applying the usual change-of-variables formula, excludes many typical cases, such as g(x) = x$^2$. The result still holds true in these broader settings, although the proof requires more sophisticated results from mathematical analysis such as Sard's theorem and the coarea formula. In even greater generality, using the Lebesgue theory as below, it can be found that the identity $\operatorname {E} [g(X)]=\int _{-\infty }^{\infty }g(x)f(x)\,\mathrm {d} x$ holds true whenever X has a density f (which does not have to be continuous) and whenever g is a measurable function for which g(X) has finite expected value. (Every continuous function is measurable.) Furthermore, without modification to the proof, this holds even if X is a random vector (with density) and g is a multivariable function; the integral is then taken over the multi-dimensional range of values of X.

### Measure-theoretic formulation

An abstract and general form of the result is available using the framework of measure theory and the Lebesgue integral. Here, the setting is that of a measure space (Ω, μ) and a measurable map X from Ω to a measurable space Ω'. The theorem then says that for any measurable function g on Ω' which is valued in real numbers (or even the extended real number line), there is $\int _{\Omega }g\circ X\,\mathrm {d} \mu =\int _{\Omega '}g\,\mathrm {d} (X_{\sharp }\mu ),$ (interpreted as saying, in particular, that either side of the equality exists if the other side exists). Here X$_♯$ μ denotes the pushforward measure on Ω′. The 'discrete case' given above is the special case arising when X takes on only countably many values and μ is a probability measure. In fact, the discrete case (although without the restriction to probability measures) is the first step in proving the general measure-theoretic formulation, as the general version follows therefrom by an application of the monotone convergence theorem. Without any major changes, the result can also be formulated in the setting of outer measures.
If μ is a σ-finite measure, the theory of the Radon–Nikodym derivative is applicable. In the special case that the measure X$_♯$ μ is absolutely continuous relative to some background σ-finite measure ν on Ω′, there is a real-valued function f$_X$ on Ω' representing the Radon–Nikodym derivative of the two measures, and then $\int _{\Omega '}g\,\mathrm {d} (X_{\sharp }\mu )=\int _{\Omega '}gf_{X}\,\mathrm {d} \nu .$ In the further special case that Ω′ is the real number line, as in the contexts discussed above, it is natural to take ν to be the Lebesgue measure, and this then recovers the 'continuous case' given above whenever μ is a probability measure. (In this special case, the condition of σ-finiteness is vacuous, since Lebesgue measure and every probability measure are trivially σ-finite.)