Get startedGet started for free

ROC curves

Cut-off values other than 0.5 can be chosen as well but, the number of potential cut-offs is high and looking at hundreds of tables can be time-consuming. Creating a ROC curve can help you.

Such a graph can be created by using the function roc() from the add-on package pROC. The function roc() takes as inputs the vector of observed responses (typically encoded as 0 and 1) and a vector of predicted values of the same length. Again, you obtain the observed HOPPINESS purchases from the choice.data object. The predicted values are obtained by applying the function fitted() on the extended.model object. The corresponding ROC curve is created by applying the function plot() on the resulting roc object.

This exercise is part of the course

Building Response Models in R

View Course

Exercise instructions

  • Load the add-on package pROC by using the function library().
  • Obtain the observed purchases for HOPPINESS from choice.data and assign them to an object observed.
  • Create an roc object by using the function roc on the observed responses entailed choice.data and the predicted values obtained from the extended.model. Assign the result to an object called ROC.
  • Plot the ROC curve by using the function plot() on the ROC object.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Load the pROC package

# Obtain the observed purchases
observed <- ___

# Create the Roc object
ROC <- roc(predictor = ___, response = ___)

# Plot the ROC curve
Edit and Run Code