01 / 22

Principal Component
Analysis (PCA)

Discover how PCA transforms high-dimensional data into a compact set of uncorrelated components that capture maximum variance.

Statistics

What Is PCA?

Principal Component Analysis is a linear dimensionality reduction technique. It finds new orthogonal axes, called principal components, along which the data exhibits the greatest variance.

Think of PCA as rotating the coordinate system so the first axis aligns with the direction of greatest spread, the second axis captures the next greatest spread perpendicular to the first, and so on.

Why Reduce Dimensions?

Visualization
Project data from \(p\) dimensions onto 2 or 3 dimensions for plotting and exploration.
Noise Removal
Lower components often capture noise. Keeping only the top \(k\) components filters it out.
Efficiency
Fewer features speed up downstream algorithms and reduce overfitting risk.

Visual Intuition

\(x_1\) \(x_2\) PC1 PC2 PC1 captures maximum variance; PC2 is orthogonal

The Covariance Matrix \(\Sigma\)

PCA begins by computing the sample covariance matrix of the centered data. If \(\mathbf{X}\) is an \(n \times p\) matrix whose columns have been mean-centered:

Diagonal entries
Variance of each variable: \(s_{jj} = \text{Var}(X_j)\)
Off-diagonal entries
Covariance between pairs: \(s_{jk} = \text{Cov}(X_j, X_k)\)

Eigen-decomposition of \(\mathbf{S}\)

Because \(\mathbf{S}\) is symmetric, the Spectral Theorem guarantees it can be decomposed as:

Each eigenvalue \(\lambda_j\) equals the variance of the data along \(\mathbf{v}_j\). The eigenvector with the largest eigenvalue defines PC1.

Computing the Principal Components

1
Center the data: subtract the column means so each feature has mean zero.
2
Compute \(\mathbf{S}\): form the \(p \times p\) sample covariance matrix.
3
Eigen-decompose: find eigenvalues \(\lambda_1 \geq \cdots \geq \lambda_p\) and eigenvectors \(\mathbf{v}_1, \ldots, \mathbf{v}_p\).
4
Project: the \(j\)-th principal component scores are \(\mathbf{z}_j = \mathbf{X}\,\mathbf{v}_j\).
5
Select \(k\): keep only the top \(k\) components that explain sufficient variance.

PCA vs Factor Analysis

PCA Factor Analysis
Goal Maximize variance explained Identify latent factors
Model No explicit generative model Assumes \(\mathbf{x} = \boldsymbol{\mu} + \mathbf{L}\mathbf{f} + \boldsymbol{\epsilon}\)
Uniqueness Unique solution (up to sign) Rotation-dependent
Error term None assumed Per-variable error \(\boldsymbol{\epsilon}\)
Use case Compression, preprocessing Theory-driven constructs

Covariance Matrix vs Correlation Matrix

Covariance PCA
Use on \(\mathbf{S}\) when variables share the same units/scale. Preserves original variance magnitudes.
Correlation PCA
Standardize first (z-score), then PCA on \(\mathbf{R}\). Essential when variables have different scales.

How to Apply PCA

1
Inspect scales: if variables differ in units, standardize the data first.
2
Compute \(\mathbf{S}\) (or \(\mathbf{R}\)): form the covariance or correlation matrix.
3
Find eigenvalues and eigenvectors: solve \(\mathbf{S}\mathbf{v} = \lambda\mathbf{v}\).
4
Scree plot: plot eigenvalues in descending order and look for the "elbow".
5
Choose \(k\): retain components explaining > 80-90% of total variance (or use Kaiser's rule: \(\lambda_j > 1\) for correlation PCA).
6
Interpret loadings: examine eigenvector entries to understand which original variables contribute most to each PC.

Worked Example: 2D Data

Suppose we have 5 observations on two variables \(X_1\) and \(X_2\) (already centered):

Obs. \(X_1\) \(X_2\)
1\(-2\)\(-1\)
2\(-1\)\(0\)
3\(0\)\(0\)
4\(1\)\(1\)
5\(2\)\(0\)

Finding the Eigenvalues

Solve \(\det(\mathbf{S} - \lambda\mathbf{I}) = 0\):

PC1 variance
\(\lambda_1 = 2.75\), capturing \(\approx\) 91.7% of total variance.
PC2 variance
\(\lambda_2 = 0.25\), capturing \(\approx\) 8.3% of total variance.

Eigenvectors and Projection

For \(\lambda_1 = 2.75\), the eigenvector (normalized) is approximately:

To project observation \(\mathbf{x} = (-2, -1)^\top\) onto PC1:

The score \(z_1 \approx -2.214\) is the coordinate of that observation along the PC1 axis.

The Scree Plot

0 1 2 3 4 elbow PC1 PC2 PC3 PC4 PC5 PC6 Component Eigenvalue

Proportion of Variance Explained

Two key metrics help you decide how many components to retain:

Individual proportion
$$\frac{\lambda_j}{\sum_{i=1}^{p}\lambda_i}$$
Cumulative proportion
$$\frac{\sum_{i=1}^{k}\lambda_i}{\sum_{i=1}^{p}\lambda_i}$$

Common Mistakes

✕ Forgetting to Standardize
When variables have different units (e.g., height in cm vs weight in kg), PCA on the raw covariance matrix is dominated by the highest-variance variable.
✕ Interpreting PCs as Factors
PCs are mathematical summaries, not latent constructs. Labeling PC1 as "intelligence" is over-interpretation without domain justification.
✕ Using PCA on Non-linear Data
PCA captures linear relationships. If data lies on a curved manifold, PCA will fail to reduce it well. Consider kernel PCA or t-SNE instead.

PCA Quick Reference

Concept Key Fact
Input Centered (or standardized) data matrix \(\mathbf{X}_{n \times p}\)
Decomposition \(\mathbf{S} = \mathbf{V}\boldsymbol{\Lambda}\mathbf{V}^\top\)
PC scores \(\mathbf{Z} = \mathbf{X}\mathbf{V}_k\) (project onto top \(k\) eigenvectors)
Variance of PC\(_j\) \(\lambda_j\)
Total variance \(\text{tr}(\mathbf{S}) = \sum \lambda_j\)
PCs are Uncorrelated (orthogonal directions)
When to standardize Variables on different scales/units

Question 1 of 5

What does the first principal component maximize?

Question 2 of 5

If the eigenvalues of a \(4 \times 4\) covariance matrix are \(\lambda_1 = 5,\; \lambda_2 = 3,\; \lambda_3 = 1.5,\; \lambda_4 = 0.5\), what proportion of variance does PC1 explain?

Question 3 of 5

When should you perform PCA on the correlation matrix rather than the covariance matrix?

Question 4 of 5

Which property do the principal components always satisfy?

Question 5 of 5

A dataset has \(p = 10\) variables. After PCA on the correlation matrix, the first 3 eigenvalues are each greater than 1, and the remaining 7 are less than 1. How many components does Kaiser's rule suggest retaining?