Learn R Programming

SpatioTemporal (version 0.9.2)

sumLogDiag: Sum the Logarithm of Diagonal Elements

Description

Computes the sum of the logarithm of the diagonal elements in a matrix. This corresponds to the logarithm of the determinant for a Cholesky factor. Behaviour is undefined for any elements that are

Usage

sumLogDiag(mat)

Arguments

mat
A square matrix (preferably a Cholesky factor).

Value

  • Sum of the logarithm of the diagonal elements.

encoding

latin1

See Also

chol or makeCholBlock for computation of Cholesky factors. Other block matrix functions dot.prod, block.mult, calc.tF.times.mat, and calc.iS.X. This function is used by loglike.

Examples

Run this code
#Create a covariance matrix
S <- cbind(c(2,1),c(1,2))
#compute Cholesky factor
R <- chol(S)
#compute determinant
log(det(R))
#compare with sum of the logarithm of diagonal elements
sumLogDiag(R)
if( abs(log(det(R)) - sumLogDiag(R)) > 1e-10 ){
  stop("sumLogDiag: Results not equal")
}

Run the code above in your browser using DataLab