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
check_ld(
R,
method = c("check", "shrink", "eigenfix"),
r_tol = 1e-08,
shrinkage = 0.01
)Value
A list with components:
- R
The (possibly repaired) LD matrix.
- is_pd
Logical: is the matrix positive definite?
- is_psd
Logical: is the matrix positive semidefinite (within r_tol)?
- min_eigenvalue
Smallest eigenvalue of the original matrix.
- n_negative
Number of negative eigenvalues (below -r_tol).
- condition_number
Ratio of largest to smallest positive eigenvalue (
Infif any eigenvalue is zero).- method_applied
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)
check_ld(R_good)$is_pd # 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
check_ld(R_bad)$is_psd # FALSE
#> [1] FALSE
R_fixed <- check_ld(R_bad, method = "eigenfix")$R
check_ld(R_fixed)$is_psd # TRUE
#> [1] FALSE