Which way does a cloud of points spread the most? Watch a line turn through the cloud while the spread of the points’ shadows is traced.
The direction of most spread
Turn a line through six points and watch how far their shadows spread.
Six points, centred on the origin, and a line through it. Each point casts a shadow on the line.
Describe this picture
Two panels (stacked on a phone). In the first, six points on a grid, , , , , and , and a line through the origin. The line turns once through 180°, and each point drops a short dashed segment onto it at a right angle, ending in a dot: its shadow. In the second panel, the spread of the six shadows, their variance, is traced against the line’s angle as it turns. It rises and falls once, peaking at 18 at 26.57°, where the line points along , and falling to 4 at 116.57°. The peak is then marked on the curve, and the line turns on to settle at the peak. Readouts give the angle, the shadow variance and its share of the total, 22. One control after the clip: drag the end of the line round, or turn it with the arrow keys, one degree a step; the shadows, the readouts and a dot on the curve follow.
The spread along a direction
The six points in the picture are already centred: their average is the origin. That is the first step of every analysis here, since spread is measured from the middle.
Pick a direction, a unit vector . Each point casts a shadow on the line of of signed length , as on Length and the dot product. The spread of those shadows is their variance. Here and below, the variance divides the sum of squares by , one less than the number of points, as in Covariance and correlation.
Along the horizontal axis the shadows are the values, with variance ; along the vertical axis the values, with variance . Neither is the largest. The line in the picture finds 18, along .
The covariance matrix
Stack the centred points as the rows of a data matrix , one row per point. The covariance matrix is
Its diagonal holds the variance of each coordinate, and its off-diagonal entry the covariance of the two. For the six points, , and , so
The variance of the shadows along a unit is the energy of Positive definite matrices:
is symmetric, so by Symmetric matrices that is in its eigenvector coordinates. The largest it can be, for a unit , is the top eigenvalue , reached along the top eigenvector. That direction is the first principal component. The next one, perpendicular to it, is the second.
Here and , so the eigenvalues are 18 and 4. The eigenvectors are , since , and , since . The two components carry and of the total variance.
By the SVD
You don’t need to form . Take the SVD of the data matrix itself, , from The singular value decomposition. Then , so:
- the columns of are the principal directions;
- the eigenvalues of are ;
- each point’s coordinate along direction , its score, is entry of .
For the six points, and , and , . Along , the point scores , also 4.472, and scores 2.236. Keep only the first component and each point is replaced by its shadow; the squared error left over is , as in Low-rank approximation.
Programs use the SVD route: forming squares the sensitivity to rounding, as Conditioning explains.
Two traps
The method finds the direction of most spread. It can’t find anything else, and the next picture shows two ways that matters.
Two traps
Two clouds where the principal directions mislead.
Eight points on a circle: S = 0.5714 I, the same spread in every direction, though the points lie exactly on a curve. PCA sees no direction.
Describe this picture
Two clouds side by side (stacked on a phone), drawn one after the other. On the left, eight points on a circle of radius 1, every 45°, with the covariance ellipse drawn: a circle, the same spread in every direction, although the points lie exactly on a curve; its label gives , that is . On the right, the six points of the first picture with multiplied by 10, stretched far sideways at one scale both ways, with their covariance ellipse and their first principal direction drawn almost flat, at 2.12°; the caption adds that it carries 99.7 % of the variance. There is no control.
Curves are invisible. The eight points on the ring have and , so : no direction stands out. The covariance only sees spread, not shape.
Units decide. Measure in millimetres instead of centimetres, multiplying it by 10, and the top direction swings to 2.12°, almost along , with 99.7 % of the variance. Nothing about the data changed except the units. The usual fix is to standardise first: divide each coordinate by its own spread. For the six points the standardised covariance is the correlation matrix, with correlation , and its eigenvalues are and , along and .
Where this leads · regression is different
The first principal component is not the line that best predicts from . Regression, in the probability and statistics course, makes the vertical gaps small; the principal component makes the perpendicular gaps small, treating both coordinates alike. For the same cloud they give different lines.
Worked example
1. The covariance route. Sums 76, 34 and 28; ; eigenvalues 18 and 4 along and ; shares 81.8 % and 18.2 %.
2. The SVD route. and 4.472, and and 4. The squared size of is .
3. Scores. On the first component: 4.472, 4.472 and 2.236 for , and , and the negatives for the other three.
4. Standardised. , eigenvalues 1.5508 and 0.4492.
Try these before you read the answers.
- The variance along ? 18.
- If every point lies on one line through the origin, what is the second eigenvalue? 0.
- Measure in millimetres instead of centimetres. Does the top direction change? Yes: it swings towards . Standardise first.
In signal processing · waves as principal components
For smooth signals, such as audio frames or rows of an image, the principal components come out close to the cosine waves of The discrete cosine transform, in the signal processing course. That is one reason the cosine transform compresses so well: it is nearly the best basis, without having to compute one from the data.
Where you’ll meet this
Cleaning brain recordings. An eye blink shows up on many electrodes at once, in one fixed mix. In the many-channel recording it is one strong principal direction, which can be found and removed.
Faces and genes. Pictures of faces, and the genetic data of many people, have a few principal directions that carry most of their variation; maps of human populations have been drawn from the first two.
Finance. A few principal components describe how a whole set of interest rates moves: up together, steeper or flatter.
In every case the first component is the direction of most spread, not of most meaning. The meaning is something the analyst has to supply.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Centred data | rows of | subtract the average first |
| Covariance matrix | symmetric | |
| Spread along | of length 1 | |
| Principal directions | eigenvectors of | the columns of in |
| Variances | largest first | |
| Share explained | ||
| Scores | each point’s coordinate along direction | |
| Limits | sees spread, not shape; depends on units | standardise mixed units |