# Expectation of the random variable for which we know only conditional distribution

## Problem statement.

Let random variable $$X$$ has the symmetric triangular distribution on the interval $$[-2,2]$$, in other words, it has density $$f_X(x)=\frac{2-|x|}{4}\mathbf{1}_{-2 \leq x \leq 2}(x).$$

Random variable $$Y$$ has conditional distribution $$Y|X$$ which is defined as follows :

$$Y|X \sim \operatorname{Unif}([0, |X|]), \quad X < 1,$$

$$Y|X \sim \mathcal{N}(3, X), \quad X \geq 1.$$

I need to find $$\mathbb{E}[Y].$$

## My solution.

Let's rewrite conditional density as follows :

$$f_{Y|X}(x|y)=\mathbf{1}_{\{x < 1\}}\mathbf{1}_{\{0 \leq y \leq |x|\}}\frac{1}{|x|} + \mathbf{1}_{\{x \geq 1\}}\frac{1}{\sqrt{2\pi x}}e^{-\frac{1}{2x}(y-3)^2}$$

Using the formula $$\mathbb{E}[Y|X=x] = \int\limits_{\mathbb{R}}yf_{Y|X}(x|y)dy$$, I get $$\mathbb{E}[Y|X=x]=\mathbf{1}_{\{x < 1\}}\frac{|x|}{2} + 3\cdot\mathbf{1}_{\{x \geq 1\}}$$

After it, using the total expectation theorem,

$$\mathbb{E}[Y]=\mathbb{E}[\mathbb{E}[Y|X]]=\mathbb{E}\left[\mathbf{1}_{\{X < 1\}}\frac{|X|}{2}\right] + 3\cdot\mathbb{E}[\mathbf{1}_{\{X \geq 1\}}] = \mathbb{E}[g(X)] + 3\cdot\mathbb{P}[X \geq 1],$$ where $$g(X) = \mathbf{1}_{\{X < 1\}}\frac{|X|}{2}$$.

$$\mathbb{P}[X \geq 1] = \int\limits_\mathbb{R}\frac{2-|x|}{4}\mathbf{1}_{-2 \leq x \leq 2}(x)dx = \int\limits_{1}^{2}\frac{2-x}{4}dx= \frac{1}{8}$$

And using the expected value rule,

$$\mathbb{E}[g(X)] = \int\limits_{\mathbb{R}}g(x)f_X(x)dx=\int\limits_{-2}^{1}\frac{|x|}{2}\frac{2-|x|}{4}dx = \frac{1}{4}$$

Then,

$$\mathbb{E}[Y] = \frac{1}{4} + 3\cdot\frac{1}{8} = \frac{5}{8}$$

## Question.

Could somebody check whether my solution is right? Particularly I don't know is my reasoning about $$\mathbb{E}\left[\mathbf{1}_{\{X < 1\}}\frac{|X|}{2}\right]$$ correct or not. Also if there are any other mistakes I will be grateful if you can point them out.

Yes; that is correct.   You have used linearity of expectation and the known expectations of the conditional distributions of $$Y$$ (uniform and normal) in the relevant partitions.
\qquad\begin{align}\mathsf E(Y) &= \mathsf E(Y\,\mathbf 1_{ X\lt 1})+\mathsf E(Y\,\mathbf 1_{ 1\leqslant X}) \\ &=\int_{-2}^{1} \mathsf E(Y\mid X=x)\,f_X(x)\,\mathrm d x + \int_{1}^{2} \mathsf E(Y\mid X=x)\,f_X(x)\,\mathrm d x\\ &=\int_{-2}^1 \dfrac{\lvert x\rvert}{2}\cdot\dfrac{2-\lvert x\rvert}{4}\,\mathrm d x+ \int_1^2 3\cdot \dfrac{2-\lvert x\rvert}{4}\,\mathrm d x\\ &= \dfrac 14 + \dfrac 38\\&=\dfrac 58\\\blacksquare\quad\end{align}