| MatSelect | R Documentation |
Identifies all maximal subsets of variables from a symmetric matrix (typically a correlation matrix) such that all pairwise absolute values stay below a specified threshold. Implements exact algorithms such as Eppstein–Löffler–Strash (ELS) and Bron–Kerbosch (with or without pivoting).
MatSelect(mat, threshold = 0.7, method = NULL, force_in = NULL, ...)
mat |
A numeric, symmetric matrix with 1s on the diagonal (e.g. correlation matrix). Column names (if present) are used to label output variables. |
threshold |
A numeric scalar in (0, 1]. Maximum allowed absolute pairwise value.
Defaults to |
method |
Character. Selection algorithm to use. One of |
force_in |
Optional integer vector of 1-based column indices to force into every subset.
If the forced variables are themselves mutually correlated beyond |
... |
Additional arguments passed to the backend, e.g., |
An object of class CorrCombo, containing all valid subsets and their
correlation statistics. If every variable is pairwise correlated above threshold,
the only valid maximal subsets are single variables; these are returned with
min_corr/max_corr set to NA (there is no pair to summarize).
set.seed(42)
mat <- matrix(rnorm(100), ncol = 10)
colnames(mat) <- paste0("V", 1:10)
cmat <- cor(mat)
# Default method (Bron-Kerbosch)
res1 <- MatSelect(cmat, threshold = 0.5)
# Bron–Kerbosch without pivot
res2 <- MatSelect(cmat, threshold = 0.5, method = "bron-kerbosch", use_pivot = FALSE)
# Bron–Kerbosch with pivoting
res3 <- MatSelect(cmat, threshold = 0.5, method = "bron-kerbosch", use_pivot = TRUE)
# Force variables 1 and 2 into every subset (warns if they are mutually
# correlated beyond the threshold; both are still forced in regardless)
res4 <- MatSelect(cmat, threshold = 0.5, force_in = c(1, 2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.