Build Prognostic Models Using LASSO and Ridge Regression
Source:R/PrognosticModel.R
PrognosticModel.RdPrepares data, splits it into training and testing sets, and fits LASSO and Ridge regression models for survival analysis. Evaluates model performance using cross-validation and optionally generates time-dependent ROC curves for visual assessment of predictive accuracy.
Usage
PrognosticModel(
x,
y,
scale = FALSE,
seed = 123456,
train_ratio = 0.7,
nfold = 10,
plot = TRUE,
palette = "jama",
cols = NULL
)Arguments
- x
A matrix or data frame of predictor variables (features).
- y
A data frame of survival outcomes with two columns: survival time and event status.
- scale
Logical indicating whether to scale predictor variables. Default is `FALSE`.
- seed
Integer seed for random number generation to ensure reproducibility. Default is `123456`.
- train_ratio
Numeric proportion of data for training (e.g., 0.7). Default is `0.7`.
- nfold
Integer number of folds for cross-validation. Default is `10`.
- plot
Logical indicating whether to plot ROC curves. Default is `TRUE`.
- palette
String specifying color palette. Default is `"jama"`.
- cols
Optional vector of colors for ROC curves. If `NULL`, uses default palette.
Value
A list containing:
- lasso_result
Results from LASSO model including coefficients and AUC
- ridge_result
Results from Ridge model including coefficients and AUC
- train.x
Training data with sample IDs
Examples
# \donttest{
if (requireNamespace("glmnet", quietly = TRUE) &&
requireNamespace("survival", quietly = TRUE)) {
library(survival)
imvigor210_sig <- load_data("imvigor210_sig")
imvigor210_pdata <- load_data("imvigor210_pdata")
pdata_prog <- data.frame(
ID = imvigor210_pdata$ID,
OS_days = as.numeric(imvigor210_pdata$OS_days),
OS_status = as.numeric(imvigor210_pdata$OS_status)
)
prognostic_result <- PrognosticModel(
x = imvigor210_sig, y = pdata_prog,
scale = TRUE, seed = 123456,
train_ratio = 0.7, nfold = 10, plot = FALSE
)
}
#> ℹ Processing data
#> ℹ Splitting data into training and validation sets
#> ℹ Running LASSO
#> ℹ Running RIDGE REGRESSION
#> ✔ Model fitting complete
# }