scr_iv: Information Value of any grouping

View source: R/metrics.R

scr_ivR Documentation

Information Value of any grouping

Description

Laplace smoothing by default. It is not cosmetic: without it, a single-class group (a normal situation in a small sentinel population) yields Inf and contaminates any ordering that depends on the IV.

Usage

scr_iv(g, y, laplace = 0.5)

Arguments

g

Group vector (any coercible type). Rows where g or y is NA are ignored, whatever the type of g.

y

0/1 outcome vector.

laplace

Smoothing constant added to each count. 0 switches it off.

Details

Implemented with tabulate() on integer codes rather than data.table aggregation: this function is called once per candidate variable, hundreds of times per run, and the fixed cost dominated the triage.

Value

Total IV, a scalar. Zero when fewer than two groups are populated.

See Also

Other metrics: scr_metrics(), scr_psi()

Examples

set.seed(1)
y <- stats::rbinom(1000, 1, 0.3)
g <- ifelse(stats::runif(1000) < 0.5 + 0.3 * y, "A", "B")
scr_iv(g, y)

scorecraft documentation built on Dec. 6, 2026, 1:09 a.m.