user8818397
user8818397

Reputation:

How to plot ROC curve in R given only a linear regression equation

I'm trying to plot an ROC curve in R and find the area under it (AUC), given only a regression equation.

Usually, when I have a GLM I would use the command predict to do this. For example:

library("pROC")
lin_mod <- glm(y ~ p + q, family = "...", data = dat_sd)
prob <- predict(lin_mod, type = c("response"))

The coefficients of the model are 0.3 (Intercept), -0.07 (p) and 0.11 (q). To plot the ROC and find the AUC, I use

plot(roc(dat_sd$y, prob), print.auc = TRUE)

However, when I only have the equation the command doesn't work:

library("pROC")    
lin_mod <- 0.3 - 0.07 * dat_sd$p + 0.11 * dat_sd$q
predict(lin_mod, type = c("response"))

outputs

Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "c('double', 'numeric')"

What should I do to successfully plot the curve (and find the area)?

Upvotes: 2

Views: 4995

Answers (1)

Calimo
Calimo

Reputation: 7969

The following line is your predicted response from the data already:

lin_mod <- 0.3 - 0.07 * dat_sd$p + 0.11 * dat_sd$q

Just pass that response variable to pROC directly:

plot(roc(dat_sd$y, lin_mod), print.auc = TRUE)

Upvotes: 1

Related Questions