Skip to content

survival 3.7-0 breaks censored #320

@hfrick

Description

@hfrick

The new version of survival allows for infinite evaluation time points in the summary method for survfit objects instead of omitting them. It also now preserves the order of the time points.

censored captured those time points (and their order) and returned survival probabilities 1 and 0 for eval times of -Inf and Inf, respectively. We can depend on the new version of survival and remove our own handling of these cases.

With survival 3.7-0

library(survival)
library(glmnet)
#> Loading required package: Matrix
#> Loaded glmnet 4.1-8

pred_time <- c(1022, -Inf, 0, Inf, 1022, -Inf)

# for coxph
lung_pred <- tidyr::drop_na(lung)
mod <- coxph(Surv(time, status) ~ ., data = lung)
surv_fit <- survfit(mod, newdata = lung_pred[1:2, ])
summary(surv_fit, times = pred_time, extend = TRUE)
#> Call: survfit(formula = mod, newdata = lung_pred[1:2, ])
#> 
#>  time n.risk n.event survival1 survival2
#>  1022      1       0     0.117   0.00158
#>  -Inf    167       0     1.000   1.00000
#>     0    167       0     1.000   1.00000
#>   Inf      0       0     0.117   0.00158
#>  1022      1       0     0.117   0.00158
#>  -Inf    167       0     1.000   1.00000

# for general survfit
lung2 <- lung[-14, ]
lung_x <- as.matrix(lung2[, c("age", "ph.ecog")])
lung_y <- Surv(lung2$time, lung2$status)
lung_pred <- lung_x[1:2, ]

mod <- suppressWarnings(
  glmnet::glmnet(x = lung_x, y = lung_y, family = "cox")
)
surv_fit <- survfit(mod, newx = lung_pred, s = 0.1, x = lung_x, y = lung_y)
summary(surv_fit, times = pred_time, extend = TRUE)
#> Call: survfit.coxnet(formula = mod, s = 0.1, newx = lung_pred, x = lung_x, 
#>     y = lung_y)
#> 
#>  time n.risk n.event survival1 survival2
#>  1022      1       0    0.0476    0.0969
#>  -Inf    227       0    1.0000    1.0000
#>     0    227       0    1.0000    1.0000
#>   Inf      0       0    0.0476    0.0969
#>  1022      1       0    0.0476    0.0969
#>  -Inf    227       0    1.0000    1.0000

Created on 2024-06-09 with reprex v2.1.0

With survival 3.6-4

library(survival)
library(glmnet)
#> Loading required package: Matrix
#> Loaded glmnet 4.1-8

pred_time <- c(1022, -Inf, 0, Inf, 1022, -Inf)

# for coxph
lung_pred <- tidyr::drop_na(lung)
mod <- coxph(Surv(time, status) ~ ., data = lung)
surv_fit <- survfit(mod, newdata = lung_pred[1:2, ])
summary(surv_fit, times = pred_time, extend = TRUE)
#> Call: survfit(formula = mod, newdata = lung_pred[1:2, ])
#> 
#>  time n.risk n.event survival1 survival2
#>     0    167       0     1.000   1.00000
#>  1022      1     120     0.117   0.00158
#>  1022      1       0     0.117   0.00158

# for general survfit
lung2 <- lung[-14, ]
lung_x <- as.matrix(lung2[, c("age", "ph.ecog")])
lung_y <- Surv(lung2$time, lung2$status)
lung_pred <- lung_x[1:2, ]

mod <- suppressWarnings(
  glmnet::glmnet(x = lung_x, y = lung_y, family = "cox")
)
surv_fit <- survfit(mod, newx = lung_pred, s = 0.1, x = lung_x, y = lung_y)
summary(surv_fit, times = pred_time, extend = TRUE)
#> Call: survfit.coxnet(formula = mod, s = 0.1, newx = lung_pred, x = lung_x, 
#>     y = lung_y)
#> 
#>  time n.risk n.event survival1 survival2
#>     0    227       0    1.0000    1.0000
#>  1022      1     164    0.0476    0.0969
#>  1022      1       0    0.0476    0.0969

Created on 2024-06-09 with reprex v2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions