Skip to content

Commit

Permalink
Merge pull request #264 from mlr-org/add_rcll
Browse files Browse the repository at this point in the history
add RCLL
  • Loading branch information
RaphaelS1 authored Mar 31, 2022
2 parents be96ee3 + 948c1aa commit b646587
Show file tree
Hide file tree
Showing 29 changed files with 242 additions and 3 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Collate:
'MeasureSurvMSE.R'
'MeasureSurvNagelkR2.R'
'MeasureSurvOQuigleyR2.R'
'MeasureSurvRCLL.R'
'MeasureSurvRMSE.R'
'MeasureSurvSchmid.R'
'MeasureSurvSongAUC.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export(MeasureSurvMAE)
export(MeasureSurvMSE)
export(MeasureSurvNagelkR2)
export(MeasureSurvOQuigleyR2)
export(MeasureSurvRCLL)
export(MeasureSurvRMSE)
export(MeasureSurvSchmid)
export(MeasureSurvSongAUC)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# mlr3proba 0.4.7

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

# mlr3proba 0.4.6
Expand Down
72 changes: 72 additions & 0 deletions R/MeasureSurvRCLL.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#' @template surv_measure
#' @templateVar title Right-Censored Log loss
#' @templateVar fullname MeasureSurvRCLL
#'
#' @description
#' Calculates the right-censored logarithmic (log), loss.
#'
#' The RCLL, in the context of probabilistic predictions, is defined by
#' \deqn{L(f, t, \Delta) = -log(\Delta f(t) + (1 - \Delta) S(t))}
#' where \eqn{\Delta} is the censoring indicator.
#'
#' @template param_id
#' @template param_eps
#'
#' @references
#' Avati, A., Duan, T., Zhou, S., Jung, K., Shah, N. H., & Ng, A. (2018).
#' Countdown Regression: Sharp and Calibrated Survival Predictions.
#' http://arxiv.org/abs/1806.08324
#'
#' @family Probabilistic survival measures
#' @family distr survival measures
#' @export
MeasureSurvRCLL = R6::R6Class("MeasureSurvRCLL",
inherit = MeasureSurv,
public = list(
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ps(
eps = p_dbl(0, 1, default = 1e-15),
se = p_lgl(default = FALSE)
)
ps$values = list(eps = 1e-15, se = FALSE)

super$initialize(
id = "surv.rcll",
minimize = TRUE,
predict_type = "distr",
packages = "distr6",
label = "RCLL",
man = "mlr3proba::mlr_measures_surv.rcll",
range = c(-Inf, Inf),
param_set = ps
)

invisible(self)
}
),

private = list(
.score = function(prediction, ...) {
out = numeric(length(prediction$row_ids))
truth = prediction$truth
event = truth[, 2] == 1

# uncensored -> pdf at outcome time (survived *this* long)
out[event] = diag(prediction$distr$pdf(truth[event, 1]))
# censored -> survival at outcome time (survived *at least* this long)
out[!event] = diag(prediction$distr$survival(truth[!event, 1]))
# prevent infinite log errors
out[out == 0] = self$param_set$values$eps

out = -log(out)

if (self$param_set$values$se) {
sd(out) / sqrt(length(out))
} else {
mean(out)
}
}
)
)
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ register_mlr3 = function() {
x$add("surv.brier", MeasureSurvGraf)
x$add("surv.schmid", MeasureSurvSchmid)
x$add("surv.logloss", MeasureSurvLogloss)
x$add("surv.rcll", MeasureSurvRCLL)
x$add("surv.intlogloss", MeasureSurvIntLogloss)

x$add("surv.cindex", MeasureSurvCindex)
Expand Down
5 changes: 4 additions & 1 deletion man/mlr3proba-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlr_measures_surv.calib_alpha.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_measures_surv.calib_beta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_measures_surv.chambless_auc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_measures_surv.cindex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlr_measures_surv.dcalib.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/mlr_measures_surv.graf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_measures_surv.hung_auc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/mlr_measures_surv.intlogloss.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/mlr_measures_surv.logloss.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_measures_surv.mae.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_measures_surv.mse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_measures_surv.nagelk_r2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/mlr_measures_surv.oquigley_r2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b646587

Please sign in to comment.