How to get expectation of a table $X$ and $Y$ are random variables with joint distribution table given as
$$\begin{array}{l|ccc}
    & x=1  & x=2  & x=3 \\ \hline
y=1 & 3/12 & 1/12 & 3/12 \\
y=2 & 1/12 & 3/12 & 1/12 
\end{array}$$
Calculate $\mathrm{Cov}(X, Y)$ and explain why $X$ and $Y$ are independent.

Attempt:
I know
$$\mathrm{Cov}(X, Y) = E(XY) - E(X)E(Y)$$
But I'm not sure how to calculate the expectations
$$E(X) = 1 \times \frac3{12} + 2 \times \frac1{12} + 3 \times \frac3{12}$$
I don't think thats right because of the y value. Could someone help
 A: Your first intiution is correct, however the expected value of the random variable $X$ is given by the expected value of the marginal probability density function of X. It means that in order to get $E(X)$, you have to sum up on X, to get $E(Y)$ you have to do the same but on $Y$.
$$
\begin{array}{l|ccc}
    & x=1  & x=2  & x=3 & P(Y=y) \\ \hline 
y=1 & 3/12 & 1/12 & 3/12 & 7/12\\
y=2 & 1/12 & 3/12 & 1/12 & 5/12\\
P(X=x) & 4/12 & 4/12 & 4/12 & 1
\end{array}
$$
In that case you can calculate E(X) and E(Y) as follows:
$$
E(X) = 1 \times \frac{4}{12} + 2 \times \frac{4}{12} + 3\times \frac{4}{12} = 2
$$
$$
E(Y) = 1 \times \frac{7}{12} + 2 \times \frac{5}{12} = \frac{17}{12}
$$
You can get $E(XY)$ by simply multiplying each probability value at the table by the corresponding $x$ and $y$ values:
$$
E(XY) = 1 \times 1 \times \frac {3}{12} + 1 \times 2 \times \frac{1}{12} + 1 \times 3 \times \frac{3}{12} + 2 \times 1 \times \frac{1}{12} + 2 \times 2 \times \frac{3}{12} + 2 \times 3 \times \frac{1}{12} = \frac{17}{6}
$$
Hence the covariance is as follows:
$
Cov(X,Y) = E(XY) - E(X)E(Y) = \frac{17}{6} - 2 \times \frac{17}{12} = 0
$
