Skip to content

Instantly share code, notes, and snippets.

@jxnl
Last active April 13, 2016 20:05
Show Gist options
  • Save jxnl/ab589258e67fdbffb134b161b33dc437 to your computer and use it in GitHub Desktop.
Save jxnl/ab589258e67fdbffb134b161b33dc437 to your computer and use it in GitHub Desktop.
common snippet for ROC TESTS
library(pROC)
df = read.csv("...")
## 75% of the sample size
set.seed(123)
smp_size <- floor(0.75 * nrow(df))
train_ind <- sample(seq_len(nrow(df)), size = smp_size)
train <- df[train_ind, ]
test <- df[-train_ind, ]
# Training a null model
null = glm(y ~ a, data = train)
# Training a full model
full = glm(y ~ ., data = train)
# making predictions and computing
p.null = predict.glm(null, test)
p.full = predict.glm(full, test)
p.true = test$y
# rocs
r.null = roc(p.true, p.null)
r.full = roc(p.true, p.full)
roc.test(r.null, r.full)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment