Skip to contents

The charts of CAS Monograph 5, chapter 7. double_lift_table() sorts rows by the ratio of two models' predictions pred_a / pred_b, cuts them into bands of about equal exposure and gives each band's actual and predicted averages over their overall averages (each model against its own): where the models disagree, the better one follows the actual. loss_ratio_table() sorts by the predicted loss ratio pred / premium against current premium and gives each band's actual loss ratio. roc_curve() is the ROC curve of a binary model with its area (ties counting half); confusion_matrix() the weighted counts at a threshold (a row is positive when its score is at least the threshold). normalized_gini() is gini_index() over the Gini of a perfect ranking; for a 0/1 response with unit exposure AUROC = (1 + normalized Gini) / 2.

Usage

normalized_gini(y, pred, exposure = NULL)

double_lift_table(y, pred_a, pred_b, exposure = NULL, bands = 10)

loss_ratio_table(y, pred, premium, exposure = NULL, bands = 10)

roc_curve(y, score, weights = NULL)

confusion_matrix(y, score, threshold, weights = NULL)

Arguments

y

Actual losses, or 0 and 1 for roc_curve() and confusion_matrix().

pred, pred_a, pred_b

Predicted losses (pred_b positive).

exposure, weights

Optional exposure or weights per row.

bands

Number of bands.

premium

Current premium, positive.

score

A binary model's scores.

threshold

The score at and above which a row is positive.

Value

double_lift_table() and loss_ratio_table() a data frame, one row per band; roc_curve() a list with curve (a data frame of threshold, false_positive_rate, true_positive_rate) and auc; confusion_matrix() a named vector; normalized_gini() a number.

Examples

roc_curve(c(0, 0, 1, 1), c(0.1, 0.4, 0.35, 0.8))$auc
#> [1] 0.75
y <- c(1, 0, 3, 2, 5, 1)
double_lift_table(y, c(1, 1, 2, 2, 4, 1), c(2, 1, 2, 1, 3, 2), bands = 2)
#>   exposure actual model_a model_b actual_relativity a_relativity b_relativity
#> 1        3      2       3       5         0.3333333    0.5454545    0.9090909
#> 2        3     10       8       6         1.6666667    1.4545455    1.0909091
loss_ratio_table(y, c(1, 1, 2, 2, 4, 1), rep(2, 6), bands = 2)
#>   exposure premium expected actual loss_ratio expected_loss_ratio
#> 1        3       6        3      2  0.3333333            0.500000
#> 2        3       6        8     10  1.6666667            1.333333