Positive semidefinite matrices: when correlations cannot coexist
The question
X₂ and X₃ each have correlation 0.9 with X₁. Can the correlation between X₂ and X₃ be 0.1?
Move three correlations yourself; the page checks whether any random variables could have them.
- 1 SeePush three correlations to their limit.
- 2 TryPredict which combinations break the matrix.
- 3 ProveBuild the proof, line by line.
- 4 ApplyProblems to check yourself.
Before you start · 3 quick checks on the variance of a combination, a quadratic form and an eigenvector, about 3 min
Two ideas before you start
2 ideasTwo variables: a variance cannot go below 0
Figure: the variance of X₁ + tX₂ as a parabola in t, dashed, for the chosen correlation ρ. It needs JavaScript.
Var(X₁ + tX₂) = 1 + 0.6t + t²
lowest value 1 − ρ² = 0.91 at t = −0.3
For two variables with variance 1 and correlation ρ, the variance of X₁ + tX₂ is a parabola in t. Its lowest value is 1 − ρ², so it stays at or above 0 exactly when ρ is between −1 and 1. At ρ = 1 it touches 0.
Exact definition
Three standardized variables. Throughout, \(X_1\), \(X_2\), \(X_3\) are random variables with variance 1 each. Their correlations are \(\rho_{ij} = \operatorname{Cov}(X_i, X_j)\) for \(i \ne j\), with \(\rho_{ij} = \rho_{ji}\), and their correlation matrix is
\[R = \begin{pmatrix} 1 & \rho_{12} & \rho_{13} \\ \rho_{12} & 1 & \rho_{23} \\ \rho_{13} & \rho_{23} & 1 \end{pmatrix}.\]Two at a time. For every number \(t\),
\[\begin{aligned} &\operatorname{Var}(X_1 + tX_2) \\ &= 1 + 2\rho_{12}t + t^2 \\ &= (t + \rho_{12})^2 + 1 - \rho_{12}^2. \end{aligned}\]A variance is never negative, so \(1 - \rho_{12}^2 \ge 0\): every single correlation lies between \(-1\) and \(1\), as in the lesson on covariance and correlation. Conversely, any one number from \(-1\) to \(1\) is the correlation of some pair of variables.
Three variables: one matrix gives every variance
Figure: a 3 by 3 grid of the products of the weights and the correlations, for the matrix with ρ₁₂ = 0.3, ρ₁₃ = −0.4 and ρ₂₃ = 0.2. It needs JavaScript.
w = (1, 1, 0): wᵀRw = sum of the nine cells = 2.6
With weights w₁, w₂, w₃, the variance of w₁X₁ + w₂X₂ + w₃X₃ adds the nine cells of the grid, each a weight times a weight times their correlation: it is the quadratic form wᵀRw. Three numbers can be correlations only if this is never negative.
Exact definition
The variance of a combination. For weights \(w = (w_1, w_2, w_3)\), the rule for the variance of a sum gives
\[\begin{aligned} &\operatorname{Var}(w_1X_1 + w_2X_2 + w_3X_3) \\ &= \sum_i \sum_j w_iw_j\rho_{ij} = w^\mathsf{T}Rw, \end{aligned}\]with \(\rho_{ii} = 1\). This is the quadratic form of \(R\), as in the lesson on quadratic forms.
Positive semidefinite. A symmetric matrix \(A\) is positive semidefinite when \(w^\mathsf{T}Aw \ge 0\) for every vector \(w\), and positive definite when \(w^\mathsf{T}Aw \gt 0\) for every \(w \ne 0\). Equivalently, every eigenvalue of \(A\) is at least 0 (positive, for definite), because over vectors of length 1 the form runs from the smallest eigenvalue \(\lambda_{\min}\) to the largest.
Valid correlation matrices. A symmetric matrix with 1s on the diagonal is the correlation matrix of some random variables exactly when it is positive semidefinite. Every correlation matrix is, because \(w^\mathsf{T}Rw\) is a variance; the fine print below shows that every such matrix occurs.
Fine print: covariances, square roots and names
Covariance matrices. If \(X_i\) has standard deviation \(\sigma_i \gt 0\), the covariance matrix is \(\Sigma = DRD\) with \(D\) the diagonal matrix of the \(\sigma_i\), and \(w^\mathsf{T}\Sigma w = (Dw)^\mathsf{T}R(Dw)\). So \(\Sigma\) is positive semidefinite exactly when \(R\) is, and \(\det\Sigma = \sigma_1^2\sigma_2^2\sigma_3^2\det R\) has the sign of \(\det R\).
Every valid matrix occurs. For a positive semidefinite \(R\) with 1s on the diagonal, write \(R = Q\Lambda Q^\mathsf{T}\) with \(Q\) orthogonal and \(\Lambda\) the diagonal matrix of eigenvalues (the spectral theorem of the lesson on symmetric matrices), and let \(B = Q\Lambda^{1/2}Q^\mathsf{T}\), the square root \(R^{1/2}\) of the lesson on the covariance ellipse. If \(Z\) has three independent standard normal entries, \(X = BZ\) has covariance matrix \(BB^\mathsf{T} = R\), a normal vector as in the lesson on the multivariate normal.
The ellipsoid. The ellipsoid of \(R\) in stage 1 is the set of points \(R^{1/2}s\) for vectors \(s\) of length at most 1. Its half-widths along the eigenvectors are \(\sqrt{\lambda_1}\), \(\sqrt{\lambda_2}\), \(\sqrt{\lambda_3}\), so it is flat when \(\lambda_{\min} = 0\) and does not exist when \(\lambda_{\min} \lt 0\).
Names. The set of all valid triples \((\rho_{12}, \rho_{13}, \rho_{23})\) is a convex solid inside the cube \([-1, 1]^3\), sometimes called the elliptope.
Push the correlations to the edge
- Move the sliders for the correlations ρ₁₂, ρ₁₃ and ρ₂₃. Locked sliders are part of the round. The ellipsoid of R, its eigenvalues and the tiles follow.
- Each round names a target. When you think you have it, press Check my matrix; the page says whether any random variables could have these correlations.
How the game works
Each correlation moves in steps of 0.01 from \(-1\) to 1. The tiles show the smallest eigenvalue \(\lambda_{\min}\) of \(R\) and \(\det R\) for the current values; a value written with ≈ is rounded, one without is exact. Check my matrix judges by the exact determinant: with every correlation between \(-1\) and 1, \(R\) is valid exactly when \(\det R \ge 0\), and stage 3 shows why.
There are three rounds. You can check as often as you like, and a round ends when its target is reached. After round 3 a table lists your matrices. Start over clears everything.
| Round | Target | Your ρ₁₂, ρ₁₃, ρ₂₃ | λmin | Checks |
|---|
Combinations that would break
A prediction and a quick guess. The explorer below them opens once both are answered.
A matrix that cannot occur
The explorer opens once both questions above are answered.
Explorer: weights and their variance
Pick a matrix and set three weights. The table shows the nine products \(w_iw_j\rho_{ij}\); they add up to \(w^\mathsf{T}Rw\), the variance that \(w_1X_1 + w_2X_2 + w_3X_3\) would have.
| Row | w₁ | w₂ | w₃ |
|---|
Goals
Never negative, for every choice of weights. \(R\) is a correlation matrix only if \(w^\mathsf{T}Rw \ge 0\) for every \(w\). Scaling \(w\) by a number \(k\) multiplies \(w^\mathsf{T}Rw\) by \(k^2\), so the sign depends only on the direction of \(w\).
The smallest eigenvalue is the smallest variance. Over weights of length 1, \(w^\mathsf{T}Rw\) runs from \(\lambda_{\min}\) to \(\lambda_{\max}\), and it equals \(\lambda_{\min}\) along an eigenvector of \(\lambda_{\min}\). So a negative \(\lambda_{\min}\) gives a direction with a negative variance, and \(\lambda_{\min} \ge 0\) rules every such direction out.
Zero at the edge. If \(R\) is valid and \(w^\mathsf{T}Rw = 0\) for some \(w \ne 0\), the combination \(w_1X_1 + w_2X_2 + w_3X_3\) has variance 0, so it equals its mean with probability 1: the three variables satisfy a linear relation. For a valid \(R\) this happens exactly when \(\lambda_{\min} = 0\).
Why a negative determinant rules a matrix out
Assumptions. Numbers \(a\), \(b\), \(c\) with \(-1 \lt a \lt 1\), \(-1 \le b \le 1\) and \(-1 \le c \le 1\), and the matrix \(R\) with rows \((1, a, b)\), \((a, 1, c)\) and \((b, c, 1)\), whose determinant
\[\begin{aligned} \det R &= 1 + 2abc \\ &\quad {} - a^2 - b^2 - c^2 \end{aligned}\]is negative. In the stages, \(a = \rho_{12}\), \(b = \rho_{13}\) and \(c = \rho_{23}\).
Conclusion. Some weights \(w \ne (0, 0, 0)\), written directly in terms of \(a\), \(b\) and \(c\), give \(w^\mathsf{T}Rw \lt 0\). So no random variables \(X_1\), \(X_2\), \(X_3\) with variance 1 have the correlations \(\rho_{12} = a\), \(\rho_{13} = b\), \(\rho_{23} = c\): the combination \(w_1X_1 + w_2X_2 + w_3X_3\) would have a negative variance.
Facts the proof uses.
- ordinary algebra of real numbers;
- for random variables with variance 1 and these correlations, the variance of \(w_1X_1 + w_2X_2 + w_3X_3\) is \(w^\mathsf{T}Rw\) (the second idea on the Start tab), and a variance is never negative;
- \(w^\mathsf{T}Rw = w \cdot Rw\), and the \(k\)-th entry \((Rw)_k\) of \(Rw\) is row \(k\) of \(R\) times \(w\);
- a positive number times a negative number is negative.
Each option is one step about the numbers \(a\), \(b\), \(c\) of the theorem. Pick the one that is true for every \(a\), \(b\), \(c\) the theorem allows.
- The converse. If \(-1 \lt a \lt 1\) and \(\det R \ge 0\), then \(R\) is positive semidefinite. Completing the square twice gives, for every \(w\), \[\begin{aligned} w^\mathsf{T}Rw &= (w_1 + aw_2 + bw_3)^2 \\ &\quad {} + (1 - a^2)\bigl(w_2 + tw_3\bigr)^2 \\ &\quad {} + \frac{\det R}{1 - a^2}\,w_3^2 \end{aligned}\] with \(t = (c - ab)/(1 - a^2)\), and no term is negative. So when every correlation lies between \(-1\) and 1 and \(\rho_{12}\) lies strictly between, three numbers are correlations exactly when \(\det R \ge 0\).
- The range of the third correlation. \(\det R\) equals \((1 - a^2)(1 - b^2) - (c - ab)^2\), so \(\det R \ge 0\) exactly when \[\begin{aligned} &\lvert c - ab\rvert \\ &\le \sqrt{(1 - a^2)(1 - b^2)}. \end{aligned}\] For \(a = b = 0.9\) this is \(0.81 \pm 0.19\), from 0.62 to 1, as in round 1 of stage 1; for \(a = -0.6\) and \(b = -0.8\) it is \(0.48 \pm 0.48\), from 0 to 0.96.
- When \(a = \pm 1\). The proof needs one correlation strictly between \(-1\) and 1; renumbering the variables puts it in the place of \(a\). If all three are \(\pm 1\), then \(X_2 = \rho_{12}X_1\) and \(X_3 = \rho_{13}X_1\) up to constants, so \(\rho_{23} = \rho_{12}\rho_{13}\).
- Sample matrices. A correlation matrix computed from one complete data set is always positive semidefinite: \(w^\mathsf{T}Rw\) is then the sample variance of a combination of the standardized columns, the squared length of a vector \(Xw\) divided by the number of rows, as for the matrices \(X^\mathsf{T}X\) of the lesson on projection onto a subspace. Invalid matrices come from correlations estimated pair by pair, over different periods or with missing data, or set by hand.
- More variables. For \(n\) variables the test is the same in eigenvalues: \(R\) is valid exactly when \(\lambda_{\min} \ge 0\). In determinants it needs every principal minor, the determinant of the rows and columns of any set of indices, to be at least 0; for a general symmetric matrix the leading ones are not enough, since the matrix with rows \((0, 0)\) and \((0, -1)\) has leading minors 0 and 0 but is not positive semidefinite.
Problems
Each problem has hints and a full solution.
Further reading
- G. Strang, Linear Algebra and Learning from Data (Wellesley-Cambridge Press, 2019), part I, section 7, "Symmetric Positive Definite Matrices."
- R. A. Horn and C. R. Johnson, Matrix Analysis, 2nd ed. (Cambridge University Press, 2013), chapter 7, "Positive definite and semidefinite matrices."
- N. J. Higham, "Computing the nearest correlation matrix: a problem from finance," IMA Journal of Numerical Analysis 22 (2002), on repairing invalid correlation matrices.