Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the values of x-axis(FPR) and y-axis(TPR) in ROC curve

Tags:

plot

r

roc

plotly

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.

like image 526
ynjo Avatar asked Dec 21 '25 18:12

ynjo


1 Answers

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
like image 89
Darren Tsai Avatar answered Dec 23 '25 09:12

Darren Tsai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!