library(MASS)
library(pROC)
Default <- read.csv("Default.csv")
Default$default_bin <- ifelse(Default$default == "Yes", 1, 0)
# Table 4.1: Logistic Regression - balance only
model_4_1 <- glm(default_bin ~ balance, data = Default, family = binomial)
# Table 4.2: Logistic Regression - student + balance + income
model_4_2 <- glm(default_bin ~ student + balance + income, data = Default, family = binomial)
# Table 4.3: LDA - balance only
model_4_3 <- lda(default ~ balance, data = Default)
# Predicted probabilities
prob_4_1 <- predict(model_4_1, type = "response")
prob_4_2 <- predict(model_4_2, type = "response")
prob_4_3 <- predict(model_4_3)$posterior[, "Yes"]
# ROC curves
roc_4_1 <- roc(Default$default_bin, prob_4_1)
roc_4_2 <- roc(Default$default_bin, prob_4_2)
roc_4_3 <- roc(Default$default_bin, prob_4_3)
# Plot
plot(roc_4_1, col = "blue", lwd = 2,
main = "ROC Curves — Default Dataset\n(Models from Tables 4.1, 4.2 & 4.3)",
xlab = "False Positive Rate", ylab = "True Positive Rate")
plot(roc_4_2, col = "darkgreen", lwd = 2, add = TRUE)
plot(roc_4_3, col = "red", lwd = 2, lty = 2, add = TRUE)
abline(a = 0, b = 1, lty = 3, col = "gray")
legend("bottomright",
legend = c(
paste0("Table 4.1: LR (Balance only) — AUC = ", round(auc(roc_4_1), 3)),
paste0("Table 4.2: LR (Balance+Student+Income) — AUC = ", round(auc(roc_4_2), 3)),
paste0("Table 4.3: LDA (Balance only) — AUC = ", round(auc(roc_4_3), 3))
),
col = c("blue", "darkgreen", "red"),
lwd = 2, lty = c(1, 1, 2),
cex = 0.85)
