| scr_score_cross | R Documentation |
Crosses two scores read on the same rows (a credit score and a churn score, a champion and a challenger): the cross table of their bands with the event rate of one or two outcomes, the rank association of the scores, and the overlap of the rows each one selects at a few depths, with the swap-in and swap-out sets.
scr_score_cross(x, ...)
## S3 method for class 'data.frame'
scr_score_cross(
x,
score_a,
score_b,
y = NULL,
y_a = NULL,
y_b = NULL,
objective_a = "risk",
objective_b = NULL,
direction_a = NULL,
direction_b = NULL,
n_bands = 5L,
cuts_a = NULL,
cuts_b = NULL,
depths = c(0.05, 0.1, 0.2),
weight = NULL,
level = 0.95,
...
)
x |
A |
... |
Not used; an unknown argument is an error. |
score_a, score_b |
Column names of the two scores. |
y |
Column name of a 0/1 outcome read under both scores. |
y_a, y_b |
Instead of |
objective_a, objective_b |
|
direction_a, direction_b |
|
n_bands |
Bands of each score when its cuts are not given. |
cuts_a, cuts_b |
Optional cuts of each score: a numeric vector, or an
object from |
depths |
Shares of the rows selected by each score for the overlap, in (0, 1]. |
weight |
Optional column of non-negative case weights. |
level |
Confidence level of the Jeffreys intervals. |
An object of class c("scr_score_cross", "list"):
tableThe cross table: band_a, label_a, band_b,
label_b, n, pct and the outcome columns (see the section Cross
table).
overlapOne row per depth: depth, cut_a, cut_b,
share_a, share_b, n_a, n_b, n_both, n_a_only,
n_b_only and jaccard.
overlap_ratesWith an outcome, one row per depth, outcome and
set ("A", "B", "both", "A only", "B only"): n, events,
rate, rate_lo and rate_hi.
associationOne row per method ("spearman",
"kendall_tau_b"): estimate, oriented and n.
settingsA list: the score and outcome columns, objectives,
directions, cuts, codes and labels of both scores, depths,
level, n (the volume used: the sum of the weights, the number of
rows without weights), n_rows (the rows used), n_dropped (rows
left out) and weighted.
Each score is cut into n_bands bands of equal share, tie-safe as in
scr_bands() (band 1 is the event-richest), unless cuts_a or cuts_b
gives the cuts: a numeric vector, or an object from scr_bands() or
scr_tiers(), whose cuts, numbers and labels are then used (the tier
labels for tiers). Bands are left-closed, score >= cut being the upper
side.
A study given as cuts also sets the objective and the direction of its
score, so the event-rich end of the overlap is the one the study was
fitted with. objective_a, direction_a (or their _b counterparts)
need not be given then; when given and different from the study, the call
is an error.
One row per pair of bands, every pair listed (empty ones with n = 0),
then the totals of each band of A (band_b missing, label_b = "total"), of each band of B, and the grand total. Per row: n, pct
(share of all rows) and, for every outcome, events, rate with its
Jeffreys interval rate_lo, rate_hi (on the Kish effective size under
weights) and lift (the rate over the overall rate of that outcome).
With y the outcome columns have no suffix; with y_a and y_b they
end in _a and _b.
Spearman's rank correlation (Pearson on mid-ranks, as
cor(method = "spearman")) and Kendall's tau-b (pairs tied on either
score count neither way, as cor(method = "kendall")), both on the raw
scores and unweighted. The tau-b counts are exact, by Knight's (1966)
algorithm in O(n log n). oriented multiplies each estimate by the
signs of the two directions, so it is positive when the two scores put
the same rows at their event-rich ends.
At each depth, each score selects the share depth of the rows from its
event-rich end (tie-safe: the selection stops at the boundary between two
distinct scores nearest to the target, so the share selected can differ
from depth by the share of one score value; share_a and share_b
report it). overlap counts the rows selected by A, by B, by both, by A
only and by B only, and the Jaccard index n_both / (n_a + n_b - n_both). With an outcome, overlap_rates gives the event rate of each
of the five sets with its Jeffreys interval: when B replaces A at the
same depth, "B only" is the swap-in and "A only" the swap-out.
Rows with a missing or infinite value of either score, or a zero weight,
are left out (n_dropped); rows with a missing outcome count in the
volume but not in the rates of that outcome.
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")}
Knight, W. R. (1966). A computer method for calculating Kendall's tau with ungrouped data. Journal of the American Statistical Association, 61(314), 436-439. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/01621459.1966.10480879")}
scr_bands() and scr_tiers() for the cuts of each score.
Other score-studies:
scr_bands(),
scr_claims(),
scr_detection(),
scr_maturity(),
scr_mix_shift(),
scr_operating(),
scr_overlap(),
scr_rag(),
scr_rag_plan(),
scr_segments(),
scr_tiers(),
scr_uplift()
set.seed(1)
n <- 4000
z <- rnorm(n)
d <- data.frame(credit = round(600 + 40 * (-z + rnorm(n, sd = 0.6))),
churn = round(450 + 30 * (0.4 * z + rnorm(n))),
default = rbinom(n, 1, plogis(-2 + z)),
left = rbinom(n, 1, 0.3))
cx <- scr_score_cross(d, "credit", "churn", y_a = "default", y_b = "left",
objective_b = "propensity", n_bands = 4)
cx
cx$association
cx$overlap_rates[cx$overlap_rates$depth == 0.1, ]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.