Calculating covariance and correlation

correlationcovarianceexpected valueprobabilitystatistics

Suppose we have a bird that lays two eggs. Probability for one egg to hatch is $0.8$ so the probability for it not to hatch is $0.2$. If the egg hatches, there's a $0.5$ probability for it to be a male ($X$) and similarly a $0.5$ probability for female ($Y$). I calculated the probabilities of different configurations from two eggs into this table:

$\begin{array}{c|c|c|}
& \text{X=0} & \text{X=1} & \text{X=2} \\ \hline
\text{Y=0} & 0.04 & 0.16 & 0.16 \\ \hline
\text{Y=1} & 0.16 & 0.32 & 0 \\ \hline
\text{Y=2} & 0.16 & 0 & 0
\end{array}$

I believe that this table is correct, but of course it is subject to possible mistakes, too. I suppose that the actual problem is in calculating the correlation of $X$ and $Y$. First, I calculated the covariance with the formula $cov(X,Y)=E(XY)-E(X)E(Y)=1\cdot0.32-0.8^2=-0.32$, where $E(X)=0\cdot\text{the first column }+1\cdot(0,16+0.32)+2\cdot0.16=0.8$ and similarly $E(Y)=0.8$.

Then I wanted the correlation, $cor(X,Y)=\frac{cov(X,Y)}{\sqrt{Var(X)Var(Y)}}$, so I needed the variances of $X$ and $Y$. From the formula $Var(X)=E(X^2)-E(X)^2$ I got $Var(X)=0.48-0.8^2=-0.16$ and similarly, $Var(Y)=-0.16$. There must be a mistake somewhere, because now calculating the correlation gives

$cor(X,Y)=\frac{cov(X,Y)}{\sqrt{Var(X)Var(Y)}}=\frac{-0.32}{\sqrt{(-0.16)^2}}=-2.$

However, the correlation should be between $-1$ and $1$. Could someone kindly point out my mistake?

Best Answer

From the definition of variance, i.e., $\mathbb{E}[(X - \mathbb{E}[X])^2]$ it is clear that the variance should be non-negative. This is another indicator that your calculation is erroneous. Note that,

\begin{align} \mathbb{E}[X^2] &= 2^2 \cdot 0.16 + 1^2\cdot 0.48 = 0.64 + 0.48 = 1.12 \quad (\text{not }0.48)\\[1em] \mathbb{E}[(X - \mathbb{E}[X])^2] &= \mathbb{E}[X^2] - \mathbb{E}[X]^2 = 1.12 - 0.64 = 0.48. \end{align}

So that, \begin{align} \frac{cov(X,Y)}{\sqrt{Var{X}}\sqrt{Var(Y)}} = \frac{-0.32}{0.48} = -\frac{2}{3}. \end{align}

Hope this helps.

Related Question