Eigenvectors and PCA: Explained Visually

Rotate a line until the spread along it is greatest, watch the perpendicular error fall by the same amount, and see that the direction you found is the top eigenvector of the covariance matrix.

At a glance

Answer
PC1 maximizes projected variance and minimizes perpendicular reconstruction error.
Because
The two spreads sum to the covariance trace, and PC1 is its top eigenvector.
Common error
Treating PCA as regression, or assuming an eigenvector's sign changes the solution.
Not for
Computing a full PCA decomposition on pasted data. Principal Component Analysis

Runs in your browser. Every figure computes live from the numbers shown and accepts no pasted data.

Rotate the line

Rotate the line through the centroid until the points spread out along it as much as they can. Watch both readouts as you go.

Projection and perpendicular residuals through the centroid

Spread along the line
6.181818
Spread away from the line
5.000000
Total
11.181818 constant
Sum squared along
68.000000
Sum squared away
55.000000
Total squared deviations
123.000000 constant
Direction
0.00 degrees

Sum squared along the line plus sum squared away from it is 123.000000 for this built-in cloud, whatever direction you choose.

Projection and perpendicular residuals through the centroid

Spread along the line
9.904304
Spread away from the line
1.277515
Total
11.181818 constant
Sum squared along
108.947339
Sum squared away
14.052661
Total squared deviations
123.000000 constant
Direction
41.06 degrees

That is the maximal direction, at 41.06 degrees.

These published figures and readouts are complete without JavaScript.

That line is an eigenvector

Drag v until Av points along the same line as v. Two directions work, and one of them is the line you already found.

A vector and its image under the current matrix

Classification
two distinct real eigenvalues
v
(1.000000, 0.000000)
Av
(6.181818, 4.272727)
Length of Av
7.514724
Alignment signal
34.3%

The covariance matrix is symmetric, so its eigenvectors are at right angles and reconstruct it as V diag(lambda) V transpose.

Two directions, ranked

Line up both axes at once. You are looking for the angle where covariance between the two projected coordinates reaches zero.

Two orthogonal directions and their variance shares

Variance along axis 1
6.181818
Variance along axis 2
5.000000
Covariance between projected coordinates
4.272727

At 41.063 degrees the variances are 9.904304 and 1.277515 and their cross covariance is zero. Normalizing those eigenvalues gives the explained-variance shares.

The sign of a component

If v is an eigenvector then the vector pointing the other way is too. The calculator makes each component's largest-magnitude entry positive and lets you flip it deliberately.

See the sign convention this affects.

Now do it with real data

Turn foods on and off and watch which countries separate. Every variable is grams per person per week, so covariance is the starting basis.

Basis

PC2 against PC1

−300−200−1000100200−400−2000200EnglandWalesScotlandNorthern Ireland
Foods in the analysis
17
Components available
min(4 - 1, 17) = 3
PC1 variance
67.4%
Ranked eigenvector coefficients
FoodCoefficient on PC1
Fresh fruit0.6326409
Alcoholic drinks0.4639682
Fresh potatoes-0.4014021
Other meat0.2589167
Other Veg0.2435937
Soft drinks-0.2322441
Fresh Veg0.1518499
Fish0.0844150
Cheese0.0569554
Carcass meat-0.0479276
Cereals0.0477029
Sugars0.0376210
Processed Veg0.0364883
Confectionery0.0296502
Processed potatoes0.0268862
Beverages0.0261878
Fats and oils0.0051936

Multiply a coefficient by the square root of its eigenvalue and you get the loading, which is what the calculator prints beside this column.

Northern Ireland sits alone at one end of PC1. Fresh fruit, alcoholic drinks and fresh potatoes carry the largest coefficients.

Compute this on your own data.

When PCA does not work

Move the sample size and watch which of these four problems more observations fix.

60 observations

One control, four panels. They all redraw together.

A condition PCA does not repair

−300−200−1000100200300−2−1012
Scenario
unstandardized
Observations
60
PC1 variance
100.0%

A condition PCA does not repair

−101−2−10123
Scenario
near-tie
Observations
60
PC1 variance
56.3%

A condition PCA does not repair

−3−2−1012−4−2024
Scenario
n-less-than-p
Observations
60
PC1 variance
21.7%
Components available
min(60 - 1, 6) = 6

A condition PCA does not repair

−1.0−0.50.00.51.0−1012
Scenario
nonlinear
Observations
60
PC1 variance
57.1%

What a calculator should warn you about.

What PCA is and is not for

Regression predicts a response and measures vertical error. PCA has no response and measures perpendicular error. Factor analysis and nonlinear embeddings ask different questions.

This page takes no data. Nothing here has a paste box, because every figure exists to make one idea move. When you have your own table, the PCA calculator runs the decomposition and names every convention it used.

Export

Sources

  1. Jolliffe and Cadima (2016), Principal component analysis: a review and recent developments. Philosophical Transactions of the Royal Society A. Retrieved .
  2. Fisher (1936), The use of multiple measurements in taxonomic problems. Annals of Eugenics. Retrieved .
  3. UK food-consumption teaching table provenance note. Setosa lineage; widely republished teaching table, primary source unestablished. Retrieved .