R/repairMatrix.R

Defines functions repairMatrix

Documented in repairMatrix

repairMatrix <- function(C, eps = 0) {
    ## compute eigenvectors/-values
    E <- eigen(C, symmetric = TRUE)
    V <- E$vectors
    D <- E$values

    ## replace *negative* eigenvalues by eps
    D <- pmax(D, eps)

    ## reconstruct correlation matrix
    BB <- V %*% diag(D) %*% t(V)

    ## rescale correlation matrix
    T <- 1/sqrt(diag(BB))
    TT <- outer(T,T)
    BB * TT
}

Try the NMOF package in your browser

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

NMOF documentation built on Oct. 20, 2023, 9:07 a.m.