I'm new to cross-validation. To understand the process, I just did k-10 cross-validation with 10 repeats, using the Caret package on my data using logistic regression with two predictors:
# creating hypothetical data
x1 = rnorm(47, mean = 45, sd = 5); x2 = rnorm(107, mean = 50, sd = 3);
z1 = rnorm(47, mean = 13, sd = 1.3); z2 = rnorm(107, mean = 15, sd = 2.3)
Y0 = rep("No", 107);Y1 = rep("Yes",47)
a = c(x2,x1); b = c(z2,z1); c = c(Y0,Y1);
data = as.data.frame(cbind(c,a,b)); names(data) = c("Group","Class1","Class2"); data$Group = as.factor(data$Group)
library(caret);library(pROC)
set.seed(1); train.control <- trainControl(method="repeatedcv", number=10, repeats = 10,
summaryFunction = twoClassSummary,
savePredictions = "all",classProbs = TRUE)
set.seed(1); model <- train(Group ~ Class1+Class2, data = data, method = "glm", family="binomial",
trControl = train.control)
Learning from previous a post, I figured the following script would produce an "overall" cross-validated AUC plot
plot(roc(response = model$pred$obs, predictor = model$pred$Yes))
But this plot produces the concatenated observation/predicted value of all 10k x 10 repeats iterations, not something I want. Since the output AUC is an average of AUC of iterations, which is the same as mean(model$Resample$ROC), I want to plot this average AUC.
Looking at the output of model$pred, I understand that the first 15 or so rows are the first fold of a specific repeat (as in model$pred$Resample), and the next 15 or so iteration is the second, and so on.
I want to take/segment the vectors of predicted and observed values for each fold.Repeat., calculate the mean for each point, and then plot the average of ROC (cross-validated ROC/AUC). I conceptually get it, but I can't come up with the specific code (especially because the length of each iteration is different).
I also want to obtain 95%CI of the AUC and do the same process with another different variable and overlap the two cross-validated average AUCs to visually show the differences. Can someone solve this, please? Thank you!