ROCcurve: Plot a ROC curve

View source: R/plotROC.R

ROCcurveR Documentation

Plot a ROC curve

Description

Plot a ROC curve from a caret model.

Usage

ROCcurve(model, ...)

## S3 method for class 'train'
ROCcurve(
  model,
  testdata = NULL,
  testy = NULL,
  testindex = NULL,
  thrs = NULL,
  use.pROC = FALSE,
  calc.train = TRUE,
  errorFunction = ci_95,
  ...
)

## S3 method for class 'ROCcurve'
plot(
  x,
  type = "facet",
  select.thr = "all",
  plot_ci = TRUE,
  add.text = TRUE,
  ...
)

Arguments

model

A model or a list of models returned by train.

...

Arguments passed to predict. Don't use object, newdata, type.

testdata

A data.frame with test values to be use in ROC curve. If NULL, training values will be used.

testy

A factor of response variable of testdata. If NULL, it will be guessed from testdata data.frame.

testindex

A list with rows index of testdata for each resample, preferably an output of create.test.index or create.test.index.blockCV. If NULL, indexes are create based on the same methods provided by trainControl used in the model. Ignored if use.pROC = TRUE.

thrs

A named vector with thresholds values between [0,1] to be plotted in the ROC curve or the output of thresholder2. If model is a list, this should be also a list of the same ordet with thresholds to be applied for each model.

use.pROC

logical. If TRUE, use roc to compute the ROC curve and confidence intervals. If FALSE, use "model" and "testindex" resamples instead.

calc.train

logical. If FALSE, ROC curve for train data is not computed.

errorFunction

A function used to calculate confidence interval across resamples. Function is ignored if use.pROC = TRUE. Else, the ROC curve is calculated from the mean between resamples. If NULL, confidence interval is not calculated and all train and test data are used to calculate the curve. Default is 95% confidence interval.

x

An objected returned by ROCcurve.

type

one of "facet", "train" or "test".

select.thr

"all", "none" or a vector with indices of thresholds to plot.

plot_ci

logical. Plot confidence intervals?

add.text

logical. Plot threshold methods names?

Value

An S3 object of class 'ROCcurve', including:

dat.roc

A data.table with values of Sensitivity and Specificity to plot the ROC curve.

thrs

A data.table with Sensitivity and Specificity for each threshold provided by thrs.

coords

A data.table with the coordinates to plot the confidence interval.

See Also

evaluate confusionMatrix2

Examples

## Not run: 
# using pROC package
ROCcurve(model, use.pROC = TRUE)

# using caret resamples, with testdata and thresholds
testindex <- create.test.index(testy)
thrs <- thresholder2(model)
r.obj <- ROCcurve(model, testdata, testy, testindex, thrs, use.pROC = FALSE)

plot(r.obj, type = "facet", select.thr = 3:7, plot_ci = TRUE, add.text = FALSE)

# for multiple models
models <- list(model1, model2, model3)
thrs <- lapply(models, thresholder2)
r.obj <- ROCcurve(models, thrs, testdata, testindex=testindex)
plot(r.obj, type = "test", select.thr = 3:7, plot_ci = FALSE, add.text = TRUE)

## End(Not run)

correapvf/caretSDM documentation built on June 2, 2022, 8:29 a.m.