1.1 Centering Multivariate Data and Shifting the Origin to the Mean

Every Principal Component Analysis pipeline begins with an essential coordinate transformation: mean-centering. Before searching for directions of maximum spread or minimum reconstruction error, we must shift the coordinate axes so that the origin 0\mathbf{0} sits directly at the empirical center of mass (the sample mean vector μ\boldsymbol{\mu}) of the dataset.

Why is centering non-negotiable? Because any vector subspace—whether a 1D line span(u)\text{span}(\mathbf{u}) or a kk-dimensional hyperplane—is mathematically locked to pass through the origin 0\mathbf{0}. If the data cloud sits far away from 0\mathbf{0}, a line through the origin cannot pass through the middle of the cloud unless it points toward μ\boldsymbol{\mu}, conflating the average location of the data with its internal directional variance.

In this Article

1. Computing the Sample Mean Vector and Centered Data Matrix

Let Xraw∈Rn×dX_{\text{raw}} \in \mathbb{R}^{n \times d} be a data matrix whose nn rows are observations (samples) and whose dd columns are features (variables). Denote the ii-th observation as a column vector xiraw∈Rd\mathbf{x}_i^{\text{raw}} \in \mathbb{R}^d.

The sample mean vector μ∈Rd\boldsymbol{\mu} \in \mathbb{R}^d averages each feature column across all nn observations:

μ=1n∑i=1nxiraw=1nXrawT1n\boldsymbol{\mu} = \frac{1}{n} \sum_{i=1}^n \mathbf{x}_i^{\text{raw}} = \frac{1}{n} X_{\text{raw}}^T \mathbf{1}_n

where 1n=[11…1]T∈Rn\mathbf{1}_n = \begin{bmatrix} 1 & 1 & \dots & 1 \end{bmatrix}^T \in \mathbb{R}^n is the all-ones column vector. Subtracting μ\boldsymbol{\mu} from each observation produces the centered vector xi=xiraw−μ\mathbf{x}_i = \mathbf{x}_i^{\text{raw}} - \boldsymbol{\mu}. In compact matrix form, using the centering matrix H=In−1n1n1nTH = I_n - \frac{1}{n}\mathbf{1}_n \mathbf{1}_n^T:

X=Xraw−1nμT=HXrawX = X_{\text{raw}} - \mathbf{1}_n \boldsymbol{\mu}^T = H X_{\text{raw}}

Zero-Sum Verification Rule: After centering, the sum (and average) of every column of XX must equal zero exactly: ∑i=1nxij=0\sum_{i=1}^n x_{ij} = 0 for every feature j=1,…,dj = 1, \dots, d. This is the quickest arithmetic sanity check when performing PCA by hand.

2. Why Translation Preserves Pairwise Distances and Angles

Does subtracting μ\boldsymbol{\mu} distort the internal geometry of our dataset? Not at all. Consider the displacement vector between any two observations ii and kk after centering:

xi−xk=(xiraw−μ)−(xkraw−μ)=xiraw−xkraw\mathbf{x}_i - \mathbf{x}_k = (\mathbf{x}_i^{\text{raw}} - \boldsymbol{\mu}) - (\mathbf{x}_k^{\text{raw}} - \boldsymbol{\mu}) = \mathbf{x}_i^{\text{raw}} - \mathbf{x}_k^{\text{raw}}

Because μ\boldsymbol{\mu} cancels out identically, every pairwise Euclidean distance ∥xi−xk∥\|\mathbf{x}_i - \mathbf{x}_k\|, every internal angle between pairs of points, and the shape of the cloud's convex hull remain 100% invariant. We have not deformed the cloud; we have merely slid our coordinate crosshairs to its center of gravity.

   BEFORE CENTERING (Origin far from cloud)        AFTER CENTERING (Origin at centroid)
   x2_raw                                          x2
    ^              *  *                             ^         *  *
    |           *  M  *   (Cloud at M=[10,10])      |      *  |  *
    |           *  *                                +------*--0--*------> x1
    |      /                                        |      *  |
    |    /  <-- Line through (0,0) forced           |
    +--0---------------------> x1_raw               (Line through 0 now slices
    (Dominated by vector 0 -> M!)                    along the cloud's true axis!)

3. The Uncentered Trap: Phantom First Principal Components

Suppose a tight horizontal cloud of points sits around μ=[100100]\boldsymbol{\mu} = \begin{bmatrix} 100 \\ 100 \end{bmatrix} with horizontal spread ±2\pm 2 and vertical spread ±0.1\pm 0.1. Its true direction of variation is purely horizontal ([10]\begin{bmatrix} 1 \\ 0 \end{bmatrix}).

However, if you forget to subtract μ\boldsymbol{\mu} and fit a line through the origin [00]\begin{bmatrix} 0 \\ 0 \end{bmatrix}, any horizontal line through [00]\begin{bmatrix} 0 \\ 0 \end{bmatrix} misses the cloud by 100100 vertical units! To get near the points at [100100]\begin{bmatrix} 100 \\ 100 \end{bmatrix}, the uncentered algorithm is forced to tilt the line to 45∘45^\circ ([1/21/2]\begin{bmatrix} 1/\sqrt{2} \\ 1/\sqrt{2} \end{bmatrix}), reporting a completely bogus direction that reflects the mean offset μ\boldsymbol{\mu} rather than the horizontal variance.

4. Step-by-Step Worked Numerical Example

Let us center a 3-observation, 2-feature dataset XrawX_{\text{raw}}:

Observation iiRaw Feature 1 (xi1rawx_{i1}^{\text{raw}})Raw Feature 2 (xi2rawx_{i2}^{\text{raw}})Centered xi1=xi1raw−4x_{i1} = x_{i1}^{\text{raw}} - 4Centered xi2=xi2raw−6x_{i2} = x_{i2}^{\text{raw}} - 6
i=1i = 12233−2-2−3-3
i=2i = 244660000
i=3i = 36699+2+2+3+3
Column Meanμ1=2+4+63=4\mu_1 = \frac{2+4+6}{3} = 4μ2=3+6+93=6\mu_2 = \frac{3+6+9}{3} = 6−2+0+23=0\frac{-2+0+2}{3} = 0−3+0+33=0\frac{-3+0+3}{3} = 0

Notice how the centered points [−2−3],[00],[23]\begin{bmatrix} -2 \\ -3 \end{bmatrix}, \begin{bmatrix} 0 \\ 0 \end{bmatrix}, \begin{bmatrix} 2 \\ 3 \end{bmatrix} now lie cleanly on a single line through the origin with direction vector [23]\begin{bmatrix} 2 \\ 3 \end{bmatrix}.

5. Active Recall Check and Key Takeaways

Quick Check: Test Your Understanding

Question: Given three 2D observations x1raw=[102]\mathbf{x}_1^{\text{raw}} = \begin{bmatrix} 10 \\ 2 \end{bmatrix}, x2raw=[125]\mathbf{x}_2^{\text{raw}} = \begin{bmatrix} 12 \\ 5 \end{bmatrix}, and x3raw=[148]\mathbf{x}_3^{\text{raw}} = \begin{bmatrix} 14 \\ 8 \end{bmatrix}, compute the mean vector μ\boldsymbol{\mu} and the centered vector x1\mathbf{x}_1. What is the Euclidean distance between observations 1 and 3 before and after centering?

Answer: The mean vector is μ=13[10+12+142+5+8]=[125]\boldsymbol{\mu} = \frac{1}{3}\begin{bmatrix} 10+12+14 \\ 2+5+8 \end{bmatrix} = \begin{bmatrix} 12 \\ 5 \end{bmatrix}. Subtracting μ\boldsymbol{\mu} from x1raw\mathbf{x}_1^{\text{raw}} gives x1=[10−122−5]=[−2−3]\mathbf{x}_1 = \begin{bmatrix} 10-12 \\ 2-5 \end{bmatrix} = \begin{bmatrix} -2 \\ -3 \end{bmatrix} (and x3=[23]\mathbf{x}_3 = \begin{bmatrix} 2 \\ 3 \end{bmatrix}). Before centering, the displacement is [14−108−2]=[46]\begin{bmatrix} 14-10 \\ 8-2 \end{bmatrix} = \begin{bmatrix} 4 \\ 6 \end{bmatrix} with distance 42+62=52\sqrt{4^2+6^2} = \sqrt{52}. After centering, the displacement is [2−(−2)3−(−3)]=[46]\begin{bmatrix} 2-(-2) \\ 3-(-3) \end{bmatrix} = \begin{bmatrix} 4 \\ 6 \end{bmatrix} with the exact same distance 52\sqrt{52}.

Take a Quiz Based on This Article

Test your understanding with AI-generated questions tailored to this content

Adaptive Learning with SynLearn

Explore this article through guided practice that adapts to your answers

✓Step-by-step concepts & lessons
✓Active recall & adaptive feedback
✓Personalized spaced repetition
mean-centering
pca
multivariate-statistics
data-preprocessing
linear-algebra