| scr_mix_shift | R Documentation |
Splits the change of the event rate between a base and a comparison
sample into the part due to the mix (the population moved across the
score bands) and the part due to the rates (the bands themselves have a
different event rate), on bands frozen on the base. With by, every
period or segment is compared with the base.
scr_mix_shift(x, ...)
## S3 method for class 'scr_study'
scr_mix_shift(x, base = NULL, compare = NULL, level = NULL, ...)
## S3 method for class 'scr_scorecard'
scr_mix_shift(
x,
base = NULL,
compare = NULL,
by = NULL,
n_bands = NULL,
breaks = NULL,
level = NULL,
max_cells = 1e+05,
...
)
## S3 method for class 'data.frame'
scr_mix_shift(
x,
base = NULL,
compare = NULL,
by = NULL,
n_bands = NULL,
breaks = NULL,
level = 0.95,
score = "score",
y = "y",
objective = "risk",
direction = NULL,
weight = NULL,
counts = FALSE,
n = "n",
events = "events",
max_cells = 1e+05,
...
)
x |
An object from |
... |
Passed on to the methods; an unknown argument is an error. |
base |
The base: a sample or a value of |
compare |
The comparisons: samples or values of |
level |
Confidence level: |
by |
Name of the column of periods or segments. Needed for a data.frame; for a scorecard, a column of its scored samples. |
n_bands |
Equal-share bands frozen on the base. |
breaks |
Explicit ascending cut points; overrides |
max_cells |
Largest number of distinct score values kept exactly. |
score, y |
Column names of the score and of the 0/1 outcome ( |
objective |
|
direction |
|
weight |
Optional column of non-negative case weights. |
counts |
|
n, events |
Column names of the counts when |
An object of class c("scr_mix_shift", "list"):
tableOne row per comparison and band, event-richest band
first: group, band, label, n_base, n_cmp (rows with a
known outcome), pct_base, pct_cmp, rate_base, rate_cmp,
mix_effect, rate_effect, total, p_rate and p_rate_adj.
summaryOne row per comparison: group, n_base, n_cmp,
rate_base, rate_cmp, delta, mix_total, rate_total,
share_mix, psi, psi_critical and bands_changed (bands with
p_rate_adj below 1 - level).
cuts, base, groups, by, level, objective,
direction, target, callThe cuts and the settings.
With p_k the share of band k among the rows with a known
outcome and r_k its event rate, on the base (b) and on the
comparison (c):
mix_k = (p_{c,k} - p_{b,k}) (r_{b,k} + r_{c,k}) / 2, \qquad
rate_k = (r_{c,k} - r_{b,k}) (p_{b,k} + p_{c,k}) / 2.
The weights are the midpoints of the two samples, so the effects carry no
interaction term and add up exactly:
\sum_k mix_k + \sum_k rate_k = R_c - R_b, the change of the overall
rate. A band empty in one sample has no rate there; it takes the rate of
the other sample, so its rate effect is 0 and its whole contribution is
a mix effect (the columns rate_base and rate_cmp keep the missing
rate as NA). total is mix_effect + rate_effect.
The summary adds, per comparison, share_mix = mix_total / delta (NA
when the rate did not change; it can fall outside [0, 1] when the two
effects have opposite signs) and the PSI of the band shares against the
base with its n-adjusted critical value at 1 - level (see scr_psi()).
p_rate is the two-sided p-value of the change of the rate of the band,
on the unweighted counts: Fisher's exact test when the smallest expected
count of the two-by-two table (sample by outcome) is below 5, and the
pooled two-proportion z test otherwise. p_rate_adj is Holm-adjusted
across the bands of the comparison. A band empty in either sample has no
test.
An object from scr_bands() or scr_tiers() with
at least two samples: its cuts and labels are used, base is one of
its samples (default its reference) and compare the others.
base and compare are scored samples ("train"
against "holdout"). With by, a column of the scored samples such
as "date", the rows of both samples are pooled and grouped by that
column; base is then one of its values (default the first) and
compare the others.
by names the column that tells the groups apart (a
period, a segment or a sample label); base is one of its values
(default the first level) and compare the others.
The values of by are read in the order of the levels of a factor, in
numeric order for a numeric column and as sorted text otherwise (dates
included); the first is the default base. Rows with a missing by value
are left out. Rows with a missing outcome are left out of the shares and
of the rates, so that the effects add up to the change of the rate.
Holm, S. (1979). A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, 6(2), 65-70.
Yurdakul, B. and Naranjo, J. (2020). Statistical properties of the population stability index. Journal of Risk Model Validation, 14(4), 89-100.
scr_bands() for the bands, scr_rag() for the lights of a
sample against its reference, scr_segments() for one score read on
many segments.
Other score-studies:
scr_bands(),
scr_claims(),
scr_detection(),
scr_maturity(),
scr_operating(),
scr_overlap(),
scr_rag(),
scr_rag_plan(),
scr_score_cross(),
scr_segments(),
scr_tiers(),
scr_uplift()
local({
set.seed(1)
n <- 6000
period <- rep(c("2025", "2026"), each = n / 2)
# 2026 has riskier applicants (mix) and a higher rate at every score (rate)
x <- rnorm(n, mean = ifelse(period == "2026", -0.3, 0))
d <- data.frame(period = period, score = round(600 + 50 * x),
y = rbinom(n, 1, plogis(-2 - x + 0.3 * (period == "2026"))))
ms <- scr_mix_shift(d, by = "period", n_bands = 5)
print(ms)
ms$table[, c("band", "label", "pct_base", "pct_cmp", "mix_effect", "rate_effect")]
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.