diff --git a/NAMESPACE b/NAMESPACE index d35d82547..f3c9e008a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,6 +26,7 @@ S3method(as.data.frame,r2_bayes) S3method(as.data.frame,r2_loo) S3method(as.data.frame,r2_nakagawa) S3method(as.numeric,check_outliers) +S3method(as.numeric,performance_roc) S3method(check_autocorrelation,default) S3method(check_collinearity,BFBayesFactor) S3method(check_collinearity,MixMod) diff --git a/R/performance_roc.R b/R/performance_roc.R index 5cdd8d17f..e7d0f0006 100644 --- a/R/performance_roc.R +++ b/R/performance_roc.R @@ -46,6 +46,7 @@ #' #' model <- glm(y ~ Sepal.Length + Sepal.Width, data = train_data, family = "binomial") #' as.data.frame(performance_roc(model, new_data = test_data)) +#' as.numeric(performance_roc(model)) #' #' roc <- performance_roc(model, new_data = test_data) #' area_under_curve(roc$Specificity, roc$Sensitivity) @@ -122,6 +123,21 @@ print.performance_roc <- function(x, ...) { } +#' @export +as.numeric.performance_roc <- function(x, ...) { + if (length(unique(x$Model)) == 1) { + auc <- bayestestR::area_under_curve(x$Specificity, x$Sensitivity) + } else { + dat <- split(x, f = x$Model) + + auc <- c() + for (i in seq_along(dat)) { + auc <- c(auc, bayestestR::area_under_curve(dat[[i]]$Specificity, dat[[i]]$Sensitivity)) + } + } + auc +} + # utilities --------------------------- @@ -181,5 +197,5 @@ print.performance_roc <- function(x, ...) { if (inherits(x, "model_fit")) { x <- x$fit } - inherits(x, c("glm", "glmerMod", "logitor", "logitmfx", "probitmfx")) + inherits(x, c("glm", "glmerMod", "logitor", "logitmfx", "probitmfx", "glmmTMB")) } diff --git a/man/performance_roc.Rd b/man/performance_roc.Rd index 1e116af70..48b473a42 100644 --- a/man/performance_roc.Rd +++ b/man/performance_roc.Rd @@ -59,6 +59,7 @@ train_data <- iris[-folds, ] model <- glm(y ~ Sepal.Length + Sepal.Width, data = train_data, family = "binomial") as.data.frame(performance_roc(model, new_data = test_data)) +as.numeric(performance_roc(model)) roc <- performance_roc(model, new_data = test_data) area_under_curve(roc$Specificity, roc$Sensitivity)