| corrPrune | R Documentation |
corrPrune() performs model-free variable subset selection by iteratively
removing predictors until all pairwise associations fall below a specified
threshold. It returns a single pruned data frame with predictors that satisfy
the association constraint.
corrPrune(
data,
threshold = 0.7,
measure = "auto",
mode = "auto",
force_in = NULL,
by = NULL,
group_q = 1,
max_exact_p = 100,
...
)
data |
A data.frame containing candidate predictors. |
threshold |
Numeric scalar. Maximum allowed pairwise association
(default: 0.7). Must be in |
measure |
Character string specifying the numeric-numeric association
measure to use. One of |
mode |
Character string specifying the search algorithm. Options:
|
force_in |
Character vector of variable names that must be retained in the final subset. Default: NULL. |
by |
Character vector naming one or more grouping variables. If provided,
associations are computed separately within each group, then aggregated
using the quantile specified by |
group_q |
Numeric scalar in (0, 1]. Quantile used to aggregate
associations across groups when |
max_exact_p |
Integer. Maximum number of predictors for which exact
mode is used when |
... |
Additional arguments (reserved for future use). |
corrPrune() identifies a subset of predictors whose pairwise associations
are all below threshold. The function works in several stages:
Variable type detection: Identifies numeric vs. categorical predictors
Association measurement: Computes appropriate pairwise associations
Grouping (optional): If by is specified, computes associations within
each group and aggregates using the specified quantile
Feasibility check: Verifies that force_in variables satisfy the
threshold constraint
Subset selection: Uses either exact or greedy search to find a valid subset
Grouped Pruning: When by is provided, the function ensures the selected
predictors satisfy the threshold constraint across groups. For example, with
group_q = 1 (default), the returned predictors will have pairwise associations
below threshold in all groups. With group_q = 0.9, they will satisfy
the constraint in at least 90% of groups.
Mode Selection: Exact mode guarantees finding all maximal subsets and returns the largest one. Greedy mode is faster but approximate, using an iterative removal strategy based on association scores.
Tie-Breaking: When multiple subsets or variables are equally good, deterministic tie-breaking is applied:
Exact mode: Selects by (1) largest subset size, (2) lowest average correlation, (3) alphabetically first variable names. Column order does not affect the result.
Greedy mode: Removes the variable with (1) most constraint violations, (2) highest max association, (3) highest average association, (4) lowest column index. Column order can influence the result when earlier criteria are tied.
To see all maximal subsets instead of a single selection, use
corrSelect().
A data.frame containing the pruned subset of predictors, with the
selected columns unchanged from data (same types and values –
character/logical/integer columns are converted internally only for
association computation, never in the returned data). The result
has the following attributes:
Character vector of retained variable names
Character vector of removed variable names
Character string indicating which mode was used ("exact" or "greedy")
Character string indicating which measure was used for numeric-numeric pairs
Named list mapping each pair-type combination (e.g. "numeric_numeric", "numeric_factor") to the association method actually used
The threshold value used
Number of complete-case rows used to compute associations (see Details); the returned data itself is not row-filtered
corrSelect for exhaustive subset enumeration,
assocSelect for mixed-type data subset enumeration,
modelPrune for model-based predictor pruning.
# Basic numeric data pruning
data(mtcars)
pruned <- corrPrune(mtcars, threshold = 0.7)
names(pruned)
# Force certain variables to be included
pruned <- corrPrune(mtcars, threshold = 0.7, force_in = "mpg")
# Use greedy mode for faster computation
pruned <- corrPrune(mtcars, threshold = 0.7, mode = "greedy")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.