TITLE: unbiased estimate of the covariance
QUESTION [15 upvotes]: How can I prove that
$$
\frac 1 {n-1} \sum_{i=1}^n (X_i - \bar X)(Y_i-\bar Y)
$$
is an unbiased estimate of the covariance $\operatorname{Cov}(X, Y)$
where $\bar X = \dfrac 1 n \sum_{i=1}^n X_i$ and $\bar Y = \dfrac 1 n \sum_{i=1}^n Y_i$ and $(X_1, Y_1), \ldots ,(X_n, Y_n)$ an independent sample from random vector  $(X, Y)$?

REPLY [5 votes]: Just adding on top of the above post by @BruceET and expanding the last term (may be useful for someone):
$E\left[\left(\sum\limits_{i=1}^{n}X_i\right).\left(\sum\limits_{j=1}^{n}Y_j\right)\right]$
$=E\left[\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}X_i.Y_j\right]$
$=E\left[\sum\limits_{(i,j=1\ldots n) \wedge (i=j)}X_i.Y_j+\sum\limits_{(i,j=1\ldots n) \wedge (i\neq j)}X_i.Y_j\right]$
$=E\left[\sum\limits_{i=1}^{n}X_i.Y_i\right]+E\left[\sum\limits_{(i,j=1\ldots n) \wedge (i\neq j)}X_i.Y_j\right]$ 
$=\sum\limits_{i=1}^{n}E\left[X_i.Y_i\right]+\sum\limits_{(i,j=1\ldots n) \wedge (i\neq j)}E\left[X_i.Y_j\right]$     (by linearity of expectation)
$=n\mu_{XY}+n(n-1)\mu_X\mu_Y$ (Since $X_i \perp \!\!\! \perp  Y_j$ for $i \neq j$)