Robust log-determinant suitable for sparse, dense, or rank-deficient
covariance matrices. Mirrors SPM25's spm_logdet, with fast paths
for 1x1 and diagonal inputs.
Arguments
- C
Square matrix.
Value
Numeric log-determinant (or NaN if non-positive).
Examples
C <- diag(c(1, 2, 4))
dcm_logdet(C) # log(1 * 2 * 4)
#> [1] 2.079442
log(prod(c(1, 2, 4))) # same
#> [1] 2.079442
# Zero rows/columns are dropped rather than sending the result to -Inf
dcm_logdet(diag(c(1, 2, 0)))
#> [1] 0.6931472