Skip to content

Commit

Permalink
add as.numeric method
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Nov 14, 2024
1 parent 454b24a commit ac1e372
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions R/performance_roc.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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)
Expand Down Expand Up @@ -118,6 +119,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 ---------------------------

Expand Down
12 changes: 12 additions & 0 deletions man/performance_roc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac1e372

Please sign in to comment.