Validates that a matrix can serve as a correlation matrix for variant-set tests. Correlation matrices are used to account for linkage disequilibrium among genetic variants.
validate_correlation_matrix(M, n_variants = NULL, tol = 1e-08)A list with elements:
Logical; TRUE if all checks pass
Character string with validation result or error message
Dimension of the matrix
Logical; TRUE if symmetric within tolerance
Smallest eigenvalue (for PSD check)
Character vector of non-fatal warnings
Checks that a matrix is a valid correlation matrix suitable for use in GLOW tests. This includes checking symmetry, diagonal values, positive semi-definiteness, and appropriate dimensions.
Validation checks performed:
Basic structure:
Must be a square matrix
Must be numeric
Correlation properties:
Must be symmetric (M = t(M) within tolerance)
Diagonal must be all 1s (within tolerance)
Off-diagonal values must be in \([-1, 1]\)
Positive semi-definiteness:
All eigenvalues must be >= -tol
Required for valid correlation matrices
Small negative eigenvalues (< tol) are acceptable due to numerical error
Dimension matching (if n_variants provided):
Matrix dimension must match expected number of variants
Computational Complexity: O(n^3) for eigenvalue check where n=dim(M)
Returns: List with validation status and diagnostic information
# Valid correlation matrix
M <- diag(10)
result <- validate_correlation_matrix(M)
result$valid # TRUE
#> [1] TRUE
# Valid with correlation structure
M_cor <- matrix(0.3, 5, 5) + diag(0.7, 5)
result_cor <- validate_correlation_matrix(M_cor)
# Invalid: not symmetric
M_bad <- matrix(runif(25), 5, 5)
result_bad <- validate_correlation_matrix(M_bad)
result_bad$valid # FALSE
#> [1] FALSE
# Check dimension matching
result_dim <- validate_correlation_matrix(M_cor, n_variants=5)
result_dim$valid # TRUE
#> [1] TRUE