roc.curve {ROSE} | R Documentation |
ROC curve
Description
This function returns the ROC curve and computes the area under the curve (AUC) for binary classifiers.
Usage
roc.curve(response, predicted, plotit = TRUE, add.roc = FALSE,
n.thresholds=100, ...)
Arguments
response |
A vector of responses containing two classes to be used to compute the ROC curve. It can be of class |
predicted |
A vector containing a prediction for each observation. This can be of class |
plotit |
Logical, if |
add.roc |
Logical, if |
n.thresholds |
Number of |
... |
Further arguments to be passed either to |
Value
The value is an object of class roc.curve
which has components
Call |
The matched call. |
auc |
The value of the area under the ROC curve. |
false positive rate |
The false positive rate (or equivalently the complement of sensitivity) of the classifier at the evaluated |
true positive rate |
The true positive rate (or equivalently the specificity) of the classifier at the evaluated |
thresholds |
Thresholds at which the ROC curve is evaluated. |
References
Fawcet T. (2006). An introduction to ROC analysis. Pattern Recognition Letters, 27 (8), 861–875.
See Also
Examples
# 2-dimensional example
# loading data
data(hacide)
# check imbalance on training set
table(hacide.train$cls)
# model estimation using logistic regression
fit.hacide <- glm(cls~., data=hacide.train, family="binomial")
# prediction on training set
pred.hacide.train <- predict(fit.hacide, newdata=hacide.train)
# plot the ROC curve (training set)
roc.curve(hacide.train$cls, pred.hacide.train,
main="ROC curve \n (Half circle depleted data)")
# check imbalance on test set
table(hacide.test$cls)
# prediction using test set
pred.hacide.test <- predict(fit.hacide, newdata=hacide.test)
# add the ROC curve (test set)
roc.curve(hacide.test$cls, pred.hacide.test, add=TRUE, col=2,
lwd=2, lty=2)
legend("topleft", c("Resubstitution estimate", "Holdout estimate"),
col=1:2, lty=1:2, lwd=2)