Skip to contents

A model is auto-calibrated when the mean response among rows with prediction p is p. isotonic_fit() is weighted isotonic regression by pool-adjacent-violators, as scikit-learn's IsotonicRegression (tied x merged into their weighted mean first, values clipped to [y_min, y_max] when given); predict() reads it linearly (or as steps) between its points and holds the end values beyond them. recalibrate() is the increasing isotonic regression of the response on a model's predictions on held-out data: apply it to new predictions with predict(). A frequency model needs a floor (y_min), since the lowest pooled level can be 0. balance_correction() is the multiplier sum(w y) / sum(w pred) that makes the totals agree. reliability() gives mean prediction against mean response in bands of about equal weight. murphy() splits a family's mean deviance into miscalibration - discrimination + uncertainty (Dimitriadis, Gneiting and Jordan's CORP decomposition): the miscalibration is what isotonic recalibration gains.

Usage

isotonic_fit(
  x,
  y,
  weights = NULL,
  increasing = TRUE,
  y_min = NULL,
  y_max = NULL,
  interpolation = c("linear", "step")
)

recalibrate(pred, y, weights = NULL, y_min = NULL, y_max = NULL)

balance_correction(y, pred, weights = NULL)

reliability(y, pred, weights = NULL, bins = 10)

murphy(y, pred, family = "gaussian", weights = NULL, theta = NaN, power = NaN)

Arguments

x, y

Inputs and responses.

weights

Weights (exposures when y and pred are rates), or NULL.

increasing

Whether the fit is non-decreasing.

y_min, y_max

Bounds on the fitted values, or NULL.

interpolation

"linear" or "step".

pred

A model's predictions.

bins

Number of bands.

family

A family name, as for glm_fit().

theta, power

For the negative binomial and Tweedie.

Value

isotonic_fit() and recalibrate(): an isotonic_fit object with properties x and values, read at new inputs by predict(); balance_correction() a number; reliability() a data frame with lo, hi, mean_pred, mean_actual, weight and count; murphy() a list with score, miscalibration, discrimination and uncertainty.

Examples

f <- isotonic_fit(c(1, 2, 3, 4), c(1, 3, 2, 4))
f@values
#> [1] 1.0 2.5 2.5 4.0
predict(f, c(2.5, 0, 9))
#> [1] 2.5 1.0 4.0
m <- recalibrate(c(1, 2, 3, 4), c(0, 1, 1, 2), y_min = 0.1)
predict(m, c(1, 2.5, 4))
#> [1] 0.1 1.0 2.0
balance_correction(c(1, 3), c(1, 1))
#> [1] 2
murphy(c(0, 1, 1, 2), c(0.5, 0.5, 2, 2))
#> $score
#> [1] 0.375
#> 
#> $miscalibration
#> [1] 0.125
#> 
#> $discrimination
#> [1] 0.25
#> 
#> $uncertainty
#> [1] 0.5
#>