| assocSelect | R Documentation |
Identifies 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.
assocSelect(
df,
threshold = 0.7,
method = NULL,
force_in = NULL,
method_num_num = c("pearson", "spearman", "kendall", "bicor", "distance", "maximal"),
method_num_ord = c("spearman", "kendall"),
method_ord_ord = c("spearman", "kendall"),
...
)
df |
A data frame (or tibble / data.table). May contain any mix of:
|
threshold |
Numeric in |
method |
Character; the subset-search algorithm. One of
|
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 |
method_num_ord |
Association measure for numeric–ordered pairs.
One of |
method_ord_ord |
Association measure for ordered–ordered pairs.
One of |
... |
Additional arguments passed unchanged to |
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:
method_num_num (default "pearson")
method_num_ord
"eta" (the correlation ratio
\eta = \sqrt{\eta^{2}} of a one-way ANOVA)
method_ord_ord
"cramersv"
"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.
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:
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.
Named list mapping every possible
variable-type-pair combination to its resolved method, regardless of
whether that combination occurs in df.
corrSelect(), MatSelect(), corrSubset()
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.