# Can a covariance matrix be recalculated for dummy variables?

Say I have the following sample from a continuous variable $$X$$ and a categorical (dichotomous) variable $$Y$$:

  X Y
0.5 1
2.3 2
2.2 2
1.8 1


Moreover, the covariance matrix between $$X$$ and $$Y$$ is also known:

$$\Sigma_{XY} = \begin{pmatrix} \sigma_{XX} & \sigma_{XY} \\ \sigma_{YX} & \sigma_{YY} \end{pmatrix} = \begin{pmatrix} 0.5 & 1.2 \\ 1.2 & 0.4 \end{pmatrix}$$

Now let's say we have dummy-coded $$Y$$, so our data looks like this:

  X Y1 Y2
0.5  1  0
2.3  0  1
2.2  0  1
1.8  1  0


My question is: how can we calculate the covariance matrix between $$X$$, $$Y_1$$ and $$Y_2$$?

$$\Sigma_{XY_1Y_2} = \begin{pmatrix} \sigma_{XX} & \sigma_{XY_1} & \sigma_{XY_2} \\ \sigma_{Y_1X} & \sigma_{Y_1Y_1} & \sigma_{Y_1Y_2} \\ \sigma_{Y_2X} & \sigma_{Y_2Y_1} & \sigma_{Y_2Y_2} \end{pmatrix} = \begin{pmatrix} 0.5 & ? & ? \\ ? & ? & ? \\ ? & ? & ? \end{pmatrix}$$

In my actual problem, I can often bootstrap my way into getting a fair estimate for this matrix, but it is very important for me to find the analytical solution as well. For what it's worth, the proportion of each category in the population is also known.

We've got:

$$Y_1 = 1 - Y_2 \;\;(1)$$ $$Y = Y_2 + 1 \;\;(2)$$ $$Y = 2 - Y_1 \;\;(3)$$

So, using equation $$(1)$$: $$\sigma_{Y_1Y_1} = Var(Y_1) = 0 + (-1)^2 Var(Y_2) = \sigma_{Y_2Y_2}$$ $$\sigma_{Y_1Y_2} = \sigma_{Y_2Y_1} = Cov(Y_1, Y_2) = -Cov(Y_1, Y_1) = -\sigma_{Y_1Y_1}$$

... and using equations (2, 3):

$$Var(Y) = 0.4 = Var(Y_2) = Var(Y_1)$$

As for the other two $$\sigma$$s, assuming that the covariance $$\sigma_{XY}$$ was calculated using their numerical values :

$$\sigma_{XY} = Cov(X, Y) = E((X - E(X))(Y - E(Y))) = 1.2$$ $$= E((X-E(X))(Y_2 + 1 - 1 - E(Y_2))) = \sigma_{XY_2}$$

Similarly:

$$\sigma_{XY} = E((X-E(X))(2 - Y_1 - 2 + E(Y_1))) = -\sigma_{XY_1}$$

$$\Sigma_{XY} = \begin{pmatrix} 0.5 & -1.2 & 1.2 \\ -1.2 & 0.4 & -0.4 \\ 1.2 & -0.4 & 0.4 \end{pmatrix}$$
• Thank you for that, I'll try to reproduce it in my example (and hopefully properly expand to the polytomous case). As for your last remark, correlations involving a continuous and a dichotomous variable are commonly calculated using point-biserial correlation. I am assuming a properly-calculated $\Sigma_{XY}$ could be derived from that, but that's something I'll check later. Oct 12, 2018 at 12:05
• Thanks for the example. Btw, I've made an edit, removing my unreasonable and unneeded $Bernoulli$ assumption. Oct 12, 2018 at 12:40