Session 4
ROC (Receiver Operating Characteristic) Analysis
Session Contents
  • ROC curve
Positive Correlation
Negative Correlation
Performing and Plotting ROC Analysis in R

To create a ROC curve, you need a **numeric predictor** and a **binary outcome**. The ROC curve evaluates how well the predictor discriminates between categories.

# Load necessary library
library(pROC)   

# Convert categorical variable to binary (1 = "Yes", 0 = "No")
data$Outcome_binary <- ifelse(data$Outcome == "Yes", 1, 0)

# Compute ROC curve
roc_model <- roc(data$Outcome_binary, data$Score)

# Plot ROC curve
plot(roc_model, col = "blue", main = "ROC Curve")
abline(a = 0, b = 1, lty = 2, col = "gray")  # Random classifier line
auc(roc_model)  # Calculate AUC
Key Statistics of the ROC Curve

The ROC curve evaluates a model’s classification performance by plotting sensitivity vs. 1-specificity.

  • True Positive Rate (TPR) / Sensitivity: Proportion of actual positives correctly identified.
  • False Positive Rate (FPR): Proportion of actual negatives incorrectly classified as positive.
  • Area Under the Curve (AUC): Measures overall model performance (0.5 = random, 1.0 = perfect).
  • Optimal Threshold: The probability cutoff that maximizes sensitivity and specificity.