library(data.table)
n <- 200
set.seed(10)
X <- rnorm(n)
dt <- data.table(Y = as.factor(rbinom(n, size = 1, prob = 1/(1+exp(1/2-X)))),
X = X,
fold = unlist(lapply(1:10,function(iL){rep(iL,n/10)})))
## compute auc
auc(labels = dt$Y, predictions = dt$X, direction = ">")
## compute auc after 10-fold cross-validation
auc(labels = dt$Y, prediction = dt$X, fold = dt$fold, observation = 1:NROW(dt))
Run the code above in your browser using DataLab