Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Example online
- # Load library
- library(pROC)
- ### Actual outcomes
- outcomes <- c(rep(0,27),(rep(1,76)))
- # Set seed
- set.seed(42)
- ### Prediction Method 1
- pred1 <- c(rep(0,4),(rep(1,99)))
- ### Prediction Method 2
- pred2 <- c(rnorm(27,mean=0.3, sd=0.2),rnorm(76,mean=0.5, sd=0.2))
- # Compare ROC
- roc1 <- roc(outcomes,pred1)
- roc2 <- roc(outcomes,pred2)
- plot(roc1, print.auc=F, lty=2, xlim=c(1,0), lwd=3)
- text(0.15, 0.1, labels=sprintf("Method1|AUC: %0.3f", auc(roc1)), col="black")
- lines(roc2, col="green", lty=4, lwd=3)
- text(0.15, 0.05, labels=sprintf("Metod2|AUC: %0.3f", auc(roc2)), col="green")
- # Compare confusion matrices
- confusionMatrix(factor(outcomes),factor(pred1))
- confusionMatrix(factor(outcomes),factor((pred2>=0.35)*1))
Advertisement
Add Comment
Please, Sign In to add comment