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.
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]$$
Visualizing Covariance in 2D
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}$$
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\)
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
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
Worked Example: Building \(\Sigma\)
Given \(n = 5\) observations of two variables \(X_1\) and \(X_2\):
| Obs | \(X_1\) | \(X_2\) |
|---|---|---|
| 1 | 2 | 4 |
| 2 | 4 | 6 |
| 3 | 6 | 7 |
| 4 | 8 | 9 |
| 5 | 10 | 14 |
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
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)}$$
Common Mistakes
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?