corrPrune: Association-Based Predictor Pruning

View source: R/corrPrune.R

corrPruneR Documentation

Association-Based Predictor Pruning

Description

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.

Usage

corrPrune(
  data,
  threshold = 0.7,
  measure = "auto",
  mode = "auto",
  force_in = NULL,
  by = NULL,
  group_q = 1,
  max_exact_p = 100,
  ...
)

Arguments

data

A data.frame containing candidate predictors.

threshold

Numeric scalar. Maximum allowed pairwise association (default: 0.7). Must be in ⁠[0, 1]⁠ – every supported association measure is bounded in ⁠[0, 1]⁠ (in absolute value), so this range is enforced the same way regardless of mode (threshold = 0 is valid only in mode = "greedy"; see Mode Selection below).

measure

Character string specifying the numeric-numeric association measure to use. One of "auto" (default, Pearson), "pearson", "spearman", "kendall", "bicor", "distance", or "maximal". This only customizes numeric-numeric pairs; every other pair-type combination is fixed and not affected by measure: eta-squared for numeric-categorical pairs, Cramer's V for categorical-categorical pairs, and Spearman for numeric-ordered and ordered-ordered pairs. The measure actually used for each pair-type combination is reported in the assoc_methods_used attribute of the result.

mode

Character string specifying the search algorithm. Options:

  • "auto" (default): uses exact search if number of predictors <= max_exact_p and there are at least 2 predictors with threshold > 0, otherwise uses greedy search (exact search requires both, since it routes through MatSelect())

  • "exact": exhaustive search for maximal subsets (may be slow for large p); requires at least 2 predictors and threshold > 0

  • "greedy": fast approximate search using iterative removal; supports a single predictor and threshold = 0

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. Default: NULL (no grouping).

group_q

Numeric scalar in (0, 1]. Quantile used to aggregate associations across groups when by is provided. Default: 1 (maximum, ensuring threshold holds in all groups). Use 0.9 for 90th percentile, etc.

max_exact_p

Integer. Maximum number of predictors for which exact mode is used when mode = "auto". Default: 100.

...

Additional arguments (reserved for future use).

Details

corrPrune() identifies a subset of predictors whose pairwise associations are all below threshold. The function works in several stages:

  1. Variable type detection: Identifies numeric vs. categorical predictors

  2. Association measurement: Computes appropriate pairwise associations

  3. Grouping (optional): If by is specified, computes associations within each group and aggregates using the specified quantile

  4. Feasibility check: Verifies that force_in variables satisfy the threshold constraint

  5. 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().

Value

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:

selected_vars

Character vector of retained variable names

removed_vars

Character vector of removed variable names

mode

Character string indicating which mode was used ("exact" or "greedy")

measure

Character string indicating which measure was used for numeric-numeric pairs

assoc_methods_used

Named list mapping each pair-type combination (e.g. "numeric_numeric", "numeric_factor") to the association method actually used

threshold

The threshold value used

n_rows_used

Number of complete-case rows used to compute associations (see Details); the returned data itself is not row-filtered

See Also

corrSelect for exhaustive subset enumeration, assocSelect for mixed-type data subset enumeration, modelPrune for model-based predictor pruning.

Examples

# 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")


corrselect documentation built on July 19, 2026, 1:06 a.m.