PCA: Find the Shadow

Move the light until the data cast their widest shadow

Game instructions

The points form an object in three dimensions. A distant light source sends parallel rays through the object onto a screen.

Move the light around the object. Find the shadow that preserves as much variation as possible, then lock your answer.

After the reveal, PCA shows its own projection, PC1 and PC2, and their component coefficients. The explanation below the game shows how those coefficients determine where a shadow lands.

1 Object
-- Points
0 Completed shadows
-- Average score
Shadow laboratory
X1, X2 and X3 are the original variables.
Projection screen
PCA screen
Light rays
PC1
PC2
Shadow on the screen
Darker regions contain overlapping projected points.
Judge the shadow visually before locking your answer.

Move the sun

0°180°359°
-90°0°90°
Find the angle where the shadow appears to preserve the largest spread of the original 3D object.

PCA reveal

Shadow efficiency --
Plane error --
PC1 · PC2 --

Component directions

Variable PC1 PC2
X1 -- --
X2 -- --
X3 -- --

These are unit direction-vector coefficients. Larger absolute values mean the component points more strongly along that original axis. Reversing every sign gives the same PCA axis.

How does PCA make the shadow?

Start with one ordinary shadow. No PCA yet. Once that geometry is clear, PCA is mostly the same calculation repeated for many points while choosing the direction that makes their shadows spread out.

1. One point, one shadow

Put one point at P = (3, 4). Now cast its shadow onto a line tilted 30° above the X axis. The question is simply: where on that line does the shadow land?

Point P = (3, 4)
Projection angle θ = 30°
Direction = (cos 30°, sin 30°)
= (0.866, 0.500)

2. Cosine gives the shadow length

A shadow keeps only the part of the point that points along the chosen direction. In coordinates, add the X part and the Y part that point along the tilted line.

shadow position z
= 3 cos 30° + 4 sin 30°
= 3(0.866) + 4(0.500)
= 4.60
The number 4.60 is not an abstract statistic. It is the signed distance from the centre to the shadow on the line.

3. PCA asks which angle gives the widest shadows

With many centred points, every possible angle gives a different set of shadow positions. PCA chooses the angle for which those positions have the largest variance.

From the centred points:
sₓ² = Σx²/(n-1) = 3.25
sᵧ² = Σy²/(n-1) = 1.75
sₓᵧ = Σxy/(n-1) = 1.30

θ = ½ atan2(2sₓᵧ, sₓ² - sᵧ²)
θ = 30°

4. The PCA coefficients tell us where the axis points

Once PCA has found θ, the PC1 direction is just a unit arrow. Its coefficients are the trigonometric parts of that arrow along the original axes.

PC1 = (cos θ, sin θ)
= (cos 30°, sin 30°)
= (0.866, 0.500)

score = 0.866x + 0.500y
A large coefficient means that PC1 points strongly along that original variable. A coefficient near zero means it points very little along it.

5. Three dimensions use exactly the same idea

In the game a point has three centred coordinates. PC1 is a unit direction (a, b, c), so its three coefficients are direction cosines with X1, X2 and X3.

x = (3, 1, 2)
PC1 = (0.667, 0.667, 0.333)
PC1 score = 3(0.667) + 1(0.667)
+ 2(0.333) = 3.33

6. Two scores tell us where the 2D shadow lands

Repeat the same projection onto PC2. Those two signed shadow lengths become the coordinates on the PCA screen.

PC1 score = +3.33
PC2 score = -1.41

position on PCA screen
= (PC1 score, PC2 score)
= (3.33, -1.41)
The familiar PCA plot is simply all observations placed at their own pair of PC1 and PC2 shadow coordinates.
PCA is a carefully chosen shadow. The data determine the best direction. The component coefficients tell us which way the new axes point. The component scores tell us where each observation's shadow lands on those axes.