Skip to content

Commit

Permalink
Merge pull request #1026 from tidymodels/fix-965
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt authored Nov 20, 2023
2 parents 4130a0b + 1aba5c1 commit 1db4a8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Fixed documentation for `mlp(engine = "brulee")`: the default values for `learn_rate` and `epochs` were swapped (#1018).

* The `new_data` argument for the `predict()` method of `censoring_model_reverse_km()` has been deprecated (#965).

* When computing censoring weights, the resulting vectors are no longer named (#1023).

# parsnip 1.1.1
Expand Down
17 changes: 9 additions & 8 deletions R/survival-censoring-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ predict.censoring_model <- function(object, ...) {
}

#' @export
predict.censoring_model_reverse_km <- function(object, new_data = NULL, time, as_vector = FALSE, ...) {
predict.censoring_model_reverse_km <- function(object, new_data, time, as_vector = FALSE, ...) {
rlang::check_installed("prodlim", version = "2022.10.13")
rlang::check_installed("censored", version = "0.1.1.9002")

if (lifecycle::is_present(new_data)) {
lifecycle::deprecate_stop(
"1.2.0",
"predict.censoring_model_reverse_km(new_data)"
)
}

res <- rep(NA_real_, length(time))
if (length(time) == 0) {
return(res)
Expand All @@ -76,13 +83,7 @@ predict.censoring_model_reverse_km <- function(object, new_data = NULL, time, as
time <- time[-is_na]
}

if (is.null(new_data)) {
tmp <-
purrr::map_dbl(time, ~ predict(object$fit, times = .x, type = "surv"))
} else {
tmp <-
purrr::map_dbl(time, ~ predict(object$fit, newdata = new_data, times = .x, type = "surv"))
}
tmp <- purrr::map_dbl(time, ~ predict(object$fit, times = .x, type = "surv"))

zero_prob <- purrr::map_lgl(tmp, ~ !is.na(.x) && .x == 0)
if (any(zero_prob)) {
Expand Down

0 comments on commit 1db4a8b

Please sign in to comment.