apply_dia: Apply a Trained Diagnostic Model to New Data

View source: R/diagnosis.R

apply_diaR Documentation

Apply a Trained Diagnostic Model to New Data

Description

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

Usage

apply_dia(
  trained_model_object,
  new_data,
  label_col_name = NULL,
  pos_class,
  neg_class
)

Arguments

trained_model_object

A trained model object, as returned by models_dia, bagging_dia, stacking_dia, voting_dia, or imbalance_dia.

new_data

A data frame containing the new data for prediction. The first column must be the sample ID, subsequent columns are features.

label_col_name

A character string, the name of the column containing the class labels in the new data. This is optional and only used to include true labels in the output; it is not used for prediction.

pos_class

A character string, the label for the positive class (must match the label used during training).

neg_class

A character string, the label for the negative class (must match the label used during training).

Value

A data frame with sample (ID), label (original numeric label from new data, or NA if not provided), and score (predicted probability for the positive class).

Examples


# 1. Assume 'train_dia' and 'test_dia' are loaded from your package
# data(train_dia)
# data(test_dia) # test_dia has same structure, maybe without the label column
initialize_modeling_system_dia()

# 2. Train a model
train_results <- models_dia(
  data = train_dia, model = "lasso",
  new_positive_label = "Case", new_negative_label = "Control"
)
trained_lasso_model <- train_results$lasso$model_object

# 3. Apply the trained model to new data
new_predictions <- apply_dia(
  trained_model_object = trained_lasso_model,
  new_data = test_dia,
  label_col_name = "Disease_Status", # Optional
  pos_class = "Case",
  neg_class = "Control"
)
utils::head(new_predictions)


E2E documentation built on Aug. 27, 2025, 1:09 a.m.