Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Details to performance_roc() #777

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 25 additions & 0 deletions R/performance_roc.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
#' @description This function calculates a simple ROC curves of x/y coordinates
#' based on response and predictions of a binomial model.
#'
#' It returns the area under the curve (AUC) as a percentage, which corresponds
#' to the probability that a randomly chosen observation of "condition 1" is correctly
#' classified by the model as having a higher probability of being "condition 1" than
#' a randomly chosen "condition 2" observation.
#'
#' Applying `as.data.frame()` to the output returns a data frame containing the following:
#' - `Sensitivity` (that actually corresponds to `1 - Specificity`): It is the False Positive Rate.
#' - `Sensitivity`: It is the True Positive Rate, which is the proportion of correctly classified "condition 1" observations.

Check warning on line 14 in R/performance_roc.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/performance_roc.R,line=14,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @param x A numeric vector, representing the outcome (0/1), or a model with
#' binomial outcome.
#' @param predictions If `x` is numeric, a numeric vector of same length
Expand Down Expand Up @@ -33,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 All @@ -53,7 +63,7 @@

object_names <- c(
insight::safe_deparse_symbol(substitute(x)),
sapply(match.call(expand.dots = FALSE)$`...`, insight::safe_deparse)

Check warning on line 66 in R/performance_roc.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/performance_roc.R,line=66,col=44,[keyword_quote_linter] Only quote targets of extraction with $ if necessary, i.e., if the name is not a valid R symbol (see ?make.names). Use backticks to create non-syntactic names, or use [[ to extract by string.
)

if (insight::is_model(x)) {
Expand Down Expand Up @@ -109,6 +119,21 @@
}


#' @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()

Check warning on line 129 in R/performance_roc.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/performance_roc.R,line=129,col=12,[unnecessary_concatenation_linter] Replace unnecessary c() by NULL or, whenever possible, vector() seeded with the correct type and/or length.
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.

Loading