How to calculate median, variance and correlation on two-dimensional random variable. Two random variables, X and Y, have the joint density function:
$$f(x, y) = \begin{cases} 2 & 0 < x \le y < 1 \\ 0 & ioc\end{cases}$$
Calculate the correlation coefficient between X and Y.
I am pretty much stuck because y is an upper limit for x, and x is a bottom limit for y; so calculating medians and such is proving too hard for me. I'd appreciate it if anyone could lend me a hand and teach me how to solve this.
If it helps save some time, the marginal equations are $f_x (x) = 2 - 2x$ and $f_y (y) = 2y$.
 A: Let $X$ and $Y$ random variables with joint density function given by
$$f(x,y)=\begin{cases} 2, \quad \text{if}\quad 0<x\leqslant y<1,\\ 0, \quad \text{if}\quad \text{otherwise}\end{cases}.$$
The coefficient correlation of $X$ and $Y$ is given by,
$$\boxed{\rho_{XY}=\frac{{\rm Cov}(X,Y)}{\sigma_{X}\sigma_{Y}}=\frac{\sigma_{XY}}{\sigma_{X}\sigma_{Y}}}$$
where ${\rm Cov}(X,Y)=\mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y]$ is the covariance of $X$ and $Y$ and $\sigma_{X}$ and $\sigma_{Y}$ standard deviations.
Now,

*

*$\displaystyle f_{X}(x)=\int_{x}^{1}f(x,y)\, {\rm d}y=2(1-x).$

*$\displaystyle f_{Y}(y)=\int_{0}^{y}f(x,y)\, {\rm d}x=2y.$

*$\displaystyle \mathbb{E}[X]=\int_{-\infty}^{+\infty}xf_{X}(x)\, {\rm d}x=\int_{0}^{1}x(2-2x)\, {\rm d}x=\frac{1}{3}$.

*$\displaystyle \mathbb{E}[X^{2}]=\int_{-\infty}^{+\infty}x^{2}f_{X}(x)\, {\rm d}x=\int_{0}^{1}x^{2}(2-2x)\, {\rm d}x=\frac{1}{6}$.

*$\displaystyle \mathbb{E}[Y]=\int_{-\infty}^{+\infty}yf_{Y}(y)\, {\rm d}y=\int_{0}^{1}y(2y)\, {\rm d}y=\frac{2}{3}$.

*$\displaystyle \mathbb{E}[Y^{2}]=\int_{-\infty}^{+\infty}y^{2}f_{Y}(y)\, {\rm d}y=\int_{0}^{1}y^{2}(2y)\, {\rm d}y=\frac{1}{2}$.

*$\displaystyle \mathbb{E}[XY]=\int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty}xyf(x,y)\, {\rm d}x{\rm d}y=\int_{0}^{1}\int_{0}^{y}xy(2)\, {\rm d}x{\rm d}y=\int_{0}^{1}y^{3}\, {\rm d}y=\frac{1}{4}$.

*$\displaystyle {\rm Cov}(X,Y)=\mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y]=\frac{1}{4}-\frac{1}{3}\times \frac{2}{3}=\frac{1}{36}$.

*$\displaystyle \sigma_{X}=\sqrt{{\rm Var}(X)}=\sqrt{\mathbb{E}[X^{2}]-(\mathbb{E}[X])^{2}}=\sqrt{\frac{1}{6}-\left(\frac{1}{3}\right)^{2}}=\frac{\sqrt{2}}{6}$.

*$\displaystyle \sigma_{Y}=\sqrt{{\rm Var}(Y)}=\sqrt{\mathbb{E}[Y^{2}]-(\mathbb{E}[Y])^{2}}=\sqrt{\frac{1}{2}-\left(\frac{2}{3}\right)^{2}}=\frac{\sqrt{2}}{6}$.

Therefore,
$$\rho_{XY}=\frac{{\rm Cov}(X,Y)}{\sigma_{X}\sigma_{Y}}=\frac{1/36}{(\sqrt{2}/6)^{2}}=\frac{1}{2}>0.$$
Since $\rho_{XY}>0$ then $X$ and $Y$ they are positively, linearly correlated, but not perfectly so.
A: The correlation coefficient between X and Y is defined as follows:
$${\displaystyle \rho _{X,Y}={\frac {\operatorname {\mathbb {E} } [(X-\mu _{X})(Y-\mu _{Y})]}{\sigma _{X}\sigma _{Y}}}}$$
However, $\rho$ can be expressed in terms of uncentered moments:
$${\displaystyle \rho _{X,Y}={\frac {\operatorname {\mathbb {E} } [\,X\,Y\,]-\operatorname {\mathbb {E} } [\,X\,]\operatorname {\mathbb {E} } [\,Y\,]}{{\sqrt {\operatorname {\mathbb {E} } [\,X^{2}\,]-\left(\operatorname {\mathbb {E} } [\,X\,]\right)^{2}}}~{\sqrt {\operatorname {\mathbb {E} } [\,Y^{2}\,]-\left(\operatorname {\mathbb {E} } [\,Y\,]\right)^{2}}}}}.}$$

It seems that you are struggling with the orders of integration. It helps to recall the Law of Total Expectation, which states that
$\mathbb{E}[X] = \mathbb{E}[ \mathbb{E}[X |  Y]]$ and $\mathbb{E}[Y] = \mathbb{E}[ \mathbb{E}[Y |  X]]$

Then, the integrals you need to compute are:
$\mathbb{E}[X] = \mathbb{E}[ \mathbb{E}[X |  Y]] = \int_0^1\int_0^y xf(x,y)\,dx\,dy $
$\mathbb{E}[X^2] = \mathbb{E}[ \mathbb{E}[X^2 |  Y]] = \int_0^1\int_0^y x^2f(x,y)\,dx\,dy $
$\mathbb{E}[Y] = \mathbb{E}[ \mathbb{E}[Y|  X]] =\int_0^1\int_x^1 yf(x,y)\,dy\,dx$
$\mathbb{E}[Y^2] = \mathbb{E}[ \mathbb{E}[Y^2|  X]] =\int_0^1\int_x^1 y^2f(x,y)\,dy\,dx$
$\mathbb{E}[XY] =\int_0^1\int_x^1 xyf(x,y)\,dy\,dx$
