Why are these two random variables correlated? The process to generate the two RVs is as follows. We first draw $T$ from $Uniform(0, 1)$. If $T \leq 0.5$ we take $X = T$ and draw $Y$ from $Uniform(0, 1)$. Otherwise if $T > 0.5$, we take $Y = T$ and draw $X$ from $Uniform(0, 1)$. Running a simulation it seems like $X$ and $Y$ are positively correlated, though intuitively it seems like they should have no effect on each other. What is the explanation?
 A: Let's compute $E[XY] - E[X]E[Y]$. We have $E[Y] = \frac{1}{2}(E[Y\mid T \le 0.5] + E[Y \mid T > 0.5]) = \frac{0.5 + 0.75}{2} $. Similarly, we have $E[X] = \frac{1}{2}(E[X \mid T \le 0.5] + E[X \mid T > 0.5]) = \frac{0.25 + 0.5}{2}$.
Then, we have $E[XY] = \frac{1}{2}(E[XY \mid T \le 0.5] + E[XY \mid T > 0.5])$. If $T \le 0.5$, $Y$ is independent from $X$, so $E[XY \mid T \le 0.5] = 0.25 \cdot 0.5$. Similarly, when $T > 0.5$, $Y$ is indepdent from $X$, so $E[XY \mid T > 0.5] = 0.5 \cdot 0.75$. Thus, we have $\operatorname{cov}(X, Y) = \frac{1}{2}(0.125 + 0.375) - \frac{1.25 \cdot 0.75}{4} \approx 0.0156$, indicating a positive correlation.
A: Of course they are correlated. For one thing they are not independent (as $X$ can only be bigger than $0.5$ if $Y> 0.5$ and conversely $Y$ can only be smaller than $0.5$ if $X\leq 0.5$).
But in fact they are positively correlated, as the cases with $X>0.5$, $Y<0.5$ cannot happen.
Let’s calculate this:
$$ \mathbb E(X) = \int_0^{0.5} x\,dx + 0.5\int_0^1 x\,dx = (0.5^2 + 0.5)/2 = 0.75/2 = 0.375$$
and
$$ \mathbb E(Y) = 0.5\int_0^1 x\,dx + \int_{0.5}^{1} x\,dx = (0.5 + (1-0.5^2))/2 = 0.625$$
Then
$$ \mathbb E((X-0.375)(Y-0.625)) = \int_0^{0.5} (x-0.375)\int_0^1(y-0.625)\,dy\,dx + \int_0^1 (x-0.375)\int_{0.5}^1(y-0.625)\,dy\,dx$$
which amounts to $1/64$ for the covariance. So the correlation is positive. We’d still need to calculate the variance of $X,Y$ (which is the same) for the correlation:
$$
\mathbb E(X^2) = \int_0^{0.5}x^2\,d x + 0.5\int_0^1x^2\,dx = (0.5^3+0.5)/3 = (5/8)/3=5/24$$
so
$$ \mathrm{Var} X = 5/24 - (3/8)^2 = 13/192 $$
so we get a correlation of
$$ (1/64)/(13/192) = 3/13 \approx 0.23 $$
