A.4 Decompositions and positive definiteness: Cholesky, eigenvalues and condition numbers
What you will learn
- Factor a covariance matrix with the Cholesky decomposition, and use the factor to draw correlated random numbers and to keep estimates admissible.
- Move between a covariance matrix, its correlations, its SDs and its CVs.
- Read a condition number of a correlation matrix, and see how a robust Cholesky repairs a matrix that is almost positive semi-definite.
Prerequisites: A.2.
The Cholesky decomposition
A symmetric positive definite matrix \(S\) has a unique factorisation
Three uses account for most of its appearances in nlmx.
| Use | How |
|---|---|
| Drawing \(x\sim N(0,S)\) | \(x=Lz\) with \(z\sim N(0,I)\); then \(\operatorname{Cov}(x)=LL^{\mathsf T}=S\) (page A.14) |
| Estimating a covariance | optimise the elements of \(L\), with the diagonal on the log scale; \(LL^{\mathsf T}\) is then positive definite whatever the optimiser does (page A.9) |
| Whitening | \(L^{-1}(x)\) has identity covariance; weighted residuals divide by such a factor |
The determinant is a by-product: \(\lvert S\rvert=\bigl(\prod_kL_{kk}\bigr)^2\), so \(\log\lvert S\rvert=2\sum_k\log L_{kk}\).
A worked illustration
A two-ETA covariance matrix. Let
Its Cholesky factor is built row by row. \(L_{11}=\sqrt{0.09}=0.3\); \(L_{21}=0.03/0.3=0.1\); \(L_{22}=\sqrt{0.04-0.1^2}=\sqrt{0.03}=0.17321\). So
| Quantity | Value |
|---|---|
| SDs | \(0.30\) and \(0.20\) |
| correlation | \(0.03/(0.30\times0.20)=0.50\) |
| CVs (log-normal) | \(100\sqrt{e^{0.09}-1}=30.7\,\%\) and \(100\sqrt{e^{0.04}-1}=20.2\,\%\) |
| \(\log\lvert\Omega\rvert\) | \(2(\log0.3+\log0.17321)=\log(0.0027)=-5.915\) |
A draw with \(z=(1,\,-1)^{\mathsf T}\) is \(\eta=Lz=(0.30,\ 0.1-0.17321)=(0.30,\ -0.0732)\): the first ETA is one SD above its mean and the second is pulled down by the independent part of its draw, in spite of the positive correlation.
Correlation, covariance and the delta from variance to CV
The CV formula comes from the log-normal variance: if \(\eta\sim N(0,\omega^2)\), then \(P=\theta e^{\eta}\) has \(\operatorname{Var}(P)/\mathbb E(P)^2=e^{\omega^2}-1\). For small \(\omega^2\), \(\mathrm{CV}\approx100\,\omega\).
Eigenvalues and the condition number
A symmetric \(A\) has real eigenvalues \(\lambda_1\ge\dots\ge\lambda_p\); it is positive definite exactly when all are positive. The condition number is \(\kappa=\lambda_{\max}/\lambda_{\min}\). nlmx reports it for the correlation matrix of the estimates and flags a value above 1000; a very large value means some combination of parameters is barely determined by the data.
For a \(2\times2\) correlation matrix with off-diagonal \(r\), the eigenvalues are \(1\pm r\) and so \(\kappa=(1+r)/(1-r)\):
| \(r\) | 0.5 | 0.9 | 0.95 | 0.99 |
|---|---|---|---|---|
| \(\kappa\) | 3 | 19 | 39 | 199 |
Pairs of estimates with \(\lvert r\rvert>0.95\) are listed separately by the program. With more parameters the matrix can be ill-conditioned without any single pair being highly correlated, which is why the condition number is reported as well as the pairs.
Matrices that are not positive definite
Three situations produce a matrix that is not positive definite:
| Cause | Typical sign |
|---|---|
| a variance at a boundary (an ETA that the data cannot support) | a variance shrinks toward zero; a correlation near \(\pm1\) |
| numerical noise in an estimated or differenced matrix | a small negative eigenvalue |
| inconsistent user input (a correlation larger than 1 in magnitude) | the matrix cannot be a covariance at all |
For random-number generation, nlmx uses a robust Cholesky: if \(S\) is not positive semi-definite, it is projected onto the positive semi-definite cone through its eigen-decomposition (negative eigenvalues set to zero), and the relative size of the repair is returned. A repair below \(10^{-8}\) is accepted silently as rounding; a larger one is refused for the model's own matrices ("not positive semidefinite"), while for the covariance of parameter uncertainty a larger repair is allowed and reported as a note with its largest change.
Worked illustration of a repair. Take \(S=\begin{pmatrix}0.04&0.06\\0.06&0.04\end{pmatrix}\), whose "correlation" \(0.06/0.04=1.5\) is impossible. Its eigenvalues are \(0.10\) (eigenvector \((1,1)/\sqrt2\)) and \(-0.02\) (eigenvector \((1,-1)/\sqrt2\)). Setting the negative one to zero gives
a perfectly correlated, singular matrix that differs from \(S\) by \(+0.01\) on the diagonal and \(-0.01\) off it. That is a large repair relative to the entries, and it would be refused for a model matrix; the program's message is the sign that the inputs, not the arithmetic, are wrong.
Common mistakes
- Reading an off-diagonal as a correlation when it is a covariance.
- Treating a correlation of 0.99 as "high but fine": the estimates are then nearly redundant (page A.12).
- Repairing a non-positive-definite matrix silently. A repair is information about the model or the data; the program reports it.
Review checklist
- Can you compute a Cholesky factor of a \(2\times2\) covariance by hand and recover the matrix?
- Can you convert between a covariance, a correlation, an SD and a CV?
- Do you know what a condition number above 1000 says about a covariance step?
Navigation
See the previous page, the next page and the mathematical reference.