Title: | Calibration Bands |
---|---|
Description: | Package to assess the calibration of probabilistic classifiers using confidence bands for monotonic functions. Besides testing the classical goodness-of-fit null hypothesis of perfect calibration, the confidence bands calculated within that package facilitate inverted goodness-of-fit tests whose rejection allows for a sought-after conclusion of a sufficiently well-calibrated model. The package creates flexible graphical tools to perform these tests. For construction details see also Dimitriadis, Dümbgen, Henzi, Puke, Ziegel (2022) <arXiv:2203.04065>. |
Authors: | Timo Dimitriadis [aut], Alexander Henzi [aut], Marius Puke [aut, cre] |
Maintainer: | Marius Puke <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-11-11 03:59:13 UTC |
Source: | https://github.com/marius-cp/calibrationband |
Confidence bands for monotone probabilities
calibration_bands( x, y, alpha = 0.05, method = "standard", digits = NULL, nc = FALSE )
calibration_bands( x, y, alpha = 0.05, method = "standard", digits = NULL, nc = FALSE )
x |
covariate. |
y |
response variable (in 0,1). |
alpha |
type one error probability (1 minus the confidence level). |
method |
|
digits |
number of digits for method |
nc |
use non-crossing bands for method |
An object of class calibrationband
, which is a list containing the following entries:
bands |
a tibble holding x,lwr,upr the lower and upper bound,
for each value of x .
The upper bound extends to the left and the lower bound to the right,
that is, the upper bound for x[i]<s<x[i+1] is upr[i+1] ,
and the lower bound for x[i]<s<x[i+1] is lwr[i] . |
cal |
a tibble holding the areas/segments of calibration (out=0 ) and miscalibration (out=1 ). |
bins |
a tibble of the characteristics of the isotonic bins. |
cases |
tibble of all predictions and observations.
In addition it holds the column isoy , which is the isotonic
regression of y at points x . |
alpha |
the given type one error probability (1 minus the nominal coverage of the band). |
method |
the selected method for computing the band. |
nc |
the selected method for non-crossing. |
digits |
the given digits for method "round"
(or NULL for method "standard" ). |
time |
time to compute the upper and lower band. |
Uses the ggplot2 package to illustrate monotone confidence bands to assess calibration of prediction methods that issue probability forecasts.
## S3 method for class 'calibrationband' autoplot( object, ..., approx.equi = NULL, cut.bands = FALSE, p_ribbon = NULL, p_isoreg = NULL, p_diag = NULL ) ## S3 method for class 'calibrationband' autolayer( object, ..., approx.equi = NULL, cut.bands = FALSE, p_diag = NA, p_isoreg = NA, p_ribbon = NA ) ## S3 method for class 'calibrationband' plot(x, ...)
## S3 method for class 'calibrationband' autoplot( object, ..., approx.equi = NULL, cut.bands = FALSE, p_ribbon = NULL, p_isoreg = NULL, p_diag = NULL ) ## S3 method for class 'calibrationband' autolayer( object, ..., approx.equi = NULL, cut.bands = FALSE, p_diag = NA, p_isoreg = NA, p_ribbon = NA ) ## S3 method for class 'calibrationband' plot(x, ...)
object |
object of class |
... |
Further arguments to be passed to or from methods. |
approx.equi |
If In large data sets, Note, we add important additional points the initial scalar of
|
cut.bands |
Cut the bands at most extreme prediction values. Bands will not be extended to 0 and 1 respectively if option is set equal to true. |
p_ribbon |
If non |
p_isoreg |
If non |
p_diag |
If non |
x |
object of class |
When plotting the monotone confidence band, the upper bound should be
extended to the left, that is, the bound at x[i]
is valid on the
interval (x[i-1],x[i]]
. The lower bound should be extended to the
right, i.e. the bound at x[i] is extended to the interval [x[i],x[i +
1])
. This function creates x and y values for correct plotting of these
bounds.
autoplot
behaves like any ggplot() + layer()
combination.
That means, customized plots should be created using autoplot
and
autolayer
.
Setting any of the p_*
arguments to NA
disables that layer.
Default parameter values for p_*
p_isoreg |
list(color = "darkgray") |
p_diag |
list(color = "black", fill="blue", alpha = .1) |
p_ribbon |
list(low = "gray", high = "red", guide = "none", limits=c(0,1))
|
An object inheriting from class 'ggplot'
.
s=.8 n=10000 x <- sort(runif(n)) p <- function(x,s){p = 1/(1+((1/x*(1-x))^(s+1)));return(p)} dat <- data.frame(pr=x, y=rbinom(n,1,p(x,s))) cb <- calibration_bands(x=dat$pr, y=dat$y,alpha=0.05, method="round", digits =3) #simple plotting plot(cb) autoplot(cb) #customize the plot using ggplot2::autolayer autoplot( cb, approx.equi=NULL, p_ribbon = NA )+ ggplot2::autolayer( cb, p_ribbon = list(alpha = .3, fill = "gray", colour = "blue"), )
s=.8 n=10000 x <- sort(runif(n)) p <- function(x,s){p = 1/(1+((1/x*(1-x))^(s+1)));return(p)} dat <- data.frame(pr=x, y=rbinom(n,1,p(x,s))) cb <- calibration_bands(x=dat$pr, y=dat$y,alpha=0.05, method="round", digits =3) #simple plotting plot(cb) autoplot(cb) #customize the plot using ggplot2::autolayer autoplot( cb, approx.equi=NULL, p_ribbon = NA )+ ggplot2::autolayer( cb, p_ribbon = list(alpha = .3, fill = "gray", colour = "blue"), )
Printing methods for 'calibrationband'
and
'summary.calibrationband'
objects.
## S3 method for class 'calibrationband' print(x, ...) ## S3 method for class 'summary.calibrationband' print(x, ...)
## S3 method for class 'calibrationband' print(x, ...) ## S3 method for class 'summary.calibrationband' print(x, ...)
x |
object of class |
... |
Further arguments to be passed to or from methods;
in particular these passed to |
print.calibrationband
always sends an autoplot object to the
current graphics device and prints a summary to the console.
Invisibly returns x
.
autoplot.calibrationband
,
summary.calibrationband
An object of class calibrationband
contains the calibration band
coordinates, the pairs of original observation and forecast values,
and the recalibrated forecasts obtained by isotonic regression.
The function summary.reliabilitydiag
calculates the areas of
miscalibration.
## S3 method for class 'calibrationband' summary(object, ..., iso_test = FALSE, n = 3)
## S3 method for class 'calibrationband' summary(object, ..., iso_test = FALSE, n = 3)
object |
object of class |
... |
Further arguments to be passed to or from methods. |
iso_test |
with |
n |
number of rows in output table. |
A 'summary.reliability'
object, which is also a
tibble (see tibble::tibble()
) with columns:
min_x | minimal x-coordinate of misscalibration segment (ordered by length). |
max_x | maximal x-coordinate of misscalibration segment (ordered by length). |
set.seed(123) s=.8 n=10000 x <- sort(runif(n)) p <- function(x,s){p = 1/(1+((1/x*(1-x))^(s+1)));return(p)} dat <- data.frame(pr=x, y=rbinom(n,1,p(x,s))) cb <- calibration_bands(x=dat$pr, y=dat$y,alpha=0.05, method="round", digits =3) summary(cb) print(summary(cb), n=5)
set.seed(123) s=.8 n=10000 x <- sort(runif(n)) p <- function(x,s){p = 1/(1+((1/x*(1-x))^(s+1)));return(p)} dat <- data.frame(pr=x, y=rbinom(n,1,p(x,s))) cb <- calibration_bands(x=dat$pr, y=dat$y,alpha=0.05, method="round", digits =3) summary(cb) print(summary(cb), n=5)