# Conditional expectation of a continuous random variable given a discrete random variable

For a problem I am working on I need to compute the conditional expectation of a continuous random variable $$T$$ given a discrete random variable $$K$$. I already derived a formula for the joint distribution function $$P(T\leq t, K = k)$$, as well as the pdf of $$T$$ and the probability mass function of $$K$$. Is there some formula to compute $$\mathbb{E}\left[T|K=k \right]$$? (And just out of interest, is there a formula for $$\mathbb{E}\left[K|T=t \right]$$?)

• From $P(T\leq t, K = k)$ one can derive $P(T\leq t|K = k)$, which is the conditional cdf of $T$ given $K$. From there one can either derive the conditional density or directly compute the expectation from the cdf. May 21 at 9:27

The question of how to compute $$E[T|K = k]$$ has been addressed by Xi'an in the comment. More explicitly, assume $$p_k := P(K = k) > 0$$ for each $$k$$, then the conditional density of $$T$$ given $$T = k$$ is $$f(t|K = k) = \frac{f(t, k)}{p_k}$$, where $$f(t, k) = \frac{dF_k(t)}{dt}$$ and $$F_k(t) = P[T \leq t, K = k]$$. It thus follows that \begin{align} E[T|K = k] = \int_\mathbb{R} tf(t|K = k)dt = p_k^{-1}\int_\mathbb{R}tf(t, k)dt. \end{align}
Your second question about determining $$E[K|T = t]$$ is much more technical and a complete answer requires measure-theoretic machinery. Compared with the first question, the difficulty lies in that the conditional distribution of $$K$$ given $$T = t$$ can no longer be evaluated by the elementary event-based conditional probability formula $$P(A | B) = P(A \cap B)/P(B)$$ as $$P[T = t] = 0$$ when $$T$$ is continuous. To begin with, it is OK to expand $$E[K | T = t]$$ as \begin{align} E[K | T = t] = \sum_k kP(K = k|T = t). \tag{1} \end{align}
Coming to determine $$P(K = k|T = t)$$, because of the aforementioned technicality, it should be understood as the a.s. value of the measure-theoretic conditional probability (which is a random variable of $$T$$) $$g(T) := P(K = k|T) = P(K = k|\sigma(T))$$ on the set $$[T = t]$$. Exercise 33.16 in Probability and Measure (3rd edition) by Patrick Billingsley connected this value with the joint distribution function $$P[T \leq t, K = k]$$: \begin{align} & P(K = k | T = t) = \lim_{h \to 0}P[K = k | t - h < T \leq t + h] \\ =& \lim_{h \to 0} \frac{P(T \leq t + h, K = k) - P(T \leq t - h, K = k)}{P(t - h < T \leq t + h)}. \tag{2} \end{align}
With the available information you stated, $$(1)$$ and $$(2)$$ together should be sufficient to determine $$E[K | T = t]$$.