What a covariance matrix does to a circle
The question
Can you tune two variances and a correlation until the cloud's match score reaches 100?
The shape is a clue. The matrix tells you how to measure it.
- 1 SeeTurn the cloud into a circle.
- 2 TryTest what the boundary means.
- 3 ProveBuild the square-root argument.
- 4 ApplyCompute axes, distances and scales.
Before you start · 3 quick checks on variance, covariance and eigenvectors
Two ideas before you start
2 ideasMeasure deviations from the center
A small point cloud and its center; translating both preserves their relative positions.
Covariance records spread around the mean. Moving every point by the same amount changes the mean but leaves covariance unchanged.
Exact definition
Let \(X=(X_1,X_2)^T\) have finite second moments and mean \(\mu=E[X]\). Its covariance matrix is
\[\begin{aligned}\Sigma&=E[(X-\mu)(X-\mu)^T]\\&=\begin{pmatrix}v_1&c\\c&v_2\end{pmatrix}.\end{aligned}\]Here \(v_i=\operatorname{Var}(X_i)\) and \(c=\operatorname{Cov}(X_1,X_2)\). When both variances are positive, \(c=\rho\sqrt{v_1v_2}\), where \(\rho\) is correlation. The lesson on covariance and correlation explains these entries. For an equally weighted finite cloud, expectation means the average over its points.
Read the matrix along a direction
A unit direction through a centered cloud; its projection has a variance.
A unit vector chooses a direction to measure. Projecting the centered cloud onto that line turns its spread into a scalar variance.
Exact definition
For a unit column vector \(q\), the scalar projection is \(q^T(X-\mu)\). Expanding its square gives
\[\operatorname{Var}(q^TX)=q^T\Sigma q.\]The variance is nonnegative in every direction. This property is called positive semidefiniteness. Because \(\operatorname{Cov}(X_1,X_2)=\operatorname{Cov}(X_2,X_1)\), the matrix is also symmetric, so every covariance matrix is symmetric positive semidefinite. A covariance is positive definite when the variance is strictly positive in every nonzero direction. The figures use equal spatial units on both coordinate axes; otherwise the apparent angle and shape would depend on the drawing scale.
Refresher: orthonormal eigenvectors
An eigenvector satisfies \(\Sigma q=\lambda q\) and is nonzero. For a real symmetric matrix, the spectral theorem supplies an orthonormal basis of eigenvectors. Put them in the columns of \(Q\). Then
\[\Sigma=Q\Lambda Q^T,\qquad Q^TQ=I.\]The diagonal matrix \(\Lambda\) lists the matching eigenvalues. The transpose \(Q^T\) finds coordinates along those perpendicular unit directions; \(Q\) converts back. Orthogonal changes of coordinates preserve lengths. For covariance matrices the eigenvalues are nonnegative, because each is the variance in its unit eigenvector direction. Equal eigenvalues allow many choices of axes.
Undo the cloud's stretch
- Adjust your proposed variances and correlation. They form a matrix B; the page uses its inverse square root to transform the cloud.
- Match the dashed covariance ellipse to the solid unit circle. Press Check this transform to see its axes, score and measured covariance.
- Reach the approximate goal, then try the other cloud. Start over clears both goals and your checked result.
Why the controls use a square root
The source cloud was built as \(x=\Sigma^{1/2}z\), from a centered cloud whose covariance is I. The displayed transform is \(y=B^{-1/2}x\). Its covariance is
\[C=B^{-1/2}\Sigma B^{-1/2}.\]When the proposed B equals the source covariance, C is I. This operation is called whitening. It removes second-moment differences between directions. A round covariance ellipse does not require every point to lie on a circle.
Write \(\Sigma=Q\Lambda Q^T\). Its symmetric positive square root is
\[\Sigma^{1/2}=Q\Lambda^{1/2}Q^T.\]It stretches each eigenvector direction by the square root of its variance. Applying this matrix to the unit circle gives semiaxes \(\sqrt{\lambda_1}\) and \(\sqrt{\lambda_2}\). Applying \(\Sigma\) itself instead gives semiaxes \(\lambda_1\) and \(\lambda_2\). So the covariance ellipse is the image of the unit circle under \(\Sigma^{1/2}\), not under \(\Sigma\).
How the score and synthetic points work
The score is \(100/(1+e)\), where \(e=\|C-I\|_F\). The Frobenius norm squares every matrix entry, adds, and takes a square root. A round ellipse of the wrong size still loses points. The goal uses \(e\le0.05\), an approximate match; the score can round to 100 without exact equality.
The synthetic points use equally spaced directions on concentric rings. Their average is zero and their covariance, with divisor n, is I before the source stretch. They are a designed cloud, not a random sample from a normal distribution. The unit circle is a geometric input boundary, not that standardized cloud: a uniform distribution on the unit circle has covariance I/2.
The controls keep both proposed variances positive and correlation strictly between −1 and 1. This guarantees that B is invertible and has a real positive square root. Center real data before whitening; otherwise a nonzero mean remains a separate issue.
What does the boundary tell you?
Now suppose X is a centered bivariate normal random vector with positive definite covariance Σ. The boundary is \(x^T\Sigma^{-1}x=1\). Predict the probability inside before opening the explanation.
Choose a probability, then enlarge the contour
The covariance describes the shape; the normal assumption supplies a density. Move k to change the boundary to \(x^T\Sigma^{-1}x=k^2\). The diagram uses a fixed diagonal covariance and the same scale on both axes.
Where the normal probability comes from
Whitening a centered bivariate normal gives independent standard normal coordinates. Their joint density is \((2\pi)^{-1}e^{-(z_1^2+z_2^2)/2}\). In polar coordinates the radius r contributes the area factor r. Integrating around the circle cancels the constant, giving
\[\begin{aligned}P(\|Z\|\le k)&=\int_0^k re^{-r^2/2}\,dr\\&=1-e^{-k^2/2},\quad k\ge0.\end{aligned}\]This calculation uses a two-dimensional normal model, not the one-coordinate rule for a normal interval. A covariance matrix by itself does not determine these probabilities. Another distribution with the same covariance can put a different fraction of its mass inside the ellipse.
When an ellipse collapses
If a covariance eigenvalue is zero, the corresponding centered projection has variance zero and is zero with probability one. The centered vector \(X-\mu\) is then confined to a line through the origin, or to the origin itself. The ellipse collapses too: if \(\lambda_1\gt0=\lambda_2\), the square root \(\Sigma^{1/2}=\sqrt{\lambda_1}\,q_1q_1^T\) maps the unit circle onto the segment from \(-\sqrt{\lambda_1}\,q_1\) to \(\sqrt{\lambda_1}\,q_1\), and if \(\Sigma=0\) it maps the circle to the origin. The equation \(x^T\Sigma^{-1}x=1\) no longer applies, because \(\Sigma^{-1}\) does not exist. No linear map can turn that collapsed covariance into I.
If both eigenvalues are equal and positive, the covariance ellipse is a circle and no principal direction is singled out. If the off-diagonal covariance is zero but the diagonal variances differ, the ellipse is axis-aligned but not circular. Correlation describes coupling; it does not set the whole shape.
Derive the square-root stretch
Let Σ be a real symmetric positive definite matrix in the plane, with orthonormal eigenvectors \(q_1,q_2\) and eigenvalues \(\lambda_1,\lambda_2\). Let Z have mean zero, finite second moments and covariance I. Define \(A=Q\Lambda^{1/2}Q^T\), taking positive scalar square roots. Then X = AZ has covariance Σ.
The image of the unit circle under A is \(x^T\Sigma^{-1}x=1\). Its semiaxes lie along the eigenvectors and have lengths \(\sqrt{\lambda_i}\). Conversely, \(W=A^{-1}\) whitens X. No normal-distribution assumption is used in this theorem.
For the builder, u is any unit vector. The covariance transformation rule follows by expanding \(E[(AZ)(AZ)^T]\): fixed matrices can be pulled outside expectation, so \(\operatorname{Cov}(AZ)=A\operatorname{Cov}(Z)A^T\).
Read the equation in principal coordinates
Set \(t=Q^Tx\). Orthogonality turns the boundary equation into
\[\frac{t_1^2}{\lambda_1}+\frac{t_2^2}{\lambda_2}=1.\]Setting either coordinate to zero gives the intercepts on the other principal axis. This proves the semiaxis lengths without treating the matrix entries as lengths. The diagonal entries are variances along the original coordinate axes; they need not be eigenvalues.
For a nonzero mean μ, replace x by x − μ throughout. The ellipse moves without changing its axes or lengths. A different covariance factor L with \(LL^T=\Sigma\), such as the lower-triangular Cholesky factor, also produces covariance Σ from Z. It maps the unit circle onto the same ellipse: if \(x=Lz\), then \(x^T\Sigma^{-1}x=z^TL^T(LL^T)^{-1}Lz=z^Tz\). Only the point that each \(z\) lands on changes. The symmetric square root is convenient, but it is not the only factor with these properties.
Read a matrix as a shape
Use what you found above. Enter a decimal without units. Each problem accepts the stated tolerance around its unrounded answer. Keep intermediate values unrounded; hints and worked solutions are available after you act.
Further reading
- R. A. Johnson and D. W. Wichern, Applied Multivariate Statistical Analysis, chapter 4, The Multivariate Normal Distribution.
- G. Strang, Introduction to Linear Algebra, chapter 6, Eigenvalues and Eigenvectors.