3

I'm trying to make a ROC curve using plotly.js with the values obtained in R.

In plotly, I have to fill out the values(x-axis, y-axis) to make a plot.

But, I don't know how to get the values when I use Logistic Regression function glm or multinom(in nnet packages).

df <- data.frame(age = c(10, 20, 30, 40, 50),height = c(150, 161, 141, 155, 180), house = c("0", "0", "0", "1", "1"))
smp_size <- floor(nrow(df) * (0.6))
train_idx <- sample(seq_len(nrow(df)), size = smp_size)

train <- df[train_idx, ]
validation <- df[-train_idx, ]

validation_x <- validation[c("age", "height")]
validation_y <- validation[["house"]]

m <- glm(house ~ age + height, data = train, family = 'binomial')
y_pred <- predict(m, validation_x)

library(plotROC)
plotROC(validation_y, y_pred)

I want to know how to get the values of x-axis(FPR) and y-axis(TPR) in ROC curve

thank you.

Darren Tsai
  • 32,117
  • 5
  • 21
  • 51
ynjo
  • 97
  • 6

1 Answers1

3

Use the function roc() in package pROC:

# install.packages("pROC")
library(pROC)
my.roc <- roc(validation_y, y_pred)

roc() returns a list recording specificities(x-axis), sensitivities(y-axis), thresholds, AUC, and other information. You can use $ to extract them:

my.roc$specificities
my.roc$sensitivities
Darren Tsai
  • 32,117
  • 5
  • 21
  • 51