I would expect the answer to the problem below to be at least $\frac{1}{2}$. However, it is not. Therefore, I am thinking I did something wrong. Did I?
Problem:
Suppose that $X$ is a uniformly distributed random variable over the interval $[-1,1]$. That is, the density function for $X$ is:
$$ f(x) = \begin{cases}
\frac{1}{2}, & \text{for } {-1} \leq x \leq 1 \\
0, & \text{otherwise }
\end{cases} $$
Now $Y$ is a random variable that follows the triangle distribution. That is, the density function for $Y$ is:
$$ g(y) = \begin{cases}
y + 1, & \text{for } {-1} \leq y \leq 0 \\
1 - y, & \text{for } 0 \leq y \leq 1 \\
0, & \text{otherwise }
\end{cases} $$
We generate a value $x_0$ using the density function $f(x)$. We then generate a value $y_0$ using the density function $g(y)$ such that
$$ \int_{-1}^{x_0} \frac{1}{2} \, dx = \int_{-1}^{y_0} g(y) \, dy $$
What is the correlation between $X$ and $Y$?
Answer:
The formula for correlation is: $$\rho = \frac{\sigma_{xy}}{ \sigma_x \sigma_y } $$ Observe that the $E(X) = E(Y) = 0$. \begin{align*} E(X^2) &= \int_{-1}^{1} \frac{x^2}{2} \, dx = \frac{x^3}{6} \Big|_{-1}^{1} = \frac{1}{6} - \frac{-1}{6} \\ E(X^2) &= \frac{1}{3} \\ \sigma_x^2 &= E(X^2) - (E(x))^2 = \frac{1}{3} \\ \sigma_x &=\frac{ \sqrt{3} }{3} \\ E(Y^2) &= \int_{-1}^{1} y^2 f(y) \, dy = \int_{-1}^{0} y^2 f(y) \, dy + \int_{0}^{1} y^2 f(y) \, dy \\ \int_{-1}^{0} y^2 (y+1) \, dy &= \int_{-1}^{0} y^3 + y^2 \,\, dy = \frac{y^4}{4} + \frac{y^3}{3} \Big|_{-1}^{0} \\ \int_{-1}^{0} y^2 (y+1) \, dy &= 0 - \left( \frac{1}{4} - \frac{1}{3} \right) \\ \int_{-1}^{0} y^2 (y+1) \, dy &= \frac{1}{12} \\ \sigma_y^2 &= E(Y^2) - (E(y))^2 = \frac{1}{12} \\ \sigma_y &= \frac{1}{\sqrt{12}} = \frac{ \sqrt{3} } {6} \end{align*} Now we need to find $\sigma_{xy}$.To do this, we need to find $E(XY)$. Observe that if $-1\leq x \leq 0$ then the area under the $f(x)$ between $x = -1$ and $x = 0$ is $\left( \frac{1}{2}\right) (x + 1)$. Now we need to find $y$ in terms of $x$. \begin{align*} \left( \frac{1}{2}\right) (x + 1) &= \int_{-1}^{y} y + 1 \, dy = \frac{y^2}{2} + y \Big|_{-1}^{y} \\ \left( \frac{1}{2}\right) (x + 1) &= \frac{y^2}{2} + y - \left( \frac{1}{2} - 1 \right) \\ \left( \frac{1}{2}\right) (x + 1) &= \frac{y^2}{2} + y + \frac{1}{2} \\ x + 1 &= y^2 + 2y + 1 \\ x &= y^2 + 2y \\ E(XY) &= 2 \int_{-1}^{0} (y^2+y)(y)(y+1) \, dy \\ \int_{-1}^{0} (y^2+y)(y)(y+1) \, dy &= \int_{-1}^{0} y^4 + y^3 + y^3 + y^2 \, dy \\ \int_{-1}^{0} (y^2+y)(y)(y+1) \, dy &= \int_{-1}^{0} y^4 + 2y^3 + y^2 \, dy \\ \int_{-1}^{0} (y^2+y)(y)(y+1) \, dy &= \frac{y^5}{5}+ \frac{2y^4}{4} + \frac{y^3}{3} \Big|_{-1}^{0} \\ \int_{-1}^{0} (y^2+y)(y)(y+1) \, dy &=0 - \left( -\frac{1}{5} + \frac{2}{4} - \frac{1}{3} \right) = \frac{1}{5} - \frac{2}{4} + \frac{1}{3} \\ \int_{-1}^{0} (y^2+y)(y)(y+1) \, dy &= \frac{1}{30} \\ E(XY) &= \frac{1}{15} \\ \rho &= \frac{ \left( \frac{1}{15} \right) }{ \left( \frac{ \sqrt{3} }{3} \right) \left( \frac{ \sqrt{3} } {6} \right) } = \frac{ \frac{1}{15} } { \frac{3}{18} } \\ \rho &= \frac{2}{5} \end{align*}