R: How to calculate AUC and ROC curve for object 'bgeva' objekt / model?

Since I have data with a binary answer, but with rare events, I would like to improve its forecast by setting a model bgevainstead of a model gam. In order to prove and compare its prediction accuracy and compare it with other models that I tried, I need to calculate the AUC and plot the ROC curve.

The problem is that my code that works with glmand gamdoes not work with the object bgeva. Exactly, using the function predict()prints an error: no applicable method for 'predict' applied to an object of class "bgeva" and my friend Google did not find any solution for me.

Here is one simple example from the package bgeva()and the code that I used to calculate the AUC, and plot the ROC curve for the objects glmand gam:

library(bgeva)

set.seed(0)
n <- 1500
x1 <- round(runif(n))
x2 <- runif(n)
x3 <- runif(n)
f1 <- function(x) (cos(pi*2*x)) + sin(pi*x)
f2 <- function(x) (x+exp(-30*(x-0.5)^2))
y <- as.integer(rlogis(n, location = -6 + 2*x1 + f1(x2) + f2(x3), scale  = 1) > 0)
dataSim <- data.frame(y,x1,x2,x3)

################
# bgeva model: #
################
out <- bgeva(y ~ x1 + s(x2) + s(x3))

# AUC for bgeva (does not work)##################################
library(ROCR)
pred <-as.numeric(predict(out, type="response", newdata=dataSim))
rp <- prediction(pred, dataSim$y) 
auc <- performance( rp, "auc")@y.values[[1]]
auc

################
# gam model:   #
################
library(mgcv)

out_gam <- gam(y ~ x1 + s(x2) + s(x3), family=binomial(link=logit))

# AUC and ROC for gam (the same code, works with gam) ############
 pred_gam <-as.numeric(predict(out_gam, type="response"))
 rp_gam <- prediction(pred_gam, dataSim$y)

 auc_gam <- performance( rp_gam, "auc")@y.values[[1]]
 auc_gam

 roc_gam <- performance( rp_gam, "tpr", "fpr")
 plot(roc_gam)
+4
source share

All Articles