Sample covariance mean-corrected vector proof

Prove that $$(n-1)S = X^TX -{1\over{n}}(X^T\vec1)(\vec1^TX) = X^TX-n\vec{\bar x}\vec{\bar x}^T$$

My attempt so far goes like this

$$S = {1\over{n-1}}X_m^TX_m$$

Edit: Where $X_m$ is the mean corrected matrix. So

$$(n-1)S = (X-\vec1\vec{\bar x^T})^T(X-\vec1\vec{\bar x^T})$$ $$=(X^T-\vec{\bar x}\vec{1^T})(X-\vec1\vec{\bar x^T})$$ $$=X^TX -X^T\vec1\vec{\bar x^T}-\bar x\vec1^TX + \vec {\bar x}\vec1^T\vec1\vec {\bar x^T}$$

I think the last term can be written as $n\vec {\bar x}\vec {\bar x^T}$ but beyond that I'm not sure where to go from there (if I'm even right so far).

• If $X$ is a vector, then $\bar x$ should be presented as a scalar, not as a vector. Is this the case? Oct 27, 2014 at 15:29
• $X$ is $n$ observations of $p$ variables, so the mean vector is the vector of the mean of variable 1, 2, ... , p $$\vec {\bar x} = (\bar x_1, \bar x_2, ... ,\bar x_p)^T$$ Oct 27, 2014 at 17:15

After the OP's clarifications, $X$ is not a vector but a matrix, and $S$ is a variance covariance matrix.
We have that $\vec{1^T} \vec1= n$, a scalar.
Also, $X^T\vec1$ produces a $p \times 1$ column vector with $\sum_{i=1}^n x_{ji}$ in each position, for the $j=1,...,p$ variables. Multiply and divide by $n$ to get
$$X^T\vec1\vec{\bar x^T} = n\cdot \left(\frac 1n X^T\vec1\right)\vec{\bar x^T} =n\vec{\bar x}\vec{\bar x^T}$$
• Thanks, I think I have it now. So similarly $\vec{1^T}X$ becomes the $p \times 1$ vector with the same values. Therefore $\vec {\bar x} \vec{1^T} X$ is also $n\vec{\bar x}\vec{\bar x^T}$ Oct 27, 2014 at 19:10