roc.curves: Plot ROC Curves

roc.curvesR Documentation

Plot ROC Curves

Description

This function plots ROC Curves of one or several classification predictions.

Usage

roc.curves(
  predictions,
  gt,
  methods.names = NULL,
  positive = levels(factor(gt))[1],
  type = c("auto", "fuzzy", "hard"),
  ...
)

Arguments

predictions

The predictions of one or several classification models. Four shapes are accepted: a factor of hard labels (one model); a numeric vector of scores for the positive class (one model); a matrix of class probabilities, i.e. one column per class named after it, as returned by predict (model, x, fuzzy = TRUE) (one model); or any other matrix/data.frame, read as one column per model.

gt

Actual labels of the dataset (factor or vector), two classes only.

methods.names

The name of the compared methods (vector).

positive

The label of the positive class. Defaults to the first level of gt, as everywhere else in the package – note that for the usual alphabetical ordering this is often the negative class, so it is worth setting explicitly.

type

"auto" (default) reads predictions according to its shape, "fuzzy" requires scores and refuses hard labels, "hard" reduces everything to the predicted class first (this is the coarse three-point curve discussed above).

...

Other parameters, passed to the underlying plot.

Details

A ROC curve needs a score: the higher it is, the more likely the observation is to belong to the positive class. The natural one is the estimated probability returned by predict (model, x, fuzzy = TRUE). Hard class labels give only two distinct values, so the "curve" reduces to three points and the area under it says very little. That coarse version is available on purpose – it makes a useful comparison – but it has to be asked for: pass hard labels, or type = "hard".

Value

Nothing; the curves are drawn on the current graphics device.

See Also

cost.curves, performance

Examples

require (datasets)
data (iris)
d = iris
levels (d [, 5]) = c ("+", "+", "-") # Building a two classes dataset
model.nb = NB (d [, -5], d [, 5])
model.lda = LDA (d [, -5], d [, 5])
# From the estimated probabilities: the meaningful curve
roc.curves (predict (model.nb, d [, -5], fuzzy = TRUE), d [, 5], positive = "+")
# Two models compared, one score column each
roc.curves (cbind (NB = predict (model.nb, d [, -5], fuzzy = TRUE) [, "+"],
                   LDA = predict (model.lda, d [, -5], fuzzy = TRUE) [, "+"]),
            d [, 5], c ("NB", "LDA"), positive = "+")
# The same predictions reduced to hard labels: three points, and little to read
roc.curves (predict (model.nb, d [, -5]), d [, 5], positive = "+", type = "hard")

fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.