LDLT: LDL' decomposition

View source: R/linalg.R

LDLTR Documentation

LDL' decomposition

Description

This wrapper around chol factors a square, symmetric, positive (semi-)definite matrix into the product of a lower triangular matrix (L), a diagonal matrix (D), and an upper triangular matrix (U) equal to the transpose of the lower triangular one (U=L'). It is also known as the square-root-free Cholesky decomposition. This decomposition is notably used in quantitative genetics (Misztal and Perez-Enciso, 1993). The determinant of the input matrix is then easily computed as the product of the diagonal entries of the decomposition.

Usage

LDLT(x, returnFormat = "matrix")

Arguments

x

matrix

returnFormat

a lower triangular matrix with the elements of D on the diagonal, or a list with two components, L as a matrix with 1 on the diagonal and the diagonal of D as a vector

Value

matrix

See Also

getSparseInv

Examples

## Not run: ## example matrix from Misztal and Perez-Enciso (1993):
W <- matrix(NA, nrow=5, ncol=5)
W[1,] <- c(5, 0, 0, 3, 0)
W[2,-1] <- c(3, 0, 0, 1)
W[3,-c(1:2)] <- c(4, 1, 1)
W[4,-c(1:3)] <- c(4, 0)
W[5,-c(1:4)] <- 2
W
W[lower.tri(W)] <- t(W)[lower.tri(W)]
W

## decomposition/factorization:
(decompM <- LDLT(W, returnFormat="matrix"))
(decompL <- LDLT(W, returnFormat="list"))

## determinant:
prod(diag(decompM)) # ~= 162, as in the paper
prod(decompL$vecD)

## End(Not run)

timflutre/rutilstimflutre documentation built on Feb. 12, 2025, 11:35 p.m.