Diagnoses positive-definiteness of an LD correlation matrix and optionally repairs it. Downstream methods like PRS-CS require positive-definite LD (Cholesky decomposition), while others (lassosum, SDPR) handle non-PD matrices internally via their own regularization.
Usage
checkLd(
R,
method = c("check", "shrink", "eigenfix"),
rTol = 1e-08,
shrinkage = 0.01
)Value
A list with components:
- R
The (possibly repaired) LD matrix.
- isPd
Logical: is the matrix positive definite?
- isPsd
Logical: is the matrix positive semidefinite (within rTol)?
- minEigenvalue
Smallest eigenvalue of the original matrix.
- nNegative
Number of negative eigenvalues (below -rTol).
- conditionNumber
Ratio of largest to smallest positive eigenvalue (
Infif any eigenvalue is zero).- methodApplied
Character:
"none","shrink", or"eigenfix".
Details
Three modes are available:
"check"Diagnostic only - returns eigenvalue statistics without modifying the matrix.
"shrink"Apply shrinkage toward identity:
R_s = (1 - shrinkage) * R + shrinkage * I. Simple and fast; always produces a positive-definite matrix whenshrinkage > 0."eigenfix"Set negative eigenvalues to zero and reconstruct the matrix. Matches the approach used in susieR's
rss_lambda_constructorand is the closest positive semidefinite matrix in the Frobenius norm. Does not inflate the diagonal like shrinkage does.
Examples
# A well-conditioned matrix
R_good <- diag(5)
checkLd(R_good)$isPd # TRUE
#> [1] TRUE
# A matrix with negative eigenvalues
R_bad <- matrix(0.9, 3, 3); diag(R_bad) <- 1; R_bad[1,3] <- R_bad[3,1] <- -0.5
checkLd(R_bad)$isPsd # FALSE
#> [1] FALSE
R_fixed <- checkLd(R_bad, method = "eigenfix")$R
checkLd(R_fixed)$isPsd # TRUE
#> [1] FALSE