$X$ is uniformly distributed in $[0,1]$, and $Y$ is uniformly distributed in $[0,X]$
(a) Find $\mathbb{E}(Y)$ and $\text{Var}(Y)$
Solution:
By conditioning on $X$, we obtain the first two orders of statistics of $Y$ as $\mathbb{E}(Y)=\mathbb{E}_X[\mathbb{E}_Y(Y|X)]=\mathbb{E}_X[\frac{X}{2}]=\frac14$
$\mathbb{E}(Y^2)=\mathbb{E}_X[\mathbb{E}_Y(Y^2|X)]=\mathbb{E}_X[\frac{X^2}{3}]=\frac19$
$\text{Var}(Y)= \mathbb{E}(Y^2)-\mathbb{E}^2(Y) = \frac19-(\frac14)^2=\frac{7}{144}$
So, I understand why E[Y]=1/4 without doing any integrals and stuff, but I'm a bit confused as to how to get the E[Y^2] value.
From where I understand you have to take the integral from 0 to x of y^2/x. But I don't understand where they got this integral from.
The uniform distribution on $(0,X)$ has density $\frac{1}{X}$ $$\mathbb{E}_Y(Y^2 | X) = \int_0^X y^2 \frac{1}{X} dy = \frac{X^2}{3}$$
And $$\mathbb{E}_X \left[\frac{X^2}{3}\right] = \int_0^1 \frac{x^2}{3} dX = \frac{1}{9}$$