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
Exercise instructions
- Load the add-on package
pROC
by using the functionlibrary()
. - Obtain the observed purchases for
HOPPINESS
fromchoice.data
and assign them to an objectobserved
. - Create an
roc
object by using the functionroc
on the observed responses entailedchoice.data
and the predicted values obtained from theextended.model
. Assign the result to an object calledROC
. - Plot the ROC curve by using the function
plot()
on theROC
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