# Step by step correlation calculation

I must understand how I can calculate the correlation for the following probability variables.

X  -1    0    1
1/4  1/2  1/4

Y =  X^2(this is an edit) =     0       1
1/2     1/2


The correlation formula r(X,Y) = E[(X- E(X))(Y -E(Y))] / D(X) * D(Y)

I calculate E(X) = 0 and E(Y) = 1/2.

My calculations stops here: E(X(Y - 1/2)) =?

Please patient person explain me how I can calculate step by step, this example or any example you want, but with this formula.

Thank you very much.

-

Let us use your formula. First deal with the denominator. What you called $D(X)$ and $D(Y)$ are the standard deviations of $X$ and of $Y$ respectively.

The standard deviation is the square root of the variance, and the variance of a random variable $W$ is $E(W-E(W))^2$.

For $X$, we have $E(X)=0$, so $X-E(X)=X$. So we want $E(X^2)$. When $X=-1$, we have $X^2=1$. When $X=1$ we also have $X^2=1$. So $X^2=1$ with probability $1/4+1/4=1/2$, and $X^2=0$ with probability $1/2$. It follows that $E(X^2)=1/2$, so $D(X)=\sqrt{1/2}$.

Similarly, to find the variance of $Y$, we find $E(Y-E(Y))^2$. Here $E(Y)=1/2$, so we want $E((Y-1/2)^2)$. Now $Y-1/2$ is $-1/2$ with probability $1/2$, and $1/2$ with probability $1/2$. So $(Y-1/2)^2=1/4$ with probability $1$, and therefore has expectation $1/4$. This is the variance of $Y$. Thus $D(Y)=\sqrt{1/4}$.

Now we calculate the numerator, $E((X-E(X))(Y-E(Y))$. We have $X-E(X)=X$ and $Y-E(Y)=Y-1/2$. So we want to find $E(X(Y-1/2))$. That is the stage you were at.

When $X=-1$, we have $Y=X^2=1$, so $X(Y-1/2)=(-1)(1/2)=-1/2$. This happens with probability $1/4$.

When $X=0$, of course $X(Y-1/2)=0$. This happens with probability $1/2$.

When $X=1$, we have $Y=X^2=1$, and therefore $X(Y-1/2)=1/2$. This happens with probability $1/4$.

Now $E(X(Y-1/2))$ is easy to calculate. It is $0$.

Divide by $D(X)D(Y)$. We get $0$. All this work for nothing!

The point of this problem: The random variables $X$ and $X^2$, that is, $X$ and $Y$, are obviously not independent. To see this, note for example that the probability that $X=1$ and $Y=0$ is obviously $0$, so it is not $\Pr(X=1)\Pr(Y=0)$.

But $X$ and $Y$ are uncorrelated (they have correlation coefficient $0$). So the point of the problem is to show you that uncorrelated does not imply independent.

Remark: There are efficient shortcuts for computing covariance and variance. For example, the covariance of $X$ and $Y$ turns out to be $E(XY)-E(X)E(Y)$, which is usually easier to deal with than the expression you quoted. In our case, the situation was so simple that not much added work is involved.

Similarly, the variance of $W$ is $E(W^2)-(E(W))^2$. This is usually easier to compute than $E((W-E(W))^2)$.

-
thank you, I understand yet :D:D:D:D –  Tatar Elemér Nov 19 '12 at 21:49
@flatronka: Without some assumptions about the relationship between $X$ and $Y$, it is impossible to determine the correlation coefficient. Always, when $X$ and $Y$ are independent, the correlation coefficient is $0$. Sometimes, as in this case, the correlation coefficient can be $0$ even though the random variables are not independent. In this case, the reason is the symmetry of the distribution of $X$ about $0$, and the fact that Y=X^2$. – André Nicolas Nov 19 '12 at 22:12 edit There is a very good answer for the corrected question by André Nicolas. I will not delete my answer for the old question, since somebody voted it up. However I will show how to easily calculate the numerator of r(X,Y) (for the corrected question) using a table. We know that E(X) = 0, E(Y) = 1/2. We observe that the value of Y = X^2 is fixed if we know the value of X. Therefore the probabilities of (X,Y) pairs are determined by the probabilities of X. (X,Y) pair probability of this pair (X-E(X))(Y-E(Y)) (-1, 0) 0 (-1 - 0)(0 - 1/2) = 1/2 (-1, 1) 1/4 (-1 - 0)(1 - 1/2) = -1/2 ( 0, 0) 1/2 ( 0 - 0)(0 - 1/2) = 0 ( 0, 1) 0 ( 0 - 0)(1 - 1/2) = 0 ( 1, 0) 0 ( 1 - 0)(0 - 1/2) = -1/2 ( 1, 1) 1/4 ( 1 - 0)(0 - 1/2) = 1/2  Of course we calculate E[ (X-E(X)) (Y-E(Y)) ] as sum of (probability of a pair) * (X-E(X))(Y-E(Y), so:$ E[ (X-E(X)) (Y-E(Y)) ] = 0 \cdot \frac{1}{2} + \frac{1}{4} \cdot (-\frac{1}{2}) + \frac{1}{2} \cdot 0 + 0 \cdot 0 + 0 \cdot (-\frac{1}{2}) + \frac{1}{4} \cdot \frac{1}{2} = -\frac{1}{8} + \frac{1}{8} = 0$r(X,Y)=0, so X and Y are uncorrelated but are not independent - for more info on this see the answer by André Nicolas. Below is the solution for the unedited question. end edit I understand that by X -1 0 1 1/4 1/2 1/4  you mean that probability that X has value -1 is 1/4, probability that X has value 0 is 1/2 and probability that X has value 1 is 1/4. Similarly for Y: Y 0 1 1/2 1/2  probability of Y being 0 is 1/2 and probability of Y being 1 is 1/2. As you see probabilities for X do not depend on the value of Y (probability of X being -1 is 1/4, no matter what value Y has). Similarly, probabilities for Y do not depend on the value of X. So we can simplify the numerator in the formula for r(X,Y): E[(X - E(X))(Y - E(Y))] = E[X - E(X)] E[Y - E(Y)] = 0 * 0 = 0  So the correlation coefficient is 0. The variables X and Y are not correlated. In fact we knew it from the begining - we saw that there is no connection between the values of X and probabilities of Y and vice versa, so there is no correlation... - thanks for the answer, now I edit the question a bit – Tatar Elemér Nov 19 '12 at 20:30 @au700: We cannot determine whether$X$and$Y$are independent by just considering the distributions of$X$and$Y\$. And in fact as the OP amended the question, they are not independent. (In the question as put first, one cannot determine the covariance.) –  André Nicolas Nov 19 '12 at 22:07
Sorry for the edit, I vote up your question, thanks for the another solution for the edited question. I try to understand –  Tatar Elemér Nov 19 '12 at 22:15
@AndréNicolas You're right, in the answer to the original question I assumed that X and Y were independent. And this is why: I thougt X and Y were defined by the two tables in the begining of my original answer. If they were defined this way, they would be independent. –  au700 Nov 19 '12 at 22:24