/
MeasureSurvUnoAUC.R
69 lines (65 loc) · 1.62 KB
/
MeasureSurvUnoAUC.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
#' @template surv_measure
#' @templateVar title Uno's AUC
#' @templateVar fullname MeasureSurvUnoAUC
#'
#' @description
#' Calls [survAUC::AUC.uno()].
#'
#' Assumes random censoring.
#'
#' @template measure_survAUC
#' @template param_integrated
#' @template param_times
#'
#' @references
#' `r format_bib("uno_2007")`
#'
#' @family AUC survival measures
#' @family lp survival measures
#' @export
MeasureSurvUnoAUC = R6Class("MeasureSurvUnoAUC",
inherit = MeasureSurvAUC,
public = list(
#' @description Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
integrated = p_lgl(default = TRUE),
times = p_uty()
)
ps$values$integrated = TRUE
super$initialize(
param_set = ps,
id = "surv.uno_auc",
properties = c("requires_task", "requires_train_set"),
label = "Uno's AUC",
man = "mlr3proba::mlr_measures_surv.uno_auc"
)
}
),
private = list(
.score = function(prediction, task, train_set, ...) {
ps = self$param_set$values
if (!ps$integrated) {
msg = "If `integrated=FALSE` then `times` should be a scalar numeric."
assert_numeric(ps$times, len = 1, .var.name = msg)
} else {
if (!is.null(ps$times) && length(ps$times) == 1) {
ps$integrated = FALSE
}
}
x = super$.score(
prediction = prediction,
task = task,
train_set = train_set,
FUN = survAUC::AUC.uno,
...
)
if (is.list(x)) {
x$iauc
} else {
x
}
}
)
)
register_measure("surv.uno_auc", MeasureSurvUnoAUC)