# Calculating the correlation of two related random variables

Problem: Suppose that $x$ is a uniformly distributed random variable on the interval $(0,6)$ and $y = (x-3)^2$. What is the correlation between $x$ and $y$?

Answer: First observe that $u_x = E(x) = 3$ \begin{eqnarray*} E(y) &=& E((x-3)^2) = E(x^2) -6E(x) + 9 \\ E(x^2) &=& \int_0^6 \frac{x^2}{6} \,\,\, dx = \frac{x^3}{18} \Big|_0^6 = \frac{6^3}{18}\\ E(x^2) &=& \frac{6(36)}{{18}} = \frac{36}{3} = 12 \\ E(y) &=& E((x-3)^2) = 12 - 6(3) + 9 = 12 - 18 + 9 = 3 \\ \sigma_x^2 &=& E(x^2) - (E(x))^2 = 12 - 3^2 = 3 \\ \sigma_x &=& \sqrt{3} \\ E(y^2) &=& \int_0^6 \frac{(x-3)^4}{6} \,\,\, dx = \frac{(x-3)^5}{5(6)} \Big|_0^6 = \frac{(6-3)^5}{5(6)} - \frac{(0-3)^5}{5(6)} \\ E(y^2) &=& \frac{3^5}{30} - \frac{-3^5}{30} = \frac{3^5}{30} + \frac{3^5}{30} = \frac{3^4}{10} + \frac{3^4}{10} \\ E(y^2) &=& \frac{81}{5} \\ \sigma_y^2 &=& E(y^2) - (E(x))^2 = \frac{81}{5} - 3^2 = \frac{81 - 9(5)}{5} \\ \sigma_y^2 &=& \frac{36}{5} \\ \sigma_y &=& \frac{\sqrt{36}}{\sqrt{5}} \\ cov(x,y) &=& E(xy) - E(x)E(y) \\ E(xy) &=& E(x(x-3)^2) = \int_0^6 \frac{x(x-3)^2}{6} \,\,\, dx = \int_0^6 \frac{x(x^2-6x+9)}{6} \,\,\, dx \\ E(xy) &=& \int_0^6 \frac{x^3}{6} - x^2 + \frac{9x}{6} \,\,\, dx = \frac{x^4}{24} - \frac{x^3}{3} + \frac{9x^2}{12} \Big|_0^6 \\ E(xy) &=& \frac{36(36)}{24} - \frac{6(36)}{3} + \frac{9(36)}{12} = \frac{3(36)}{2} - \frac{2(36)}{1} + \frac{9(3)}{1} \\ E(xy) &=& 3(18) - 72 + 27 = 9 \\ cov(x,y) &=& 9 - 3(3) = 0 \\ \rho_{xy} &=& \frac{cov(x,y)}{\sigma_x\sigma_y} \\ \rho_{xy} &=& 0 \\ \end{eqnarray*} This answer seems wrong to me. I would like to know what I am missing.

• Is what's bothering you the fact that $X$ and $Y$ are clearly not independent, but seem to be uncorrelated? – kimchi lover Jul 27 '17 at 13:28
• @kimchi, Yes. I would expect the $X$ and $Y$ to have a correlation over $0.8$ and I could believe that it is $1$. Bob – Bob Jul 27 '17 at 13:30
• this does not seem wrong to me (at least at first sight). why do you think it is wrong? – supinf Jul 27 '17 at 13:33
• Correlation is a measure of linear dependence. While $Y$ is dependent on $X$ (in fact determined by), it is not linearly dependent. – Graham Kemp Jul 27 '17 at 13:33
• Didn't you ask a very related question, recently? Surely you tried to apply the techniques explained in its answers, to solve the present question? – Did Jul 27 '17 at 13:33

\begin{align*}\mathsf {Cov}(X,Y) ~&=~ \mathsf {Cov}(X,X^2-6X+9) \\ &=~ \mathsf {Cov}(X,X^2)-6\mathsf {Cov}(X,X)+\mathsf {Cov}(X,9) \\ &=~\mathsf {Cov}(X,X^2) - 6\mathsf{Var}(X) \\ &=~ \int_0^6 \tfrac {x^3}6\operatorname d x - \int_0^6\tfrac {x^2}6\operatorname d x\cdot\int_0^6 \tfrac x6\operatorname d x -6\left(\int_0^6\tfrac {x^2}6\operatorname d x-{\left(\int_0^6 \tfrac x6\operatorname d x\right)}^2\right) \\ &=~\tfrac{6^4}{24}-\tfrac {6^3}{18}\cdotp\tfrac{6^2}{12}-6\left(\tfrac {6^3}{18}-{\left(\tfrac{6^2}{12}\right)}^2\right) \\ &=~ 0 \end{align*}
Remark: Correlation is a measure of the Linear Dependency between two random variables.   Here, although $X,Y$ are clearly dependent (as $Y$ is determined by $X$), the relation is not linear.   Indeed, a plot of $Y$ versus $X$ will show that the curve is a parabola; one symmetrical about the mean over the interval $X\in[0;6]$.   In light of this, a correlation of zero is not surprising.