50  statusPartition()

The examples in Chapter 50 require (see the explanation of the function name conflict in Section 7.4)

library(maxEff)
# Loading required package: groupedHyperframe
# Registered S3 method overwritten by 'pROC':
#   method   from            
#   plot.roc spatstat.explore

Function maxEff::statusPartition() (v0.2.1)

  1. splits a left-censored survival::Surv object by its survival status, i.e., observed versus left-censored;
  2. partitions the observed and left-censored subjects, respectively, into test/training sets.

See Section 12.2 for the usage of the terms “split” versus “partition”.

Listing 50.1 creates a Surv object capacitor_failure from the example data frame capacitor from package survival (Therneau 2024, v3.8.3),

Listing 50.1: Data: left-censored Surv object capacitor_failure
capacitor_failure = survival::capacitor |> 
  with(expr = survival::Surv(time, status))
capacitor_failure
#  [1]  439   904  1092  1105   572   690   904  1090   315   315   439   628   258   258   347   588   959  1065  1065  1087   216   315   455   473   241   315   332   380   241   241   435   455 
# [33] 1105+ 1105+ 1105+ 1105+ 1090+ 1090+ 1090+ 1090+  628+  628+  628+  628+  588+  588+  588+  588+ 1087+ 1087+ 1087+ 1087+  473+  473+  473+  473+  380+  380+  380+  380+  455+  455+  455+  455+

Function statusPartition() (Listing 50.2) intends to avoid the situation that a Cox proportional hazards model survival::coxph() in one or more of the partitioned data set being degenerate due to the fact that all subjects in that partition being censored.

Listing 50.2: Example: statusPartition(), balanced by survival status (Listing 50.1)
set.seed(12); id = capacitor_failure |>
  statusPartition(times = 1L, p = .5) |>
  unlist()
capacitor_failure[id, 2L] |> 
  table()
# 
#  0  1 
# 16 16

Function statusPartition() is an extension of the very popular function caret::createDataPartition() (Listing 50.3), which stratifies a Surv object by the quantiles of its survival time (as of package caret v7.0.1).

Listing 50.3: Review: caret::createDataPartition(), not balanced by survival status (Listing 50.1)
set.seed(12); id0 = capacitor_failure |>
  caret::createDataPartition(times = 1L, p = .5) |>
  unlist()
capacitor_failure[id0, 2L] |> 
  table()
# 
#  0  1 
# 19 14