── Step 1: Install packages (only needed once) ──

install.packages(“pROC”) install.packages(“ggplot2”)

── Step 2: Load packages ──

library(pROC) library(ggplot2)

── Step 3: Load data (file browser will pop up) ──

df <- read.csv(file.choose())

── Step 4: Prepare variables ──

df\(default_bin <- ifelse(df\)default == “Yes”, 1, 0) df\(student_bin <- ifelse(df\)student == “Yes”, 1, 0)

── Step 5: Fit 3 Logistic Regression Models ──

model1 <- glm(default_bin ~ balance, data = df, family = binomial) model2 <- glm(default_bin ~ student_bin, data = df, family = binomial) model3 <- glm(default_bin ~ balance + income + student_bin, data = df, family = binomial)

── Step 6: Compute ROC curves ──

roc1 <- roc(df\(default_bin, predict(model1, type = "response")) roc2 <- roc(df\)default_bin, predict(model2, type = “response”)) roc3 <- roc(df$default_bin, predict(model3, type = “response”))

── Step 7: Print AUC Summary ──

cat(“=== AUC Summary ===”) cat(sprintf(“Table 4.1 - Balance only: AUC = %.4f”, auc(roc1))) cat(sprintf(“Table 4.2 - Student only: AUC = %.4f”, auc(roc2))) cat(sprintf(“Table 4.3 - Balance + Income + Student: AUC = %.4f”, auc(roc3)))

── Step 8: Build data frames for ggplot ──

make_roc_df <- function(roc_obj, label) { data.frame( FPR = 1 - roc_obj\(specificities, TPR = roc_obj\)sensitivities, Model = label ) }

roc_df <- rbind( make_roc_df(roc1, sprintf(“Table 4.1: Balance only= %.4f”, auc(roc1))), make_roc_df(roc2, sprintf(“Table 4.2: Student only= %.4f”, auc(roc2))), make_roc_df(roc3, sprintf(“Table 4.3: Balance + Income + Student= %.4f”, auc(roc3))) )

── Step 9: Plot ──

ggplot(roc_df, aes(x = FPR, y = TPR, color = Model)) + geom_abline(slope = 1, intercept = 0, linetype = “dashed”, color = “gray50”, linewidth = 0.8) + geom_line(linewidth = 1.2) + facet_wrap(~ Model) + scale_color_manual(values = c(“#ff4d6d”, “#ffd166”, “#4dffb4”)) + labs( title = “ROC Curves — Default Dataset”, subtitle = “Tables 4.1, 4.2, 4.3 (Logistic Regression)”, x = “False Positive Rate”, y = “True Positive Rate” ) + theme_minimal(base_size = 12) + theme( legend.position = “none”, strip.text = element_text(size = 9, face = “bold”), plot.title = element_text(face = “bold”, size = 14), plot.subtitle = element_text(color = “gray50”) )