sumLogDiag: Sum the Logarithm of (Diagonal) Elements

Description Usage Arguments Value Author(s) See Also Examples

Description

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

Usage

1
2
3

Arguments

mat

A square matrix (preferably a Cholesky factor).

v

A vector

Value

Sum of the logarithm of the (diagonal) elements.

Author(s)

Johan Lindstrom

See Also

Other basic linear algebra: blockMult, crossDist, makeCholBlock, norm2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## 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)
##or using sumLog (usefull e.g. for the Matrix-class)
sumLog(diag(R))

SpatioTemporal documentation built on May 2, 2019, 8:49 a.m.