R/cvrocs.R

# From meta/code/lib/R/MyClassifiers/R

#' #' View Model Comparison of cvROC by target and architecture
#' #'
#' #' aesthetic mappings:
#' #'     x=target
#' #'     y=ROC; ymin=ROC-SD; ymax=ROC+SD
#' #'     col=model_architecture
#' #'
#' #' @param Comparison a `MyClassifiers::Comparison` class object
#' #'
#' #' @return ggplot2 object of pointrange plot
#' #' @export
#' #'
#' #' @examples
#' #' .Viz.Comparison.cvroc(Comparison) %>%
#' #'     ggsave(filename = paste0("cvROC", date_time_stamp() %>% str_replace("_.*$", ""), ".png") %>% in_mod_subdir,
#' #'      width=10, height=4)
#' .Viz.Comparison.cvroc <- function(Comparison) {
#'     models <- Comparison@models_df
#'     order <- models %>%
#'         dplyr::group_by(target) %>%
#'         dplyr::summarise(ROC = mean(ROC)) %>%
#'         dplyr::arrange(desc(ROC)) %>%
#'         `$`(target)
#'
#'     models %>%
#'         dplyr::mutate(
#'             target = factor(target, levels=order)) %>% {
#'                 ggplot(., aes(x=target, y=ROC, ymin=ROC-ROCSD, ymax=ROC+ROCSD, col=dl)) +
#'                     geom_hline(aes(yintercept=0.6), linetype=2, alpha=0.5) +
#'                     geom_pointrange(position = position_dodge(width=0.25), size=0.3) +
#'                     scale_color_brewer("Model Architecture", palette = "Dark2", labels=c("vanilla"="1 radiograph only", "multimodal"="1 radiograph + metadata")) +
#'                     theme_classic() +
#'                     theme(axis.text.x=element_text(angle=90, hjust=1),
#'                           strip.text = element_text(angle=90)) +
#'                     labs(title="Cross-validated Binary Classifier Performance") +
#'                     theme(plot.title=element_text(hjust=0.3), plot.caption = element_text(hjust=0))}
#' }
mbadge/AnalysisToolkitR documentation built on May 27, 2019, 1:08 p.m.