From a Covariance Matrix to a PCA Calculation
In population PCA, the principal directions are unit eigenvectors of the covariance matrix. Their eigenvalues give the variances of the corresponding component scores. A two-variable calculation lets us see how these ideas fit together: first find the directions, then calculate their variances, and finally use one direction to approximate a centered observation.
Let \(X\) be a random vector with mean \(\mu\), and let \(Z=X-\mu\) be its centered version. For this tutorial, take its covariance matrix to be
A unit direction \(v\) produces the scalar score \(v^\mathsf{T}Z\). Its variance is \(v^\mathsf{T}\Sigma v\). The first principal direction maximizes this variance among unit directions; the second is orthogonal to the first and captures the remaining direction. Here we calculate these quantities directly rather than relying on a software output.
Worked Example: Eigenvalues and Unit Eigenvectors
Worked Example: Eigenvalues and Unit Eigenvectors
Find both eigenvalues and a corresponding pair of orthonormal eigenvectors for \(\Sigma\).
An eigenvalue \(\lambda\) makes \(\Sigma-\lambda I\) singular, so we solve its characteristic equation:
The quadratic formula gives
The larger eigenvalue is \(\lambda_1\), so its eigenvector gives the first principal direction. In the first row of \((\Sigma-\lambda_1 I)v_1=0\), set the first coordinate to \(4\). The equation \((4-\lambda_1)4+2y=0\) then gives \(y=\sqrt{17}-1\). Thus an eigenvector is \((4,\sqrt{17}-1)^\mathsf{T}\). Its squared length is
Writing \(D=\sqrt{34-2\sqrt{17}}\), a unit eigenvector is
An orthogonal unit vector is
Both vectors have length one, because their squared numerators are \(34-2\sqrt{17}\). Their dot product is zero: \(4(\sqrt{17}-1)-4(\sqrt{17}-1)=0\). Since \(\Sigma\) is symmetric, the vectors for distinct eigenvalues are orthogonal; thus this choice of \(v_2\) is an eigenvector for \(\lambda_2\). The two eigenvalues are positive, as required for a covariance matrix.
Why the Eigenvalues Are the Projected Variances
The calculation above identifies candidate directions. The following derivation confirms exactly how their eigenvalues relate to score variability. For any fixed unit vector \(a\), the score \(a^\mathsf{T}Z\) has mean zero because \(E[Z]=0\). By the definition of covariance,
The second equality is the scalar identity \((a^\mathsf{T}Z)^2=a^\mathsf{T}ZZ^\mathsf{T}a\). The third moves the fixed vector \(a\) outside the expectation; this requires only that the second moments in \(\Sigma\) exist. In particular, for a unit eigenvector \(v_j\),
So the first score has variance approximately \(5.562\), and the second has variance approximately \(1.438\). Their sum is \(7\), which equals the total variance \(\operatorname{tr}(\Sigma)=4+3=7\). In this example the first component accounts for a proportion \(\lambda_1/7\approx0.795\) of the total variance.
Worked Example: Variance in a Different Direction
Compare the first principal direction with the unit direction \(u=(1,1)^\mathsf{T}/\sqrt{2}\). Its projected variance is
This is less than the first eigenvalue, approximately \(5.562\), as it must be: the first principal direction maximizes projected variance over all unit directions. The result also shows why the direction with equal coordinates is not automatically the first principal direction, even when the two variables are being considered together.
Reconstructing an Observation with One Component
A component score describes one observation’s coordinate along a direction. For a centered observation \(z\), keeping only its first principal component gives the projection \(t_1v_1\), where \(t_1=v_1^\mathsf{T}z\). This reconstruction is a vector, whereas the eigenvalue describes variance across the population. The two quantities are related, but they are not interchangeable.
Worked Example: One-Component Reconstruction
Take the centered observation \(z=(3,1)^\mathsf{T}\). Calculate its first-component score, its one-component reconstruction, and the squared reconstruction error.
Using \(v_1\) from the eigenvalue calculation, its score is
The one-component reconstruction is \(t_1v_1\). Since \(D^2=34-2\sqrt{17}\), this is
The residual is therefore
To check the squared error, first calculate the score along the omitted direction:
Because \(v_1,v_2\) are an orthonormal basis, \(z=t_1v_1+t_2v_2\). Subtracting the reconstruction \(t_1v_1\) leaves \(t_2v_2\), whose squared length is \(t_2^2\), since \(v_2\) has unit length. Thus the squared residual is approximately \(1.119\), consistent with the displayed residual vector. In exact form it is \((3\sqrt{17}-7)^2/(34-2\sqrt{17})\).
Reconstruction Error and Its Population Meaning
The previous example illustrates a general two-dimensional identity. For any centered vector \(z\), its coordinates in the orthonormal basis \(v_1,v_2\) are \(t_1=v_1^\mathsf{T}z\) and \(t_2=v_2^\mathsf{T}z\). Therefore \(z=t_1v_1+t_2v_2\). A one-component reconstruction retains the first term, so its residual is \(t_2v_2\). Taking squared lengths gives
For a random centered observation \(Z\), the expected squared one-component error is consequently
The last equality holds because the score has mean zero and variance \(\lambda_2\). For this covariance matrix, the population mean squared error from retaining one component is \((7-\sqrt{17})/2\approx1.438\). It need not equal the error for a particular observation: the worked observation’s squared error is approximately \(1.119\).
If the original observation is not centered, say \(x\) with population mean \(\mu\), apply the calculation to \(z=x-\mu\). The corresponding one-component reconstruction on the original scale is \(\mu+t_1v_1\). Adding the mean back is essential; the projection calculated here is specifically for a centered vector.
Common Mistakes and Checks
- Confusing an eigenvalue with an individual score. The eigenvalue is the variance of a component score across the population. A particular observation has a score such as \(t_1\approx2.980\), not a score equal to \(\lambda_1\).
- Using an unnormalized eigenvector as if it were a PCA direction. A scalar multiple is still an eigenvector, but projected variance equals the eigenvalue when the direction has unit length. Normalize before interpreting score variance.
- Reporting the retained part as the residual. The reconstruction is \(t_1v_1\); the residual is \(z-t_1v_1=t_2v_2\). In the example these are approximately \((2.35,1.83)^\mathsf{T}\) and \((0.65,-0.83)^\mathsf{T}\), respectively.
- Assuming each observation’s error equals the omitted eigenvalue. The eigenvalue \(\lambda_2\) is the expected squared error over the population. An individual error is \(t_2^2\), which can differ from that expectation.
A useful arithmetic check is that the component variances sum to the trace, \(5.562+1.438=7\), and that the centered observation’s squared length splits into its two squared scores, \(3^2+1^2=t_1^2+t_2^2\), up to rounding. These checks catch many calculation and transcription errors.
Check Your Understanding
Use the covariance matrix and calculations above to answer these questions.
- What characteristic equation gives the eigenvalues of \(\Sigma\), and why is \(\lambda_1\) the first-component variance?
- For \(u=(1,1)^\mathsf{T}/\sqrt{2}\), what is the projected variance, and how does it compare with \(\lambda_1\)?
- For the centered observation \(z=(3,1)^\mathsf{T}\), what is the one-component reconstruction and how is the residual obtained?
- Why is the squared reconstruction error for this observation not required to equal \(\lambda_2\)?
- What change is needed to express a one-component reconstruction for an uncentered observation \(x\)?