01 / 21

Covariance Matrices
& Eigen Decomposition

Master the mathematics of multivariate spread, understand how covariance matrices capture relationships between variables, and discover how eigen decomposition reveals the hidden structure of data.

Statistics Linear Algebra

What is Covariance?

Covariance measures how two variables change together. For random variables \(X\) and \(Y\), the covariance is defined as:

$$\text{Cov}(X, Y) = E\bigl[(X - \mu_X)(Y - \mu_Y)\bigr]$$

Positive
\(\text{Cov} > 0\): variables tend to increase together
Negative
\(\text{Cov} < 0\): one increases as the other decreases
Zero
\(\text{Cov} = 0\): no linear relationship detected

Visualizing Covariance in 2D

Positive Cov X Y Negative Cov X Y Zero Cov X Y

From Covariance to Correlation

The Pearson correlation coefficient normalizes covariance by the standard deviations, giving a scale-free measure bounded between \(-1\) and \(+1\):

$$\rho_{XY} = \frac{\text{Cov}(X, Y)}{\sigma_X \, \sigma_Y}$$

\(\rho = +1\)
Perfect positive linear relationship
\(\rho = 0\)
No linear relationship (not necessarily independent)
\(\rho = -1\)
Perfect negative linear relationship

The Covariance Matrix \(\Sigma\)

For a random vector \(\mathbf{X} = (X_1, X_2, \ldots, X_p)^T\), the covariance matrix collects all pairwise covariances into a single \(p \times p\) matrix:

$$\Sigma = \begin{pmatrix} \text{Var}(X_1) & \text{Cov}(X_1, X_2) & \cdots & \text{Cov}(X_1, X_p) \\ \text{Cov}(X_2, X_1) & \text{Var}(X_2) & \cdots & \text{Cov}(X_2, X_p) \\ \vdots & \vdots & \ddots & \vdots \\ \text{Cov}(X_p, X_1) & \text{Cov}(X_p, X_2) & \cdots & \text{Var}(X_p) \end{pmatrix}$$

Properties of \(\Sigma\)

1
Symmetric: \(\Sigma_{ij} = \Sigma_{ji}\) because \(\text{Cov}(X_i, X_j) = \text{Cov}(X_j, X_i)\).
2
Positive semi-definite: All eigenvalues \(\lambda_i \geq 0\). This guarantees that variance is never negative in any direction.
3
Diagonal entries are variances: \(\Sigma_{ii} = \text{Var}(X_i) \geq 0\).
4
Real eigenvalues: Since \(\Sigma\) is real and symmetric, the Spectral Theorem guarantees all eigenvalues are real and eigenvectors can be chosen orthonormal.

The Spectral Decomposition

Every real symmetric matrix \(\Sigma\) can be decomposed as:

$$\Sigma = Q \Lambda Q^T$$

where \(Q\) is the orthogonal matrix of eigenvectors and \(\Lambda\) is the diagonal matrix of eigenvalues:

$$Q = \begin{pmatrix} | & | & & | \\ \mathbf{q}_1 & \mathbf{q}_2 & \cdots & \mathbf{q}_p \\ | & | & & | \end{pmatrix}, \quad \Lambda = \begin{pmatrix} \lambda_1 & 0 & \cdots & 0 \\ 0 & \lambda_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \lambda_p \end{pmatrix}$$

Geometric Interpretation

\(X_1\)

\(X_2\)

\(\mathbf{q}_1 (\lambda_1)\)

\(\mathbf{q}_2 (\lambda_2)\)

mean

Covariance vs Correlation Matrix

Covariance \(\Sigma\) Correlation \(R\)
Diagonal entries \(\text{Var}(X_i)\) Always \(1\)
Off-diagonal range \(-\infty\) to \(+\infty\) \(-1\) to \(+1\)
Scale-dependent? Yes No
Relationship \(R = D^{-1} \Sigma D^{-1}\) where \(D = \text{diag}(\sigma_1, \ldots, \sigma_p)\)
Use when Variables on same scale, PCA Variables on different scales

How to Compute Eigen Decomposition

1
Center the data: Subtract the mean from each variable: \(\tilde{X}_i = X_i - \bar{X}_i\).
2
Compute \(\Sigma\): \(\Sigma = \frac{1}{n-1}\tilde{X}^T\tilde{X}\) (sample covariance matrix).
3
Solve the characteristic equation: \(\det(\Sigma - \lambda I) = 0\) to find eigenvalues \(\lambda_1 \geq \lambda_2 \geq \cdots \geq \lambda_p\).
4
Find eigenvectors: For each \(\lambda_i\), solve \((\Sigma - \lambda_i I)\mathbf{q}_i = \mathbf{0}\) and normalize.
5
Assemble: Form \(Q = [\mathbf{q}_1 \mid \cdots \mid \mathbf{q}_p]\) and \(\Lambda = \text{diag}(\lambda_1, \ldots, \lambda_p)\).

Worked Example: Building \(\Sigma\)

Given \(n = 5\) observations of two variables \(X_1\) and \(X_2\):

Obs \(X_1\) \(X_2\)
124
246
367
489
51014

Worked Example: Finding Eigenvalues

Our covariance matrix from the previous slide:

$$\Sigma = \begin{pmatrix} 10 & 11.5 \\ 11.5 & 14.5 \end{pmatrix}$$

Characteristic equation:

$$\det(\Sigma - \lambda I) = (10 - \lambda)(14.5 - \lambda) - 11.5^2 = 0$$

$$\lambda^2 - 24.5\lambda + 12.75 = 0$$

Worked Example: Finding Eigenvectors

For \(\lambda_1 \approx 23.97\), solve \((\Sigma - 23.97 I)\mathbf{q}_1 = \mathbf{0}\):

$$\begin{pmatrix} -13.97 & 11.5 \\ 11.5 & -9.47 \end{pmatrix}\mathbf{q}_1 = \mathbf{0} \implies \mathbf{q}_1 \propto \begin{pmatrix} 0.636 \\ 0.772 \end{pmatrix}$$

For \(\lambda_2 \approx 0.53\), solve \((\Sigma - 0.53 I)\mathbf{q}_2 = \mathbf{0}\):

$$\mathbf{q}_2 \propto \begin{pmatrix} -0.772 \\ 0.636 \end{pmatrix}$$

Connection to PCA

Raw Data Center Compute

\(\Sigma\)

Eigen

\(Q\Lambda Q^T\)

PCA Top k

\(\tilde{X} = X - \mu\)

\(\Sigma = \frac{\tilde{X}^T\tilde{X}}{n-1}\)

\(\Sigma\mathbf{q} = \lambda\mathbf{q}\)

\(\mathbf{q}_1 \dots \mathbf{q}_k\)

PCA = Eigen decomposition of the covariance matrix The first k eigenvectors are the first k principal components

Variance Explained by Eigenvalues

The proportion of variance explained by the \(i\)-th principal component is:

$$\text{PVE}_i = \frac{\lambda_i}{\sum_{j=1}^{p} \lambda_j} = \frac{\lambda_i}{\text{tr}(\Sigma)}$$

Component PVE 0% 25% 50% 75% 100% 55% PC1 25% PC2 12% PC3 5% PC4 3% PC5 Cumul.

Common Mistakes

✕ Not Centering Data
Computing \(\Sigma\) without subtracting the mean first gives a wrong matrix that includes squared mean terms.
✕ Wrong Matrix for PCA
Using the correlation matrix when all variables share the same units, or the covariance matrix when scales differ wildly.
✕ Confusing \(\rho = 0\) with Independence
Zero correlation only means no linear relationship. Nonlinear dependencies can still exist.

Question 1 of 5

The covariance matrix \(\Sigma\) is guaranteed to have which of the following properties?

Question 2 of 5

If \(\Sigma = Q\Lambda Q^T\), what is the geometric meaning of the eigenvalue \(\lambda_1\)?

Question 3 of 5

Given \(\Sigma = \begin{pmatrix} 4 & 2 \\ 2 & 3 \end{pmatrix}\), what is the trace of \(\Sigma\), and what does it equal in terms of eigenvalues?

Question 4 of 5

When should you perform PCA on the correlation matrix instead of the covariance matrix?

Question 5 of 5

If a \(3 \times 3\) covariance matrix has eigenvalues \(\lambda_1 = 10\), \(\lambda_2 = 3\), \(\lambda_3 = 2\), what proportion of variance is explained by the first two principal components?