scr_apply: Apply the WOE transformation or the scorecard to new data

View source: R/apply.R

scr_applyR Documentation

Apply the WOE transformation or the scorecard to new data

Description

Materializes in R exactly what the production SQL does: the frozen Stage 1 pre-processing (training median, special-population flags, "MISSING") followed by the frozen Stage 2 binning and, for a scorecard, by the points. Nothing is refitted. The two paths, R and SQL, produce the same numbers, and a test guarantees it.

Usage

scr_apply(x, newdata, ...)

## S3 method for class 'scr_result'
scr_apply(
  x,
  newdata,
  features = scr_selected(x),
  what = c("woe", "bin", "both"),
  ...
)

## S3 method for class 'scr_scorecard'
scr_apply(x, newdata, what = c("score", "points", "woe", "all"), ...)

## S3 method for class 'scr_ead'
scr_apply(x, newdata, what = c("all", "ead", "pool"), ...)

## S3 method for class 'scr_lgd'
scr_apply(x, newdata, what = c("pool", "lgd", "all"), ...)

## S3 method for class 'scr_pd'
scr_apply(x, newdata, ...)

## S3 method for class 'scr_study'
scr_apply(x, newdata, score = "score", numbered = TRUE, ...)

Arguments

x

An object from scr_select() (returns WOE/bin of the approved variables), from scr_scorecard() (returns score and points), or a score study from scr_bands() or scr_tiers() (returns the band or tier of a score).

newdata

New table with the source columns of the requested variables. The target column is not needed.

...

Passed on to the methods.

features

For scr_result: which variables to transform. Defaults to the approved ones.

what

For scr_result: "woe", "bin" or "both". For scr_scorecard: "score", "points", "woe" or "all". For scr_lgd: "pool" (pool and pool LGDs), "lgd" (adds the predicted LGD) or "all" (adds the cure probability and the severity). For scr_ead: "all" (default), "ead" (pool, measure, applied CCF, predicted EAD and the floor flag) or "pool" (pool and measure).

score

For scr_study: name of the score column of newdata. newdata may also be a numeric vector of scores.

numbered

For a tiers study: TRUE (default) returns the tier labels with their order in front ("01.very high"), FALSE the plain labels. Band labels are intervals and never get a prefix.

Value

A data.table with one row per row of newdata.

Output columns

For scr_result: ⁠<f>_woe⁠ and/or ⁠<f>_bin⁠ per variable. For scr_scorecard, "score" gives link (logit), prob (model probability), score (exact, a + b * logit) and score_points (base plus the whole points per bin); "points" gives score, score_points and ⁠<f>_points⁠; "woe" gives link, score and ⁠<f>_woe⁠; "all" gives everything.

IRB models

scr_pd returns score, score_points, grade, pd (calibrated individual PD), pd_be and pd_final of the grade. scr_lgd returns pool, lgd_lra, lgd_dt, lgd_final and, with what, p_cure, severity and lgd_pred. scr_ead returns pool, measure, utilisation, undrawn, ccf_applied, ead_model, ead_floor, ead_predicted and ead_floor_binding; the predicted EAD is never below the drawn amount. scr_capital() reads pd_final, lgd_final and ead_predicted from these outputs in its list form.

Score studies

For a score study (scr_bands(), scr_tiers()), newdata is returned (as a copy) with tier, the band or tier number, and tier_label. The intervals are left-closed: score >= cut is the upper side, and a missing score gives a missing tier.

The labels of a tiers study carry their order, "01." for the tier with the highest event rate (the first row of the tiers table) down to the tier with the lowest, so they sort from the event-richest tier under any objective and direction; tier is unchanged and still rises with the event rate. The result joins to the tier_label column of the tiers table. numbered = FALSE returns the plain labels (its label column).

See Also

Other production: predict.scr_align(), scr_export(), scr_monitor(), scr_monitoring_plan(), scr_reasons(), scr_sql()

Examples

cfg <- scr_config(verbose = FALSE, nthread = 1, use_ranger = FALSE,
                  xgb_rounds = 60, n_boot = 20)
res <- scr_select(scr_demo, "default", config = cfg, drop = "id",
                  date_col = "ref_date")
new <- head(scr_demo, 50)
str(scr_apply(res, new)[, 1:3])
sc <- scr_scorecard(res)
head(scr_apply(sc, new))
head(scr_apply(sc, new, what = "points"))

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