Tutorials › Statistical Theory I - Probability and Distribution Theory › Conditioning on a Function of a Variable

Conditional Expectation · Tutorial 335 of 994

Conditioning on a Function of a Variable

Compute conditional expectations given a function of a random variable by averaging over its preimages with the correct probability weights.

Intermediate 10 min read

What You'll Learn

  • Express conditioning on a transformation \(g(X)\) through the values of \(X\) that map to the same output.
  • Compute conditional means for discrete variables by weighting each value according to its probability.
  • Derive conditional means for smooth, many-to-one transformations using inverse branches and density weights.
  • Distinguish conditioning on a transformed value from an unweighted average over its preimages.
  • Recognize when conditional-mean formulas are defined only almost everywhere.

What Does the Transformation Reveal?

Suppose we observe \(T=g(X)\), rather than \(X\) itself. Knowing \(T\) tells us which values of \(X\) are possible, but it may not distinguish between them. For example, if \(T=|X|\), then observing \(T=2\) tells us that \(X\) is either \(2\) or \(-2\), if both values are possible. The conditional mean of \(X\) given \(T=2\) is therefore an average over those possibilities.

The average is generally weighted: values of \(X\) that are more probable contribute more. The weights come from the distribution of \(X\), not just from counting how many preimages a transformation has. This principle applies to discrete variables, continuous variables, and coarsened categories.

Definition: Let \(X\) be a random variable, let \(g\) be a measurable function, and set \(T=g(X)\). For an integrable random variable \(h(X)\), \(E[h(X)\mid T]\) denotes the conditional expectation of \(h(X)\) given the information in \(T\), that is, given the sigma-field generated by \(T\). It is a random variable that can be written as a measurable function of \(T\), up to almost-sure equality. A value such as \(E[h(X)\mid T=t]\) refers to a version of that function evaluated at \(t\); for continuous \(T\), this value is specified only for almost every \(t\) under the distribution of \(T\).

The Discrete Averaging Formula

First suppose \(X\) takes values in a finite or countable set \(\{x_i\}\), with \(P(X=x_i)=p_i\). For an output \(t\) of the transformation, the values compatible with \(T=t\) are exactly those \(x_i\) for which \(g(x_i)=t\). Conditional expectation averages \(h(x_i)\) over that set, using the conditional probabilities of those values.

Theorem: Suppose \(E[|h(X)|]<\infty\), and let \(T=g(X)\). For any \(t\) such that \(P(T=t)>0\), $$ E[h(X)\mid T=t] = \frac{\displaystyle\sum_{i:g(x_i)=t}h(x_i)p_i} {\displaystyle\sum_{i:g(x_i)=t}p_i}. $$ Consequently, \(E[h(X)\mid T]\) is the function of \(T\) given by this ratio on outputs with positive probability. Its values on outputs with probability zero do not affect the conditional expectation.

To verify the formula, fix an output \(t\) with positive probability. The event \(\{T=t\}\) consists of the disjoint events \(\{X=x_i\}\) for which \(g(x_i)=t\), so $$ P(T=t)=\sum_{i:g(x_i)=t}p_i. $$ For each such \(i\), \(P(X=x_i\mid T=t)=p_i/P(T=t)\). Multiplying \(h(x_i)\) by this conditional probability and summing gives the stated ratio. The sums involving \(h\) are well-defined because \(E[|h(X)|]<\infty\). This also shows that the resulting function of \(T\) has the defining conditional-average property on each event \(\{T=t\}\). \(\square\)

Worked Example: Conditioning on Absolute Value in a Discrete Model

Let \(X\) take values \(-2,-1,1,2\) with probabilities \(0.1,0.2,0.3,0.4\), respectively, and let \(T=|X|\). Find \(E[X\mid T]\).

If \(T=1\), the compatible values are \(-1\) and \(1\), and their total probability is \(0.2+0.3=0.5\). Thus $$ E[X\mid T=1] =\frac{(-1)(0.2)+(1)(0.3)}{0.5} =\frac{0.1}{0.5} =0.2. $$

If \(T=2\), the compatible values are \(-2\) and \(2\), again with total probability \(0.1+0.4=0.5\). Therefore $$ E[X\mid T=2] =\frac{(-2)(0.1)+(2)(0.4)}{0.5} =\frac{0.6}{0.5} =1.2. $$

Since \(T\) takes only the values \(1\) and \(2\), the answer can be written as \(E[X\mid T]=0.2\) when \(T=1\), and \(E[X\mid T]=1.2\) when \(T=2\). The positive answers reflect the greater probability assigned to the positive values in each pair.

Worked Example: Conditioning on an Indicator

Let \(X\) take values \(-2,0,1,3\) with probabilities \(0.2,0.1,0.4,0.3\). Define \(T=\mathbf{1}_{\{X>0\}}\), which records whether \(X\) is positive. Find \(E[X\mid T]\).

When \(T=1\), \(X\) is either \(1\) or \(3\), and \(P(T=1)=0.4+0.3=0.7\). Hence $$ E[X\mid T=1] =\frac{1(0.4)+3(0.3)}{0.7} =\frac{1.3}{0.7} =\frac{13}{7}. $$

When \(T=0\), \(X\) is either \(-2\) or \(0\), and \(P(T=0)=0.2+0.1=0.3\). Thus $$ E[X\mid T=0] =\frac{(-2)(0.2)+0(0.1)}{0.3} =\frac{-0.4}{0.3} =-\frac{4}{3}. $$

The indicator retains only the information “positive” or “not positive.” Within each group, the conditional mean is the probability-weighted average of the original values.

Worked Example: Replacing Values by Category Labels

Suppose \(X\) takes values \(0,1,2,3\) with probabilities \(0.1,0.2,0.3,0.4\). Let \(C\) be the category “low” when \(X\leq 1\) and “high” when \(X\geq 2\). Find \(E[X\mid C]\) in each category.

The low category has probability \(0.1+0.2=0.3\). Its conditional mean is $$ E[X\mid C=\text{low}] =\frac{0(0.1)+1(0.2)}{0.3} =\frac{2}{3}. $$ The high category has probability \(0.3+0.4=0.7\), so $$ E[X\mid C=\text{high}] =\frac{2(0.3)+3(0.4)}{0.7} =\frac{1.8}{0.7} =\frac{18}{7}. $$

A category label is simply another transformation: it groups original values into sets. The conditional mean averages within each set using the probabilities of its members.

Continuous Variables: Weighting the Inverse Branches

For a continuous \(X\), individual values usually have probability zero, so the discrete formula cannot be applied by assigning probabilities to points. Instead, density determines the relative weight of each possible preimage. When \(g\) is many-to-one, a given output \(t\) may have several inverse branches \(x_j(t)\). A branch receives weight proportional to the density of \(X\) there and to the change-of-variables factor \(1/|g'(x_j(t))|\).

Theorem: Suppose \(X\) has density \(f_X\), \(E[|h(X)|]<\infty\), and the support of \(X\), apart from a set of probability zero, can be divided into finitely many intervals on each of which \(g\) is continuously differentiable and strictly monotone, with \(g'(x)\ne 0\). For almost every \(t\), let \(x_1(t),\ldots,x_k(t)\) be the inverse-branch values in the support for which \(g(x_j(t))=t\), and define $$ w_j(t)=\frac{f_X(x_j(t))}{|g'(x_j(t))|}. $$ At outputs where \(\sum_{j=1}^k w_j(t)>0\), a version of the conditional mean is $$ E[h(X)\mid T=t] = \frac{\displaystyle\sum_{j=1}^k h(x_j(t))w_j(t)} {\displaystyle\sum_{j=1}^k w_j(t)}, \qquad T=g(X). $$ This expression is defined for almost every \(t\) with respect to the distribution of \(T\).

To justify the formula, apply change of variables separately on each monotone interval. For any bounded measurable function \(a\), $$ E[h(X)a(T)] =\int h(x)a(g(x))f_X(x)\,dx =\int a(t)\sum_{j=1}^k h(x_j(t))w_j(t)\,dt. $$ The same change of variables with \(h(x)=1\) shows that \(T\) has density \(f_T(t)=\sum_{j=1}^k w_j(t)\) almost everywhere. Define \(m(t)\) by the displayed ratio wherever \(f_T(t)>0\), and choose its value arbitrarily where \(f_T(t)=0\). Then $$ E[m(T)a(T)] =\int a(t)m(t)f_T(t)\,dt =\int a(t)\sum_{j=1}^k h(x_j(t))w_j(t)\,dt =E[h(X)a(T)]. $$ These identities hold for all bounded measurable \(a\), and \(E[|h(X)|]<\infty\) ensures the relevant integrals exist. Thus \(m(T)\) has the defining conditional-expectation property given \(T\), which proves the formula. \(\square\)

Worked Example: Conditioning on the Absolute Value of a Continuous Variable

Let \(X\) have density \(f_X(x)=2(x+1)/9\) for \(-1<x<2\), and zero elsewhere. This is a density because $$ \int_{-1}^{2}\frac{2(x+1)}{9}\,dx =\frac{[(x+1)^2]_{-1}^{2}}{9} =\frac{9}{9} =1. $$ Set \(T=|X|\) and find \(E[X\mid T=t]\).

For \(0<t<1\), both inverse branches, \(x=t\) and \(x=-t\), lie in the support. Since the absolute-value transformation has derivative with absolute value \(1\) on each branch, their weights are $$ w_+(t)=f_X(t)=\frac{2(t+1)}{9}, \qquad w_-(t)=f_X(-t)=\frac{2(1-t)}{9}. $$ Therefore $$ E[X\mid T=t] =\frac{t\,w_+(t)+(-t)\,w_-(t)}{w_+(t)+w_-(t)} =t\frac{(t+1)-(1-t)}{(t+1)+(1-t)} =t^2. $$

For \(1<t<2\), the negative branch \(-t\) is outside the support, so only \(x=t\) is possible. Consequently \(E[X\mid T=t]=t\). The cases \(t=1\) and the endpoints do not affect the result, since they have probability zero under the continuous distribution of \(T\). The complete answer, almost everywhere, is \(t^2\) for \(0<t<1\) and \(t\) for \(1<t<2\).

Common Pitfall: Averaging Preimages Without Weights

A tempting shortcut is to average the possible values of \(X\) equally whenever they map to the same \(T\). That is correct only when those possibilities have equal conditional probabilities. In the discrete absolute-value example, the two values mapping to \(T=1\) are \(-1\) and \(1\), but their probabilities are \(0.2\) and \(0.3\). Their unweighted average is \(0\), whereas the correct conditional mean is \(0.2\).

The same issue appears for continuous transformations. The weights depend not only on \(f_X\) at the inverse points but also on the derivative factor \(1/|g'|\). A second mistake is to assume that conditioning on \(|X|\) always gives a mean of zero. That conclusion holds in symmetric settings where the positive and negative possibilities balance; it does not follow from the transformation alone. In the continuous example above, the conditional mean is positive because the density favors positive values.

Key takeaway: To condition on \(T=g(X)\), identify all original values compatible with the observed output, then average using their conditional probabilities. In discrete problems the weights are point probabilities; in smooth continuous problems they are density and change-of-variables weights. The resulting conditional mean is a function of \(T\), determined up to almost-sure equality.

Check Your Understanding

Work through these questions by identifying the values or inverse branches compatible with each observed transformed value.

  1. If \(X\) takes values \(0,1,2\) with probabilities \(0.2,0.5,0.3\) and \(T=\mathbf{1}_{\{X=2\}}\), what is \(E[X\mid T=0]\)?
  2. For a discrete \(X\), why must the conditional mean given \(g(X)=t\) use the probabilities of the values in that preimage?
  3. If \(X\) has a symmetric distribution about zero, under what conditions would symmetry imply \(E[X\mid |X|]=0\)?
  4. For a smooth transformation with two inverse branches, what two factors determine each branch’s weight in the continuous formula?
  5. Why is a conditional mean at a single output value not uniquely determined when that output has probability zero?