auto_cor: Multicollinearity reduction via Pearson correlation

View source: R/auto_cor.R

auto_corR Documentation

Multicollinearity reduction via Pearson correlation

Description

Filters predictors using sequential evaluation of pairwise correlations. Predictors are ranked by user preference (or column order) and evaluated sequentially. Each candidate is added to the selected pool only if its maximum absolute correlation with already-selected predictors does not exceed the threshold.

Usage

auto_cor(
  x = NULL,
  preference.order = NULL,
  cor.threshold = 0.5,
  verbose = TRUE
)

Arguments

x

Data frame with predictors, or a variable_selection object from auto_vif(). Default: NULL.

preference.order

Character vector specifying variable preference order. Does not need to include all variables in x. If NULL, column order is used. Default: NULL.

cor.threshold

Numeric between 0 and 1 (recommended: 0.5 to 0.9). Maximum allowed absolute Pearson correlation between selected variables. Default: 0.50

verbose

Logical. If TRUE, prints messages about operations and removed variables. Default: TRUE

Details

The algorithm follows these steps:

  1. Rank predictors by preference.order (or use column order if NULL).

  2. Initialize selection pool with first predictor.

  3. For each remaining candidate:

    • Compute maximum absolute correlation with selected predictors.

    • If max correlation equal or lower than cor.threshold, add to selected pool.

    • Otherwise, skip candidate.

  4. Return selected predictors.

Data cleaning: Variables in preference.order not found in colnames(x) are silently removed. Non-numeric columns are removed with a warning. Rows with NA values are removed via na.omit(). Zero-variance columns trigger a warning but are not removed.

This function can be chained with auto_vif() through pipes (see examples).

Value

List with class variable_selection containing:

  • cor: Correlation matrix of selected variables (only if 2+ variables selected).

  • selected.variables: Character vector of selected variable names.

  • selected.variables.df: Data frame containing selected variables.

See Also

auto_vif()

Other preprocessing: auto_vif(), case_weights(), default_distance_thresholds(), double_center_distance_matrix(), is_binary(), make_spatial_fold(), make_spatial_folds(), the_feature_engineer(), weights_from_distance_matrix()

Examples

data(
  plants_df,
  plants_predictors
)

y <- auto_cor(
  x = plants_df[, plants_predictors]
)

y$selected.variables
y$cor
head(y$selected.variables.df)

spatialRF documentation built on Dec. 20, 2025, 1:07 a.m.