chol2inv-methods | R Documentation |
Given formally upper and lower triangular matrices
U
and L
, compute (U' U)^{-1}
and (L L')^{-1}
, respectively.
This function can be seen as way to compute the inverse of a
symmetric positive definite matrix given its Cholesky factor.
Equivalently, it can be seen as a way to compute
(X' X)^{-1}
given the R
part of the
QR factorization of X
, if R
is constrained to have
positive diagonal entries.
chol2inv(x, ...)
## S4 method for signature 'dtrMatrix'
chol2inv(x, ...)
## S4 method for signature 'dtCMatrix'
chol2inv(x, ...)
## S4 method for signature 'generalMatrix'
chol2inv(x, uplo = "U", ...)
x |
a square matrix or |
uplo |
a string, either |
... |
further arguments passed to or from methods. |
A matrix, symmetricMatrix
,
or diagonalMatrix
representing
the inverse of the positive definite matrix whose
Cholesky factor is x
.
The result is a traditional matrix if x
is a
traditional matrix, dense if x
is dense, and
sparse if x
is sparse.
The default method from base, chol2inv
,
called for traditional matrices x
.
Generic function chol
, for computing the upper
triangular Cholesky factor L'
of a symmetric positive
semidefinite matrix.
Generic function solve
, for solving linear systems
and (as a corollary) for computing inverses more generally.
(A <- Matrix(cbind(c(1, 1, 1), c(1, 2, 4), c(1, 4, 16))))
(R <- chol(A))
(L <- t(R))
(R2i <- chol2inv(R))
(L2i <- chol2inv(R))
stopifnot(exprs = {
all.equal(R2i, tcrossprod(solve(R)))
all.equal(L2i, crossprod(solve(L)))
all.equal(as(R2i %*% A, "matrix"), diag(3L)) # the identity
all.equal(as(L2i %*% A, "matrix"), diag(3L)) # ditto
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.