Skip to content

docs: clarify how variables are filtered out in step_corr() #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions R/corr.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#' This step attempts to remove variables to keep the largest absolute
#' correlation between the variables less than `threshold`.
#'
#' The filter tries to prioritize predictors for removal based on the global
#' affect on the overall correlation structure. If you have two identical
#' predictors, the variable ordered first will be removed.
#'
#' When a column has a single unique value, that column will be excluded from
#' the correlation analysis. Also, if the data set has sporadic missing values
#' (and an inappropriate value of `use` is chosen), some columns will also be
Expand Down Expand Up @@ -246,14 +250,16 @@ corr_filter <-
diag(x) <- 1
}
averageCorr <- colMeans(abs(x))
averageCorr <- as.numeric(as.factor(averageCorr))
avgCorrVarsRank <- as.numeric(as.factor(averageCorr))
x[lower.tri(x, diag = TRUE)] <- NA
combsAboveCutoff <- which(abs(x) > cutoff)

colsToCheck <- ceiling(combsAboveCutoff / nrow(x))
rowsToCheck <- combsAboveCutoff %% nrow(x)

colsToDiscard <- averageCorr[colsToCheck] > averageCorr[rowsToCheck]
# Discard column variable in the correlation pair with the higher average
# correlation across all pairwise correlations
colsToDiscard <- avgCorrVarsRank[colsToCheck] > avgCorrVarsRank[rowsToCheck]
rowsToDiscard <- !colsToDiscard

deletecol <- c(colsToCheck[colsToDiscard], rowsToCheck[rowsToDiscard])
Expand Down
4 changes: 4 additions & 0 deletions man/step_corr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.