Centering matrix

In mathematics and multivariate statistics, the centering matrix is a symmetric and idempotent matrix, which when multiplied with a vector has the same effect as subtracting the mean of the components of the vector from every component of that vector. 
Definition.
The centering matrix of size "n" is defined as the "n"-by-"n" matrix
where formula_2 is the identity matrix of size "n" and formula_3 is an "n"-by-"n" matrix of all 1's. 
For example
Properties.
Given a column-vector, formula_7 of size "n", the centering property of formula_8 can be expressed as
where formula_10 is a column vector of ones and formula_11 is the mean of the components of formula_7.
formula_8 is symmetric positive semi-definite.
formula_8 is idempotent, so that formula_15, for formula_16. Once the mean has been removed, it is zero and removing it again has no effect.
formula_8 is singular. The effects of applying the transformation formula_18 cannot be reversed.
formula_8 has the eigenvalue 1 of multiplicity "n" − 1 and eigenvalue 0 of multiplicity 1.
formula_8 has a nullspace of dimension 1, along the vector formula_10.
formula_8 is an orthogonal projection matrix. That is, formula_23 is a projection of formula_7 onto the ("n" − 1)-dimensional subspace that is orthogonal to the nullspace formula_10. (This is the subspace of all "n"-vectors whose components sum to zero.)
The trace of formula_26 is formula_27.
Application.
Although multiplication by the centering matrix is not a computationally efficient way of removing the mean from a vector, it is a convenient analytical tool. It can be used not only to remove the mean of a single vector, but also of multiple vectors stored in the rows or columns of an "m"-by-"n" matrix formula_28.
The left multiplication by formula_29 subtracts a corresponding mean value from each of the "n" columns, so that each column of the product formula_30 has a zero mean. Similarly, the multiplication by formula_26 on the right subtracts a corresponding mean value from each of the "m" rows, and each row of the product formula_32 has a zero mean.
The multiplication on both sides creates a doubly centred matrix formula_33, whose row and column means are equal to zero.
The centering matrix provides in particular a succinct way to express the scatter matrix, formula_34 of a data sample formula_35, where formula_36 is the sample mean. The centering matrix allows us to express the scatter matrix more compactly as
formula_26 is the covariance matrix of the multinomial distribution, in the special case where the parameters of that distribution are formula_39, and formula_40.