Any two variables with finite variances have a covariance matrix, and that matrix has a shape you can see. Set the standard deviations and and the correlation , and the cloud of points, the ellipses and the principal axes move with them.
- Sample points
- Mahalanobis distance 1
- Mahalanobis distance 2
- First principal axis
- Second principal axis
Covariance matrix
Covariance matrix with first row 2.25 and 0.90, and second row 0.90 and 1.00
Variances on the diagonal, covariance off it
- Largest eigenvalue λ1
- 2.72
- Smallest eigenvalue λ2
- 0.53
- First component share λ1 / tr Σ
- 83.7%
- Correlation ρ
- 0.60
- Total variance tr Σ
- 3.25
- Generalized variance det Σ
- 1.44
The eigenvalues are equal, so both ellipses are circles and every direction through the center is a principal axis.
The points are one fixed random sample. Every setting reuses the same draws, so you can follow a single point as the cloud stretches and turns.
Things to try
- Set and , or press Circle. Both ellipses become circles, , and every direction through the center is a principal axis.
- Keep , set below and slide it up past . The first principal axis switches from vertical to horizontal. With no correlation the principal axes are the coordinate axes, and the first one follows the larger variance.
- Push toward . The total variance does not move, but shrinks toward and the cloud flattens toward a line.
- Make and equal and try any nonzero . The first axis sits at exactly when is positive and when it is negative, and the eigenvalues are and .
- Flip the sign of . The ellipses and the principal axes reflect across the horizontal axis, while the eigenvalues, the trace and the determinant stay exactly the same.
- Pick a point just inside the inner ellipse and move any slider. It never crosses the ellipse, because each point keeps the same Mahalanobis distance however changes. The next section shows why.
What you are seeing
With these parameters the covariance matrix is
It is positive definite because . Its eigenvalues come with orthonormal eigenvectors and , which give the spectral decomposition
For a matrix the eigenvalues have a closed form.
Their sum is the total variance and their product is the generalized variance.
The share is the proportion of the total variance along the first principal component.
The ellipses are the points at Mahalanobis distance from the mean , with for the inner one and for the outer one.
Each ellipse has its axes along and , with half lengths and . The two colored segments are these axes for .
Each sample point starts as a pair of independent standard normal values, drawn once. The plot shows , where is the Cholesky factor of .
That makes a draw from , and for every setting its squared distance is
Under this model has a distribution, so
That is about inside the inner ellipse and inside the outer one. The 240 points here are one random draw, so their shares come out near those values but not exactly on them.
The multivariate statistics reference has the notation and the main results in one place, and the linear algebra refresher goes over eigenvalues and quadratic forms. The videos are on the Multivariate Statistical Analysis course page.