Trains a Cox proportional hazards model with Ridge regularization
using glmnet
.
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
, and best_lambda
.
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
ridge_model <- ridge_pro(X_data, Y_surv_obj)
print(ridge_model$finalModel)
#>
#> Call: glmnet::glmnet(x = X_matrix, y = y_surv, family = "cox", alpha = 0, lambda = best_lambda)
#>
#> Df %Dev Lambda
#> 1 10 1.89 3.33