Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: parsnip
Title: A Common API to Modeling and Analysis Functions
Version: 1.1.0.9002
Version: 1.1.0.9003
Authors@R: c(
person("Max", "Kuhn", , "max@posit.co", role = c("aut", "cre")),
person("Davis", "Vaughan", , "davis@posit.co", role = "aut"),
Expand Down
8 changes: 8 additions & 0 deletions R/survival-censoring-weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ trunc_probs <- function(probs, trunc = 0.01) {
}

.check_censor_model <- function(x) {
if (x$spec$mode != "censored regression") {
cli::cli_abort(
"The model needs to be for mode 'censored regression', not for mode '{x$spec$mode}'."
)
}
nms <- names(x)
if (!any(nms == "censor_probs")) {
rlang::abort("Please refit the model with parsnip version 1.0.4 or greater.")
Expand Down Expand Up @@ -245,14 +250,17 @@ add_graf_weights_vec <- function(object, .pred, surv_obj, trunc = 0.05, eps = 10
num_times <- vctrs::list_sizes(.pred)
y <- vctrs::list_unchop(.pred)
y$surv_obj <- vctrs::vec_rep_each(surv_obj, times = num_times)

names(y)[names(y) == ".time"] <- ".eval_time" # Temporary

# Compute the actual time of evaluation
y$.weight_time <- graf_weight_time_vec(y$surv_obj, y$.eval_time, eps = eps)
# Compute the corresponding probability of being censored
y$.pred_censored <- predict(object$censor_probs, time = y$.weight_time, as_vector = TRUE)
y$.pred_censored <- trunc_probs(y$.pred_censored, trunc = trunc)
# Invert the probabilities to create weights
y$.weight_censored = 1 / y$.pred_censored

# Convert back the list column format
y$surv_obj <- NULL
vctrs::vec_chop(y, sizes = num_times)
Expand Down