# Computing the correlation between two random variables

Suppose $X$ and $Y$ are random variables uniformly distributed between $[0,1]$.

Further, $$Y=\begin{cases} X,& \text{ if } \quad X<\alpha\\ 1+\alpha - X,& \textbf{ if } \quad X \geq \alpha \end{cases}$$ Compute the correlation of $X$ and $Y$?

• How would you try to compute the correlation? Please tell us what you have tried. – Hans Hüttel May 28 '17 at 2:31
• In order to compute $\rho = \dfrac{E[XY] - E[X]E[Y]}{\sqrt{E[X^2] - E[X]^2}\sqrt{E[Y^2] - E[Y]^2}}$. I can see that $E[X] = 1/2$, and can compute $E[X^2] = 1/3$, but I am unable to compute $E[XY]$. – esperanto May 28 '17 at 2:33

To compute $\mathsf{E}[XY]$, we have for $0 < \alpha < 1$, \begin{align} \mathsf{E}[XY] &= \mathsf{E}[XY \mid X < \alpha] \cdot \Pr(X < \alpha) + \mathsf{E}[XY \mid X \geq \alpha] \cdot \Pr(X \geq \alpha) \\ &= \mathsf{E}[X^2 \mid X < \alpha] \cdot \Pr(X < \alpha) + \mathsf{E}[(1 + \alpha - X)X \mid X \geq \alpha] \cdot \Pr(X \geq \alpha) \\ &= \left(\int_0^{\alpha}\frac{x^2}{\alpha} dx\right) \cdot \alpha + \left(\int_\alpha^1 \frac{(1+\alpha - x)x}{(1-\alpha)}dx\right)\cdot(1-\alpha) \\ &= \int_0^\alpha x^2 dx + \int_\alpha^1 (1 + \alpha-x)xdx \end{align} It is left as an exercise for you to compute the result.