R/logDet_fun.R

Defines functions logDet.fun

Documented in logDet.fun

#' Log-determinant of a positive-definite matrix
#'
#' @param x positive definite matrix.
#'
#' @return log of det(x).
#'
#' @author Philippe Lambert \email{p.lambert@uliege.be}
#' @references Lambert, P. (2021). Fast Bayesian inference using Laplace approximations
#' in nonparametric double additive location-scale models with right- and
#' interval-censored data.
#' \emph{Computational Statistics and Data Analysis}, 161: 107250.
#' <doi:10.1016/j.csda.2021.107250>
#'
#' @export
#'
#' @examples
#' A = matrix(1:4,ncol=2)
#' logDet.fun(A)
#'
logDet.fun = function(x){
  if(any(is.nan(x))) return(NA)
  if(any(!is.finite(x))) return(NA)
  eival = svd(x)$d
  idx = which(eival > 0)
  return(sum(log(eival[idx])))
}

Try the DALSM package in your browser

Any scripts or data that you put into this service are public.

DALSM documentation built on Oct. 2, 2023, 5:09 p.m.