Last active
September 8, 2022 12:52
-
-
Save epijim/316cff77948ffb9b292ae615aacab922 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
score_auc <- function( | |
predictions, | |
truth | |
){ | |
if (!"patientid" %in% names(predictions)) stop("patientid missing from predictions") | |
if (!"prediction" %in% names(predictions)) stop("prediction missing from predictions") | |
if (!"patientid" %in% names(truth)) stop("patientid missing from truth") | |
if (!"has_long_covid_diag" %in% names(truth)) stop("has_long_covid_diag missing from truth") | |
if (sum(is.na(predictions)) != 0) stop("Missing data detected in predictions") | |
if (min(predictions$prediction) < 0) stop("Predictions can't be less than 0") | |
if (max(predictions$prediction) > 1) stop("Predictions can't be more than 1") | |
merged_data <- truth %>% | |
dplyr::select(patientid,has_long_covid_diag) %>% | |
dplyr::mutate( | |
has_long_covid_diag = factor(has_long_covid_diag, levels = c("1","0")) | |
) %>% | |
dplyr::left_join( | |
predictions %>% | |
dplyr::select(patientid, prediction), | |
by = "patientid" | |
) | |
yardstick::roc_auc( | |
merged_data, | |
has_long_covid_diag, | |
prediction, | |
estimator = "binary" | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment