This function returns the ROC curve and computes the area under the curve (AUC) for binary classifiers.
roc.curve(response, predicted, plotit = TRUE, add.roc = FALSE,
n.thresholds=100, ...)
A vector of responses containing two classes to be used to compute the ROC curve. It can be of class "factor"
, "numeric"
or "character"
.
A vector containing a prediction for each observation. This can be of class "factor"
or "character"
if the predicted label classes are provided or "numeric"
for the probabilities of the rare class (or a monotonic function of them).
Logical, if TRUE
the ROC curve is plotted in a new window. Default value is set to TRUE
.
Logical, if TRUE
the ROC curve is added to an existing window. Default value is set to FALSE
.
Number of thresholds
at which the ROC curve is computed.
Default value is the minimum between 100 and the number of elements in response
.
A value of n.thresholds
greater than the length of response
is ignored.
Further arguments to be passed either to plot
or lines
.
The value is an object of class roc.curve
which has components
The matched call.
The value of the area under the ROC curve.
The false positive rate (or equivalently the complement of sensitivity) of the classifier at the evaluated thresholds
.
The true positive rate (or equivalently the specificity) of the classifier at the evaluated thresholds
.
Thresholds at which the ROC curve is evaluated.
Fawcet T. (2006). An introduction to ROC analysis. Pattern Recognition Letters, 27 (8), 861--875.
# NOT RUN {
# 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)
# }
Run the code above in your browser using DataLab