View source: R/PrognosticModel.R
| PrognosticModel | R Documentation |
Prepares 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.
PrognosticModel(
x,
y,
scale = FALSE,
seed = 123456,
train_ratio = 0.7,
nfold = 10,
plot = TRUE,
palette = "jama",
cols = NULL
)
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. |
A list containing:
Results from LASSO model including coefficients and AUC
Results from Ridge model including coefficients and AUC
Training data with sample IDs
Dongqiang Zeng
if (requireNamespace("glmnet", quietly = TRUE) &&
requireNamespace("survival", quietly = TRUE)) {
library(survival)
set.seed(123)
# Create small example data (first column must be ID)
x_sim <- as.data.frame(matrix(rnorm(100 * 5), 100, 5))
colnames(x_sim) <- paste0("Sig", 1:5)
x_sim$ID <- paste0("S", 1:100)
x_sim <- x_sim[, c(6, 1:5)] # Move ID to first column
y_sim <- data.frame(
ID = paste0("S", 1:100),
OS_days = rexp(100, 0.01),
OS_status = rbinom(100, 1, 0.5)
)
prognostic_result <- PrognosticModel(
x = x_sim, y = y_sim,
scale = TRUE, seed = 123456,
train_ratio = 0.7, nfold = 3, plot = FALSE
)
if (!is.null(prognostic_result)) head(prognostic_result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.