R/makePosSemiDef.r

Defines functions makePosSemiDef

Documented in makePosSemiDef

#' Makes square matrices positive semi-definite.
#' 
#' Internal function which returns closest positive semi-definite matrix to input matrix.
#' 
#' @param a Square matrix.
#' @param offset Offset.
#' @return Positive semi-definite matrix.
#' @keywords internal
#' @author Saskia Freytag
makePosSemiDef<-function(
      a, # matrix 
      offset=0)
{
  
  lambda<-abs(min(eigen(a, only.values=TRUE)$values))
  return((a + (diag(dim(a)[1]) * (lambda+offset))) /(1+lambda+offset))
}

Try the RUVcorr package in your browser

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

RUVcorr documentation built on Nov. 8, 2020, 5:10 p.m.