Skip to contents

Applies a previously trained prognostic model (or ensemble) to a new, unseen dataset to generate prognostic scores.

Usage

apply_pro(trained_model_object, new_data, time_unit = "day")

Arguments

trained_model_object

A trained model object, as returned by models_pro, bagging_pro, or stacking_pro.

new_data

A data frame containing the new data for prediction. It should follow the same structure as the training data: ID, Outcome, Time, Features. The outcome and time columns are used for data preparation and can be included in the output, but the model's prediction only uses the features. If outcome/time are unknown, they can be filled with NA.

time_unit

A character string, the unit of time in the third column of new_data.

Value

A data frame with ID, outcome, time, and predicted score for the new data.

Examples

# \donttest{
# NOTE: This example requires 'train_pro' and 'test_pro' datasets.
if (requireNamespace("E2E", quietly = TRUE) &&
    "train_pro" %in% utils::data(package = "E2E")$results[,3] &&
    "test_pro" %in% utils::data(package = "E2E")$results[,3]) {

  data(train_pro, package = "E2E")
  data(test_pro, package = "E2E")
  initialize_modeling_system_pro()

  train_results <- models_pro(data = train_pro, model = "lasso_pro")
  trained_lasso_model <- train_results$lasso_pro$model_object

  # Apply the trained model to new data
  new_data_predictions <- apply_pro(
    trained_model_object = trained_lasso_model,
    new_data = test_pro,
    time_unit = "day" # Specify time unit of test_pro
  )
  utils::head(new_data_predictions)
}
#> Prognosis modeling system initialized and default models registered.
#> Running model: lasso_pro
#> Applying model on new data...
#>                             ID outcome time      score
#> 1 TCGA-AN-A0AM-01A-11R-A034-07       0    5 -0.2218588
#> 2 TCGA-AN-A0XR-01A-11R-A109-07       0   10  0.3724818
#> 3 TCGA-AN-A0XT-01A-11R-A109-07       0   10  1.4469934
#> 4 TCGA-AN-A0AT-01A-11R-A034-07       0   10  0.2098832
#> 5 TCGA-AN-A03X-01A-21R-A00Z-07       0   10  0.7699643
#> 6 TCGA-AN-A0XS-01A-22R-A109-07       0   10  0.2374950
# }