We were asked to find a symmetric idempotent matrix $H$ with rank $n-1$ such that if $X$ is a column vector with $n$ observations, then ${1\over n}X^THX$ is the variance of observations in $X$.
I found the matrix (for $n$ obs) to be $H_n=I_n-{1\over n}A_n$ where $I_n$ is identity matrix of dimension $n\times n$, $A_n$ is again $n\times n$ with all observations being $1$ and $H_n$ is the required matrix.
It was easy to show this is symmetric and idempotent but I'm facing difficulty with showing its rank is $n-1$.
However, it is easy to see $R_1+R_2+\dots+R_n=0$ where $R_i$ is the $i^{th}$ row. So its rank is strictly less than $n$.
I also noticed $R_1+R_2+\dots+R_n-R_i\ne0$ for any $i$.
How should I proceed?
Denoting the column vector of all $1$s by $\mathbf1$, we have$$H=I_n-\frac{1}{n}\mathbf{11}^\top$$
Indeed as you say, $H$ is an idempotent matrix. Then we know that $$\mathrm{rank}(H)=\mathrm{trace}(H)=\mathrm{trace}(I_n)-\mathrm{trace}\left(\frac{1}{n}\mathbf{11}^\top\right)=n-1$$
We can also use some trivial rank inequalities although this is quite unnecessary to prove the result:
We know that for any two matrices $A$ and $B$ having the same order, $$\mathrm{rank}(A-B+B)\le \mathrm{rank}(A-B)+\mathrm{rank}(B)$$
Or, $$\mathrm{rank}(A-B)\ge |\mathrm{rank}(A)-\mathrm{rank}(B)|$$
Noting that $\mathbf{11}^\top$ is a rank $1$ matrix, applying this inequality on $H$ we get,
$$\mathrm{rank}(H)\ge n-1$$
Now we can show that $\mathrm{rank}(H)$ is never $n$ (the only other possibility) from the fact that $$\det(H)=1-\frac{1}{n}\mathbf1^\top\mathbf1=1-1=0$$
So it must be that $$\mathrm{rank}(H)=n-1$$