Order of Integration: Continuous Joint Distribution I wanted to ask if the order of integration matters in double integration when we are calculating expectations or joint probability etc.
For example:
fXY (x, y) = 8xy, 0 ≤ x ≤ 1, 0 ≤ y ≤ x and 0 otherwise
I had to compute the E(Y) and to do that I first found the marginal distribution of y which came out as 4y and then I found its expectation which was (4/3)x^3
I also tried finding the expectation directly using the distribution function integrating first w.r.t y and then w.r.t x and the answer came out 8/15
Which answer is correct? And why are both methods giving me different answers? Also, had I integrated w.r.t x first and then y, I'd have gotten the the same answer I did when I found the marginal pdf and then found the expectation.
So, does the order of integration matter?
 A: The map $(x,y)\to 8xy$ is continuous, and the region 
$$
\mathcal D:=\{(x,y)\in\mathbb R^2 : 0\leqslant x\leqslant 1, 0\leqslant y\leqslant x \}
$$
is both closed and bounded, and hence compact. It follows that $f_{X,Y}$ is bounded, and so
$$
\int_{\mathcal D}|f_{X,Y}|\ \mathsf d(x\times y)<\infty.
$$
Hence by Fubini's theorem, the iterated integrals
$$
\int_{\mathbb R}\int_{\mathbb R}f_{X,Y}(x,y)\ \mathsf dx\ \mathsf dy
$$
and 
$$
\int_{\mathbb R}\int_{\mathbb R}f_{X,Y}(x,y)\ \mathsf dy\ \mathsf dx
$$
exist, and are equal. So the order of integration does not matter. To compute the marginal density of $Y$, we integrate $f_{X,Y}$ over all values of $x$:
$$
f_Y(y) = \int_y^1 8xy\ \mathsf dx = 4y(1-y^2).
$$
We compute the expectation of $Y$ by integrating $yf_Y(y)$:
$$
\mathbb E[Y] = \int_0^1 4y^2(1-y^2)\ \mathsf dy = \frac8{15}.
$$
Your error was in the bounds of the integral for computing $f_Y$ - the lower bound should be $y$ since since $x\leqslant y$ in the region $\mathcal D$.
A: You have.$$f_{X,Y} (x, y) = \begin{cases}8xy&,& 0 ≤ x ≤ 1, 0 ≤ y ≤ x \\ 0 && \textsf{otherwise}\end{cases}$$
The order of integration does not matter (see Fubini' and Tonelli's theorems).  What matters is using the correct integration domains.
$$\begin{split}\mathsf E(Y) &= \iint_{0\leqslant y\leqslant x\leqslant 1} y\cdot(8xy)~\mathsf d(x,y)\\&= \int_0^1\int_0^x 8xy^2~\mathsf d y~\mathsf d x \\&= \int_0^1\int_y^1 8xy^2~\mathsf d x~\mathsf d y \\&= \tfrac 8{15}\end{split}$$
