Expectations as integrals with respect to a joint distribution As part of self-study, I'm trying to learn about conditional expectation. Example 5 here presents the problem:
"Let $X_1, X_2$ be independent with $U(0, \theta)$ distribution for some known $\theta$. Let
$Y = \max\{X_1, X_2\}$ and $X = X_1$. We want to find the conditional mean of $X$ given $Y$."
It presents an equation based on "rewrit[ing]...expectations as integrals with respect to the joint distribution of $(X_1, X_2)$:" $\int_0^d\int_0^d\frac{x_1}{\theta^2}\mathrm{d}x_1\mathrm{d}x_2 = \int_0^d\frac{3y}{4}\frac{2y}{\theta^2}\mathrm{d}y$, but I don't really get this. I think the $\frac{1}{\theta^2}$ comes from the joint density of $(X_1, X_2)$ but I don't understand why there is a double integral for calculating expectation on one side and how there is a $2$ on the other side.
Can I have some guidance on how this rewriting was done?
 A: You're right, $f(x_1,x_2)=\frac{1}{\theta^2}I(0<x_1<\theta)I(0<x_2<\theta)$ is the joint density of $(X_1, X_2)$. The left hand side $E(X_1 I(Y<d))$ is computed using $$E(g(X_1,X_2))=\int g(x_1,x_2)f(x_1,x_2) dx_1 dx_2$$ where in this particular case $g(x_1,x_2)=x_1 I(\max(x_1, x_2)<d)$. The right hand side $E([3Y/4]I(Y<d))$ only involves $Y$, so it's easier to handle if we can obtain the density of $Y$. This density can be obtained by differentiating the cdf of $Y$, and you should obtain $f(y)=\frac{2y}{\theta^2}$.
Note: you could also calculate the right hand side as a double integral, explicitly rewriting $Y$ as $\max(X_1,X_2)$. This is perfectly possible, but the stated approach is easier if you are familiar with the density of $Y$.
A: Given the intuitive answer is $E[X|Y] = \frac{3}{4}Y$, the ultimate goal is to show for $0 < d < \theta$,
\begin{align}
\int_{[Y \leq d]} XdP = \int_{[Y \leq d]} \frac{3}{4}YdP. \tag{1}
\end{align}
The linked note evaluates the left hand side of $(1)$ using the joint distribution of $(X_1, X_2)$ while evaluates the right hand side of $(1)$ using the law of the unconscious statistician (i.e., deriving the marginal distribution of $Y$ first, but this step is omitted in the note -- and it is recovered in S. Catterall's answer).  In fact, you don't have to follow this procedure to verify $(1)$, it is still perfectly fine to evaluate the right hand side of $(1)$ using the joint density of $(X_1, X_2)$, and this is equally clear:
\begin{align}
 & \int_{[Y \leq d]} \frac{3}{4}Y dP \\
=& \int_{[\max(X_1, X_2) \leq d]} \frac{3}{4}\max(X_1, X_2)dP \\
=& \int_{[X_1 \leq d] \cap [X_2 \leq d]}\frac{3}{4}\max(X_1, X_2)dP \\
=& \frac{3}{4}\int_0^d\int_0^d\max(x_1, x_2)\frac{1}{\theta^2}dx_1dx_2 \\
=& \frac{3}{4\theta^2}\int_0^d\left[\int_0^{x_2}x_2dx_1 + \int_{x_2}^dx_1dx_1\right]dx_2 \\
=& \frac{3}{4\theta^2}\int_0^d\left[x_2^2 + \frac{1}{2}d^2 - \frac{1}{2}x_2^2\right]dx_2 \\
=& \frac{3}{4\theta^2}\left(\frac{1}{6}d^3 + \frac{1}{2}d^3\right) \\
=& \frac{d^3}{2\theta^2},
\end{align}
which is equal to
\begin{align}
\int_{[Y \leq d]} X dP = \int_0^d\int_0^dx_1\frac{1}{\theta^2}dx_1dx_2 = \frac{d^3}{2\theta^2}.
\end{align}
This completes the verification of $(1)$ hence $E[X|Y] = \frac{3}{4}Y$.
