Last chance! 50% off unlimited learning
Sale ends in
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.
sumLogDiag(mat) sumLog(v)
A square matrix (preferably a Cholesky factor).
A vector
Sum of the logarithm of the (diagonal) elements.
Other basic linear algebra: blockMult
,
crossDist
, dotProd
,
invCholBlock
, makeCholBlock
,
norm2
, solveTriBlock
# NOT RUN {
## 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))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab