| scr_rag | R Documentation |
Reads a study sample against the reference the score was developed on
and lights every check red, amber or green, in four families:
discrimination, calibration, stability and, for a scorecard, the
variables. With by, one set of lights per period or segment, from the
same count table.
scr_rag(x, ...)
## S3 method for class 'scr_scorecard'
scr_rag(
x,
plan = NULL,
sample = "holdout",
reference = "train",
by = NULL,
level = NULL,
min_events = 20L,
n_bands = NULL,
n_boot = NULL,
seed = NULL,
max_cells = 1e+05,
boot_cells = 10000,
...
)
## S3 method for class 'data.frame'
scr_rag(
x,
score = "score",
y = "y",
prob = NULL,
objective = "risk",
direction = NULL,
weight = NULL,
sample = NULL,
reference = NULL,
study = NULL,
by = NULL,
plan = NULL,
level = 0.95,
min_events = 20L,
n_bands = 10L,
n_boot = 200L,
seed = NULL,
max_cells = 1e+05,
boot_cells = 10000,
...
)
## S3 method for class 'scr_study'
scr_rag(
x,
plan = NULL,
sample = NULL,
level = NULL,
min_events = 20L,
n_boot = 200L,
seed = NULL,
boot_cells = 10000,
...
)
x |
An object from |
... |
Passed on to the methods; an unknown argument is an error. |
plan |
Thresholds table, as returned by |
sample |
For a scorecard: the study sample ( |
reference |
For a scorecard: the sample the bands are frozen on
( |
by |
Name of a column holding periods or segments (for a scorecard,
a column of its scored samples such as |
level |
Confidence level of the intervals. For a scorecard or a
score study, |
min_events |
Fewest events, and non-events, of the study group for a lit result. |
n_bands |
Bands frozen on the reference for the PSI, the rank order
and the band calibration. For a scorecard, |
n_boot |
Bootstrap resamples of the Gini ratio interval. For a
scorecard, |
seed |
Seed of the bootstrap. A number is local to the call (the
user's random stream is restored on exit); |
max_cells |
Largest number of distinct score values kept exactly. |
boot_cells |
Largest number of score cells resampled exactly by the
bootstrap (default 10,000; |
score, y |
Column names of the score and of the 0/1 outcome ( |
prob |
For a data.frame: optional column with the expected event probability of every case. |
objective |
|
direction |
|
weight |
Optional column of non-negative case weights. |
study |
Labels of the study samples; |
An object of class scr_rag:
tableOne row per check: sample, group, family,
metric, level ("score", a variable name or a band label),
value, lo, hi, benchmark (the reference value or critical
value it is read against), light ("green", "amber", "red",
"grey" or "none") and reason.
summaryOne row per sample and group: the light of
discrimination, calibration, stability, variables and
overall, and the reason of the overall light.
planThe thresholds used.
objective, direction, level, min_events, reference,
study, by, cuts, target, callThe settings.
gini_ratio, Gini(study) / Gini(reference), with
a bootstrap interval from independent resamples of both samples (the
count bootstrap of scr_bands(), exact up to boot_cells distinct
scores and an approximation above); auc_change_p, the one-sided
p-value of the S-test
S = (AUC_{ref} - AUC_{study}) / \sqrt{se_{study}^2 + se_{ref}^2},
with both DeLong standard errors computed from the counts per score
value. This is the two-sample form: both AUCs are estimated here, on
independent samples. The ECB (2019) instructions take the initial AUC
as fixed (only the current AUC's standard error), which suits a
development AUC taken from documentation; applied to an estimated
reference AUC, that form rejects too often. ks is reported without
a light.
Needs an expected probability: the alignment of a
scorecard, or the prob column of a data.frame; otherwise both
lights are "grey" ("no expected probability"). oe_ratio, observed over
expected events, with the Jeffreys interval of the observed rate;
band_calibration, the number of bands whose Jeffreys test rejects
the band mean expected probability. Under risk both checks are
one-sided, against under-prediction only (over-prediction is
prudent); under propensity they are two-sided (see
scr_rag_plan()). Every band is also listed, without a light.
score_psi over bands frozen on the reference, lit by
effect and significance; rank_order, the number of Holm-significant
reversals between adjacent bands.
For a scorecard read on its hold-out against train:
the CSI of every variable over its frozen bins (same rule as the
PSI), iv_ratio = IV(study) / IV(reference), and woe_sign_flip,
the number of bins holding at least 5% of the study volume whose WOE
changes sign (amber at most).
One convention holds for every light: a light is amber or red only when
the confidence interval shows the metric beyond the threshold (for a
p-value, when the test rejects); with too few events it is "grey". The
thresholds and rules are in scr_rag_plan().
A group with fewer than min_events events, or non-events, in the study
sample gets "grey" lights, with the values still reported. Within a
family the worst light wins (red, then amber, then green; "grey" only
when nothing is lit). The overall light is the worst of discrimination
and calibration; stability and variables can raise it to amber, never to
red, and an overall without any lit discrimination or calibration check
is "grey". The reason of the summary says how the overall light was
formed, for example "calibration not tested" when no expected
probability is available.
With by, a group of the study sample is compared with the same group
of the reference when the reference has it (a segment), and with the
whole reference otherwise (a new period). Without a sample column, every
group is compared with the whole data. The groups are listed in the order
of their labels, those of a numeric column in numeric order.
Brown, L. D., Cai, T. T. and DasGupta, A. (2001). Interval estimation for a binomial proportion. Statistical Science, 16(2), 101-133. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/ss/1009213286")}
DeLong, E. R., DeLong, D. M. and Clarke-Pearson, D. L. (1988). Comparing the areas under two or more correlated receiver operating characteristic curves: a nonparametric approach. Biometrics, 44(3), 837-845.
European Central Bank (2019). Instructions for reporting the validation results of internal models: IRB Pillar I models for credit risk. ECB Banking Supervision.
Siddiqi, N. (2006). Credit Risk Scorecards: Developing and Implementing Intelligent Credit Scoring. Wiley.
Yurdakul, B. and Naranjo, J. (2020). Statistical properties of the population stability index. Journal of Risk Model Validation, 14(4), 89-100.
Other score-studies:
scr_bands(),
scr_claims(),
scr_detection(),
scr_maturity(),
scr_mix_shift(),
scr_operating(),
scr_overlap(),
scr_rag_plan(),
scr_score_cross(),
scr_segments(),
scr_tiers(),
scr_uplift()
cfg <- scr_config(verbose = FALSE, nthread = 1, use_ranger = FALSE,
use_lightgbm = FALSE, xgb_rounds = 40, n_boot = 20)
res <- scr_select(scr_demo, "default", config = cfg, drop = c("id", "churn"),
date_col = "ref_date")
sc <- scr_scorecard(res)
rg <- scr_rag(sc)
rg
rg$summary
# a data.frame with a sample column and an expected probability
d <- rbind(data.frame(sample = "dev", sc$samples$train[, c("score", "y", "prob")]),
data.frame(sample = "new", sc$samples$holdout[, c("score", "y", "prob")]))
scr_rag(d, prob = "prob", sample = "sample", n_boot = 50)$summary
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.