Greedy, iterative removal of variables that carry the same information as a better-ranked one. Information Value ranks variables one at a time; two variables can both be strong and say the same thing, which a model on Weight of Evidence shows as an unstable or sign-flipped coefficient.
Arguments
- x
A
data.frameof numeric columns to be compared — normally the WoE-transformed predictors, which is the space the model sees — or a pre-computed pairwise table fromobcorrwith columnsx,yand a correlation column.- ranking
Character vector of variable names, best first. Variables absent from
rankingare treated as ranked last.- cutoff
Numeric in \((0, 1]\). Absolute correlation at or above which two variables are considered redundant. Default
0.70.- method
Character string passed to
obcorrwhenxis adata.frameof columns. Default"pearson".
Value
A list with:
keepCharacter vector of surviving variables.
droppeddata.frameofvariable,correlated_withandcorrelation— one row per removal, in the order the removals happened.pairsThe pairwise table, with an
abs_corrcolumn.cutoffThe cutoff used.
Details
The pass is iterative on purpose. Evaluating every pair independently removes both \(B\) and \(C\) from a chain \(A \sim B \sim C\) even when \(B\) and \(C\) are unrelated to each other: once \(B\) is gone, the pair \((B, C)\) no longer exists. Each iteration therefore drops one variable — the worst-ranked member of the strongest surviving pair — and recomputes what is left.
Examples
set.seed(1)
n <- 500
a <- rnorm(n)
df <- data.frame(a = a, b = a + rnorm(n, 0, 0.2), c = rnorm(n))
# b duplicates a; a is ranked better, so b goes
obwoe_prune(df, ranking = c("a", "b", "c"), cutoff = 0.7)
#> $keep
#> [1] "a" "c"
#>
#> $dropped
#> variable correlated_with correlation
#> 1 b a 0.9785343
#>
#> $pairs
#> x y pearson abs_corr
#> 1 a b 0.97853425 0.97853425
#> 2 a c -0.02845298 0.02845298
#> 3 b c -0.04396917 0.04396917
#>
#> $cutoff
#> [1] 0.7
#>
