Trains a Cox proportional hazards model and performs backward
stepwise selection using MASS::stepAIC
to select important features.
Arguments
- X
A data frame of features.
- y_surv
A
survival::Surv
object representing the survival outcome.- tune
Logical, whether to perform hyperparameter tuning (currently ignored).
Value
A list of class "train" containing the trained coxph
model object
after stepwise selection, names of features used in training, and model type.
The returned object also includes fitted_scores
(linear predictor) and y_surv
.
Examples
set.seed(42)
n_samples <- 50
n_features <- 5
X_data <- as.data.frame(matrix(rnorm(n_samples * n_features), ncol = n_features))
Y_surv_obj <- survival::Surv(
time = runif(n_samples, 100, 1000),
event = sample(0:1, n_samples, replace = TRUE)
)
# Train the model
stepcox_model <- stepcox_pro(X_data, Y_surv_obj)
print(stepcox_model$finalModel)
#> Call: survival::coxph(formula = y_surv_ ~ 1, data = data_for_cox)
#>
#> Null model
#> log likelihood= -70.22957
#> n= 50