A.2 Vectors, matrices and the identities the program relies on
What you will learn
- Use the rules for transposes, products, traces and determinants that the estimation chapters assume.
- Apply the Woodbury identity and the matrix determinant lemma, and see why they make a subject with many observations cost the same as one with few.
- Check both identities on a three-observation example.
Prerequisites: A.1.
The rules in one table
For conformable matrices \(A,B,C\) and a scalar \(c\):
| Rule | Statement |
|---|---|
| Transpose of a product | \((AB)^{\mathsf T}=B^{\mathsf T}A^{\mathsf T}\) |
| Inverse of a product | \((AB)^{-1}=B^{-1}A^{-1}\) (both square and invertible) |
| Trace is cyclic | \(\operatorname{tr}(ABC)=\operatorname{tr}(BCA)=\operatorname{tr}(CAB)\) |
| Trace of a quadratic form | \(x^{\mathsf T}Ax=\operatorname{tr}(Axx^{\mathsf T})\) |
| Determinant of a product | \(\lvert AB\rvert=\lvert A\rvert\lvert B\rvert\) |
| Determinant and scale | \(\lvert cA\rvert=c^{n}\lvert A\rvert\) for an \(n\times n\) matrix |
| Determinant of the inverse | \(\lvert A^{-1}\rvert=1/\lvert A\rvert\) |
| Determinant from eigenvalues | \(\lvert A\rvert=\prod_k\lambda_k\) and \(\operatorname{tr}A=\sum_k\lambda_k\) |
| Block determinant | \(\begin{vmatrix}A&B\\0&D\end{vmatrix}=\lvert A\rvert\lvert D\rvert\) |
A symmetric matrix \(A\) is positive definite if \(x^{\mathsf T}Ax>0\) for every \(x\neq0\); then all eigenvalues are positive, the determinant is positive and the inverse is positive definite too. A covariance matrix is positive semi-definite, and positive definite unless a variable is exactly redundant or has zero variance (page A.4).
Why a subject's calculation must stay small
A subject with \(n_i\) observations and \(p\) random effects has a marginal covariance of the observations
an \(n_i\times n_i\) matrix (\(G_i\) is \(n_i\times p\), \(\Omega\) is \(p\times p\), \(R_i\) is diagonal). Its inverse and determinant are needed at every evaluation of the objective, for every subject, at every step of the optimiser. Inverting an \(n_i\times n_i\) matrix costs about \(n_i^{3}\) operations. But \(p\) is small (two to six, usually) and \(n_i\) may be dozens. Two identities turn the large problem into a small one.
The Woodbury identity
For invertible \(R\) and \(\Omega\),
Since \(R\) is diagonal, \(R^{-1}\) is free, and the only matrix inverted is the \(p\times p\) matrix \(\Omega^{-1}+G^{\mathsf T}R^{-1}G\). In the single-ETA case the inverse is a division.
The matrix determinant lemma
With the same matrices,
The determinant of the large matrix is the product of a diagonal determinant (a product of \(n_i\) numbers), the determinant of \(\Omega\) and the determinant of the same \(p\times p\) matrix that the Woodbury identity inverts. The linearised objective of a subject (page A.8),
is therefore computed with \(p\times p\) operations only. The quadratic form needs a little more care; with \(A=\Omega^{-1}+G^{\mathsf T}R^{-1}G\),
which in the one-ETA case is \(\sum_j r_j^2/V_j-\bigl(\sum_j g_jr_j/V_j\bigr)^2/A\).
A worked illustration
Three observations, one ETA. Let \(G=(1,\ 0.8,\ 0.5)^{\mathsf T}\), \(\Omega=0.09\) and \(R=\operatorname{diag}(0.04,0.04,0.04)\). Then
The determinant by the lemma. The scalar \(A=\Omega^{-1}+G^{\mathsf T}R^{-1}G=11.1111+25(1+0.64+0.25)=58.3611\). Then
A direct \(3\times3\) determinant gives the same value, \(3.3616\times10^{-4}\).
The quadratic form. For a residual vector \(r=(0.5,\ 0.2,\ -0.1)^{\mathsf T}\):
| Quantity | Value |
|---|---|
| \(r^{\mathsf T}R^{-1}r\) | \(25(0.25+0.04+0.01)=7.5000\) |
| \(G^{\mathsf T}R^{-1}r\) | \(25(0.5+0.16-0.05)=15.2500\) |
| \(\bigl(G^{\mathsf T}R^{-1}r\bigr)^2/A\) | \(232.5625/58.3611=3.9849\) |
| \(r^{\mathsf T}C^{-1}r\) | \(7.5000-3.9849=3.5151\) |
A direct solve of \(Cx=r\) gives \(r^{\mathsf T}C^{-1}r=3.5151\) as well, and the linearised objective of this toy subject is
Both identities were recomputed with independent arithmetic and agree to the printed digits (the inverse by the Woodbury identity differs from the direct inverse by about \(4\times10^{-15}\)).
When the identities do not apply
- A non-diagonal \(R\) would make \(R^{-1}\) a matrix inverse again; the identities still hold but the saving is smaller. (In the models of this book \(R_i\) is diagonal.)
- A singular \(\Omega\) (a variance fixed at zero) has no inverse; the ETA is then not part of the active set, and \(p\) counts only the active ETAs.
- A very small \(R\) makes \(G^{\mathsf T}R^{-1}G\) large, and the subtraction in the quadratic form can lose digits: a reason why identities are checked numerically (page A.18) and not only algebraically.
Review checklist
- Can you state the Woodbury identity and say which matrix is inverted?
- Can you explain why a subject with 40 observations costs no more than one with 4 observations in the number of matrix inversions?
- Do you know that the determinant lemma is what makes the log-determinant cheap?
Navigation
See the previous page, the next page and the mathematical reference.