Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete survfit helpers #324

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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
105 changes: 0 additions & 105 deletions R/aaa_survival_prob.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,111 +116,6 @@ available_survfit_summary_elements <- function(object) {
)
}

survfit_summary_patch_infinite_time <- function(object, eval_time) {
time_neg_inf <- is.infinite(eval_time) & (eval_time < 0)
time_inf <- is.infinite(eval_time) & (eval_time > 0)

patch_neg_inf <- function(x, value, n_patch) {
rbind(
matrix(value, nrow = n_patch, ncol = ncol(x)),
x
)
}
patch_inf <- function(x, value, n_patch) {
rbind(
x,
matrix(value, nrow = n_patch, ncol = ncol(x))
)
}

# glmnet does not provide standard errors etc
has_std_error <- "std.err" %in% names(object)

if (any(time_neg_inf)) {
object$surv <- patch_neg_inf(
object$surv,
value = 1,
n_patch = sum(time_neg_inf)
)
object$cumhaz <- patch_neg_inf(
object$cumhaz,
value = 0,
n_patch = sum(time_neg_inf)
)
if (has_std_error) {
object$std.err <- patch_neg_inf(
object$std.err,
value = NA_real_,
n_patch = sum(time_neg_inf)
)
object$lower <- patch_neg_inf(
object$lower,
value = NA_real_,
n_patch = sum(time_neg_inf)
)
object$upper <- patch_neg_inf(
object$upper,
value = NA_real_,
n_patch = sum(time_neg_inf)
)
object$std.chaz <- patch_neg_inf(
object$std.chaz,
value = NA_real_,
n_patch = sum(time_neg_inf)
)
}
}
if (any(time_inf)) {
object$surv <- patch_inf(object$surv, value = 0, n_patch = sum(time_inf))
object$cumhaz <- patch_inf(
object$cumhaz,
value = 1,
n_patch = sum(time_inf)
)
if (has_std_error) {
object$std.err <- patch_inf(
object$std.err,
value = NA_real_,
n_patch = sum(time_inf)
)
object$lower <- patch_inf(
object$lower,
value = NA_real_,
n_patch = sum(time_inf)
)
object$upper <- patch_inf(
object$upper,
value = NA_real_,
n_patch = sum(time_inf)
)
object$std.chaz <- patch_inf(
object$std.chaz,
value = NA_real_,
n_patch = sum(time_inf)
)
}
}

object
}

survfit_summary_restore_time_order <- function(object, eval_time) {
# preserve original order of `eval_time` because `summary()` returns a result for
# an ordered vector of finite time
# Note that this requires a survfit summary object which has already been
# patched for infinite time points
original_order_time <- match(eval_time, sort(eval_time))

elements <- available_survfit_summary_elements(object)

# restore original order of prediction time points
for (i in elements) {
object[[i]] <- object[[i]][original_order_time, , drop = FALSE]
}

object
}

survfit_summary_patch_missings <- function(object, index_missing, eval_time, n_obs) {
if (is.null(index_missing)) {
return(object)
Expand Down
Loading