$I$: identity matrix of $p \times p$
$B$: matrix of size $p \times p$.
$X$: a data matrix of size $n \times p$
$\displaystyle \text{Tr}\big((I-B)(I-B)^TX^TX\big) =\sum_{k=1}^{p}\sum_{i=1}^{n} \Bigg(x_{ik}-\sum_{j=1}^{p} \beta_{jk}x_{ij}\Bigg)^2$
Can anyone prove (or disprove) this? If not, then how can we express the trace of this matrix? Thanks
EDITED: Yes, it is true.
I presume $x_{ij}$ are the entries of $X$ and $\beta_{ij}$ the entries of $B$.
$$\text{Tr}((I-B)(I-B)^T X^T X) = \text{Tr}(X (I-B)(I-B)^T X^T) = \text{Tr}(Q Q^T)$$ where $Q = X (I-B)$. The entries of $Q$ are $$ q_{ij} = x_{ij} - \sum_{k} x_{ik} \beta_{kj}$$ and $$\text{Tr}(Q Q^T) = \sum_i \sum_j q_{ij}^2 $$