Common quadratic forms
Usage
xTAx(x, A)
xAxT(x, A)
xTAx_solve(x, A, ...)
xTAx_qrsolve(x, A, tol = 1e-07, ...)
sandwich_solve(A, B, ...)
xTAx_eigen(x, A, tol = sqrt(.Machine$double.eps), ...)
sandwich_sginv(A, B, ...)
sandwich_ginv(A, B, ...)Functions
xTAx(): Evaluate \(x'Ax\) for vector \(x\) and square matrix \(A\).xAxT(): Evaluate \(xAx'\) for vector \(x\) and square matrix \(A\).xTAx_solve(): Evaluate \(x'A^{-1}x\) for vector \(x\) and invertible matrix \(A\) usingsolve().xTAx_qrsolve(): Evaluate \(x'A^{-1}x\) for vector \(x\) and matrix \(A\) using QR decomposition and confirming that \(x\) is in the span of \(A\) if \(A\) is singular; returnsrankandnullityas attributes just in case subsequent calculations (e.g., hypothesis test degrees of freedom) are affected.sandwich_solve(): Evaluate \(A^{-1}B(A')^{-1}\) for \(B\) a square matrix and \(A\) invertible.xTAx_eigen(): Evaluate \(x' A^{-1} x\) for vector \(x\) and matrix \(A\) (symmetric, nonnegative-definite) via eigendecomposition and confirming that \(x\) is in the span of \(A\) if \(A\) is singular; returnsrankandnullityas attributes just in case subsequent calculations (e.g., hypothesis test degrees of freedom) are affected.Decompose \(A = P L P'\) for \(L\) diagonal matrix of eigenvalues and \(P\) orthogonal. Then \(A^{-1} = P L^{-1} P'\).
Substituting, $$x' A^{-1} x = x' P L^{-1} P' x = h' L^{-1} h$$ for \(h = P' x\).