Skip to content

Commit b646587

Browse files
authored
Merge pull request #264 from mlr-org/add_rcll
add RCLL
2 parents be96ee3 + 948c1aa commit b646587

29 files changed

+242
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Collate:
9494
'MeasureSurvMSE.R'
9595
'MeasureSurvNagelkR2.R'
9696
'MeasureSurvOQuigleyR2.R'
97+
'MeasureSurvRCLL.R'
9798
'MeasureSurvRMSE.R'
9899
'MeasureSurvSchmid.R'
99100
'MeasureSurvSongAUC.R'

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export(MeasureSurvMAE)
5353
export(MeasureSurvMSE)
5454
export(MeasureSurvNagelkR2)
5555
export(MeasureSurvOQuigleyR2)
56+
export(MeasureSurvRCLL)
5657
export(MeasureSurvRMSE)
5758
export(MeasureSurvSchmid)
5859
export(MeasureSurvSongAUC)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mlr3proba 0.4.7
22

3+
* Add right-censored log loss
34
* Fix bug in {rpart} where model was being discarded when set to be kept. Parameter `model` now called `keep_model`.
45

56
# mlr3proba 0.4.6

R/MeasureSurvRCLL.R

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#' @template surv_measure
2+
#' @templateVar title Right-Censored Log loss
3+
#' @templateVar fullname MeasureSurvRCLL
4+
#'
5+
#' @description
6+
#' Calculates the right-censored logarithmic (log), loss.
7+
#'
8+
#' The RCLL, in the context of probabilistic predictions, is defined by
9+
#' \deqn{L(f, t, \Delta) = -log(\Delta f(t) + (1 - \Delta) S(t))}
10+
#' where \eqn{\Delta} is the censoring indicator.
11+
#'
12+
#' @template param_id
13+
#' @template param_eps
14+
#'
15+
#' @references
16+
#' Avati, A., Duan, T., Zhou, S., Jung, K., Shah, N. H., & Ng, A. (2018).
17+
#' Countdown Regression: Sharp and Calibrated Survival Predictions.
18+
#' http://arxiv.org/abs/1806.08324
19+
#'
20+
#' @family Probabilistic survival measures
21+
#' @family distr survival measures
22+
#' @export
23+
MeasureSurvRCLL = R6::R6Class("MeasureSurvRCLL",
24+
inherit = MeasureSurv,
25+
public = list(
26+
#' @description
27+
#' Creates a new instance of this [R6][R6::R6Class] class.
28+
initialize = function() {
29+
ps = ps(
30+
eps = p_dbl(0, 1, default = 1e-15),
31+
se = p_lgl(default = FALSE)
32+
)
33+
ps$values = list(eps = 1e-15, se = FALSE)
34+
35+
super$initialize(
36+
id = "surv.rcll",
37+
minimize = TRUE,
38+
predict_type = "distr",
39+
packages = "distr6",
40+
label = "RCLL",
41+
man = "mlr3proba::mlr_measures_surv.rcll",
42+
range = c(-Inf, Inf),
43+
param_set = ps
44+
)
45+
46+
invisible(self)
47+
}
48+
),
49+
50+
private = list(
51+
.score = function(prediction, ...) {
52+
out = numeric(length(prediction$row_ids))
53+
truth = prediction$truth
54+
event = truth[, 2] == 1
55+
56+
# uncensored -> pdf at outcome time (survived *this* long)
57+
out[event] = diag(prediction$distr$pdf(truth[event, 1]))
58+
# censored -> survival at outcome time (survived *at least* this long)
59+
out[!event] = diag(prediction$distr$survival(truth[!event, 1]))
60+
# prevent infinite log errors
61+
out[out == 0] = self$param_set$values$eps
62+
63+
out = -log(out)
64+
65+
if (self$param_set$values$se) {
66+
sd(out) / sqrt(length(out))
67+
} else {
68+
mean(out)
69+
}
70+
}
71+
)
72+
)

R/zzz.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ register_mlr3 = function() {
109109
x$add("surv.brier", MeasureSurvGraf)
110110
x$add("surv.schmid", MeasureSurvSchmid)
111111
x$add("surv.logloss", MeasureSurvLogloss)
112+
x$add("surv.rcll", MeasureSurvRCLL)
112113
x$add("surv.intlogloss", MeasureSurvIntLogloss)
113114

114115
x$add("surv.cindex", MeasureSurvCindex)

man/mlr3proba-package.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr_measures_surv.calib_alpha.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr_measures_surv.calib_beta.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr_measures_surv.chambless_auc.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr_measures_surv.cindex.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)