Trains a Cox proportional hazards model with Elastic Net regularization
using glmnet
(with alpha = 0.5).
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 simplified/ignored for direct
cv.glmnet
usage which inherently tunes lambda).
Value
A list of class "train" containing the trained glmnet
model object,
names of features used in training, and model type. The returned object
also includes fitted_scores
(linear predictor), y_surv
, best_lambda
, and alpha_val
.
Examples
set.seed(42)
n_samples <- 50
n_features <- 10
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
en_model <- en_pro(X_data, Y_surv_obj)
print(en_model$finalModel)
#>
#> Call: glmnet::glmnet(x = X_matrix, y = y_surv, family = "cox", alpha = alpha_val, lambda = best_lambda)
#>
#> Df %Dev Lambda
#> 1 2 4.27 0.2082