Learn R Programming

ROSE (version 0.0-4)

roc.curve: 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 "factor", "numeric" or "character".

predicted

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).

plotit

Logical, if TRUE the ROC curve is plotted in a new window. Default value is set to TRUE.

add.roc

Logical, if TRUE the ROC curve is added to an existing window. Default value is set to FALSE.

n.thresholds

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.

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 thresholds.

true positive rate

The true positive rate (or equivalently the specificity) of the classifier at the evaluated thresholds.

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

accuracy.meas, roc.

Examples

Run this code
# 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