-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutators.R
70 lines (69 loc) · 2.61 KB
/
mutators.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#' Adding confidence regions
#'
#' Confidence regions are supposed to contain the true "parameter" with a given degree of confidence.
#' Here, "parameter" refers to a murphy curve, a reliability curve, or a ROC curve, respectively.
#'
#' @param x An object to which a confidence region should be added.
#' @param level A single value for the level of confidence.
#' @param method A string that gives the name of method to generate the confidence regions. Currently, one of: "resampling_cases", "resampling_Bernoulli".
#' @param ... Additional arguments passed to methods.
#'
#' @return
#' The object given to `x`, but with information about the confidence regions.
#' This information can be accessed conveniently by using [regions()] on the
#' curve component of interest.
#'
#' @examples
#' data(ex_binary, package = "triptych")
#'
#' tr <- triptych(ex_binary) |>
#' dplyr::slice(1, 9)
#'
#' # Bootstrap resampling is expensive
#' # (the number of bootstrap samples is small to keep execution times short)
#'
#' tr <- add_confidence(tr, level = 0.9, method = "resampling_cases", n_boot = 20)
#' regions(tr$murphy)
#' regions(tr$reliability)
#' regions(tr$roc)
#'
#' @seealso [resampling_cases()], [resampling_Bernoulli()]
#'
#' @export
add_confidence <- function(x, level = 0.9, method = "resampling_cases", ...) {
UseMethod("add_confidence")
}
#' Adding consistency regions for reliability curves
#'
#' Consistency regions are created under the assumption that the forecasts are calibrated.
#' A reliability curve that significantly violates the consistency region indicates
#' a miscalibrated forecast.
#'
#' @param x An object to which a consistency region should be added.
#' @param level A single value for the level of confidence.
#' @param method A string that gives the name of method to generate the consistency regions. Currently, only: "resampling_Bernoulli".
#' @param ... Additional arguments passed to methods.
#'
#' @return
#' The object given to `x`, but with information about the consistency regions.
#' This information can be accessed conveniently by using [regions()] on the
#' reliability curve component.
#'
#' @examples
#' data(ex_binary, package = "triptych")
#'
#' tr <- triptych(ex_binary) |>
#' dplyr::slice(1, 9)
#'
#' # Bootstrap resampling is expensive
#' # (the number of bootstrap samples is small to keep execution times short)
#'
#' tr <- add_consistency(tr, level = 0.9, method = "resampling_Bernoulli", n_boot = 20)
#' regions(tr$reliability)
#'
#' @seealso [resampling_Bernoulli()]
#'
#' @export
add_consistency <- function(x, level = 0.9, method = "resampling_Bernoulli", ...) {
UseMethod("add_consistency")
}