Select Variable Subsets with Low Association (Mixed-Type Data Frame Interface)
Source:R/assocSelect.R
assocSelect.RdIdentifies combinations of variables of any common data type (numeric,
ordered factors, or unordered) factors—whose pair-wise association does not
exceed a user-supplied threshold.
The routine wraps MatSelect() and handles all pre-processing
(type conversion, missing-row removal, constant-column removal) for typical
data-frame/tibble/data-table inputs.
Arguments
- df
A data frame (or tibble / data.table). May contain any mix of:
numeric / integer (treated as numeric)
ordered factors
unordered factors (character vectors are coerced to factors)
- threshold
Numeric in \((0,1]\). Maximum allowed pair-wise absolute association. Default
0.7.- method
Character; the subset-search algorithm. One of
"els"or"bron-kerbosch". IfNULL(default) the function selects automatically: ELS whenforce_inis supplied, otherwise Bron–Kerbosch.- force_in
Optional character vector or column indices specifying variables that must appear in every returned subset.
- method_num_num
Association measure for numeric–numeric pairs. One of
"pearson"(default),"spearman","kendall","bicor","distance", or"maximal".- method_num_ord
Association measure for numeric–ordered pairs. One of
"spearman"(default) or"kendall".- method_ord_ord
Association measure for ordered–ordered pairs. One of
"spearman"(default) or"kendall".- ...
Additional arguments passed unchanged to
MatSelect()(e.g.,use_pivot = TRUEfor Bron–Kerbosch).
Value
A CorrCombo object containing:
all valid subsets,
their summary association statistics,
metadata (algorithm used, rows kept, forced-in variables, etc.).
The object’s show() method prints the association metrics that were
actually used for this data set.
Two additional attributes are attached to the returned object:
- assoc_methods_used
Named list mapping each variable-type-pair combination that actually occurs in
df(e.g."numeric_numeric","numeric_factor") to the association method used for it.- assoc_methods_all
Named list mapping every possible variable-type-pair combination to its resolved method, regardless of whether that combination occurs in
df.
Details
A single call can therefore screen a data set that mixes continuous and categorical features and return every subset whose internal associations are “sufficiently low” under the metric(s) you choose.
Rows containing NA are dropped with a warning; constant columns
(a single distinct value) are excluded with a warning.
The default association measure for each variable-type combination is:
- numeric – numeric
method_num_num(default"pearson")- numeric – ordered
method_num_ord- numeric – unordered
"eta"(the correlation ratio \(\eta = \sqrt{\eta^{2}}\) of a one-way ANOVA)- ordered – ordered
method_ord_ord- ordered – unordered
"cramersv"- unordered – unordered
"cramersv"
Every measure above is a correlation magnitude in \([0,1]\), so
threshold means the same thing for every variable-type pair. \(\eta\)
is the multiple correlation between the numeric variable and the factor and
equals the absolute point-biserial correlation for a two-level factor;
Cramer's V equals the absolute phi coefficient for a 2x2 table. A binary
variable therefore gets the same association whether it is supplied as a
0/1 numeric column or as a two-level factor.
External packages are required for
"bicor" (WGCNA),
"distance" (energy),
and "maximal" (minerva); an informative error is thrown if they
are missing.
Examples
set.seed(42)
df <- data.frame(
height = rnorm(15, 170, 10),
weight = rnorm(15, 70, 12),
group = factor(rep(LETTERS[1:3], each = 5)),
score = ordered(sample(c("low","med","high"), 15, TRUE))
)
## keep every subset whose internal associations <= 0.6
assocSelect(df, threshold = 0.6)
## use Kendall for all rank-based comparisons and force 'height' to appear
assocSelect(df,
threshold = 0.5,
method_num_num = "kendall",
method_num_ord = "kendall",
method_ord_ord = "kendall",
force_in = "height")