From b9c5f647bc455cf3eff2eb6225d5acae83f7caa6 Mon Sep 17 00:00:00 2001 From: KelvynBladen Date: Fri, 1 Dec 2023 13:04:42 -0700 Subject: [PATCH] Move nice_plot_breaks to misc dev --- NAMESPACE | 1 - R/nice_plot_breaks.R | 122 ---------------------------------------- man/nice_plot_breaks.Rd | 27 --------- man/pdp_compare.Rd | 30 +--------- 4 files changed, 1 insertion(+), 179 deletions(-) delete mode 100644 R/nice_plot_breaks.R delete mode 100644 man/nice_plot_breaks.Rd diff --git a/NAMESPACE b/NAMESPACE index 6dfee06..6239302 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,6 @@ export(caret_plot) export(ggvip) export(mtry_compare) export(mtry_pdp_compare) -export(nice_plot_breaks) export(partial_cor) export(pdp_compare) export(robust_vifs) diff --git a/R/nice_plot_breaks.R b/R/nice_plot_breaks.R deleted file mode 100644 index 7ad7397..0000000 --- a/R/nice_plot_breaks.R +++ /dev/null @@ -1,122 +0,0 @@ -#' Generates Nice Plot Breaks and Limits from Data Range -#' @name nice_plot_breaks -#' @importFrom dplyr %>% summarise group_by case_when relocate -#' @importFrom ggplot2 ggplot geom_point geom_line geom_tile ggtitle facet_grid -#' scale_fill_gradient aes scale_x_continuous scale_y_continuous -#' @description This function uses caret grid training results to generate -#' performance data.frames, heatmaps, and other plots for comparing the -#' performance of models across their hyper-parameters and evaluating -#' interactions between different model hyper-parameters. -#' @param x An object of class train. -#' @param sqrt Boolean value indicating whether assessment metrics should be -#' adjusted via a square root transformation. Default is FALSE. -#' @return A list of caret training performance data.frames, heatmaps, and -#' plots. -#' @examples -#' b <- nice_plot_breaks(x) -#' @export - -nice_plot_breaks <- function(vec) { - upp <- max(vec) - low <- min(vec) - d_range <- upp - low - v <- 10^(-3:6) - - max(abs(vec)) - #compare abs(u) to abs(l) - #max(abs(vec)) - # use just the interval for the larger one?? - - indr <- findInterval(d_range, v) - - indu <- findInterval(abs(upp), v) - new_upp <- upp / (10^(indu - 5)) - round_upp <- ceiling(new_upp / 10) * 10 - - indl <- findInterval(abs(low), v) - new_low <- low / (10^(indl - 5)) - round_low <- floor(new_low / 10) * 10 - - # indl <- findInterval(abs(low), v) - # new_low <- low / (10^(indu - 5)) - # round_low <- floor(new_low / 10) * 10 - - new_range <- new_upp - new_low - round_range <- round_upp - round_low - - if (any(na.omit(c(new_range / round_range, - round_low / new_low, new_upp / round_upp)) < 3 / 4)) { - round_upp <- ceiling(new_upp / 4) * 4 - round_low <- floor(new_low / 4) * 4 - } - - new_upp <- round_upp * (10^(indu - 5)) - new_low <- round_low * (10^(indl - 5)) - new_range <- new_upp - new_low - - div <- case_when( - round_range %% 5 == 0 ~ 5, - round_range %% 4 == 0 ~ 4, - round_range %% 3 == 0 ~ 3, - .default = 4 - ) - - l <- list() - l$min <- new_low - l$max <- new_upp - l$breaks <- seq(new_low, new_upp, by = new_range / div) - l -} -# n <- nice_plot_breaks(vec = c(-13, 117)) -# n - -################################################################################ -# vec = c(-117, 6) -nice_plot_breaks <- function(vec) { - vec = c(min(vec), max(vec)) - d_range <- vec[2] - vec[1] - v <- 10^(-3:6) - - #compare abs(u) to abs(l) - #max(abs(vec)) - # use just the interval for the larger one?? - - indr <- findInterval(d_range, v) - - ind <- findInterval(max(abs(vec)), v) - - i = which.max(abs(vec)) - - new_vec <- vec / (10^(ind - 5)) - - round_vec <- c(floor(new_vec[which.min(new_vec)] / 10) * 10, - ceiling(new_vec[which.max(new_vec)] / 10) * 10) - - new_range <- max(new_vec) - min(new_vec) - round_range <- max(round_vec) - min(round_vec) - - if (any(na.omit(c(new_range / round_range, - new_vec[i]/round_vec[i])) < 3 / 4)) { - round_vec <- c(floor(new_vec[which.min(new_vec)] / 4) * 4, - ceiling(new_vec[which.max(new_vec)] / 4) * 4) - } - - new_upp <- round_upp * (10^(indu - 5)) - new_low <- round_low * (10^(indl - 5)) - new_range <- new_upp - new_low - - div <- case_when( - round_range %% 5 == 0 ~ 5, - round_range %% 4 == 0 ~ 4, - round_range %% 3 == 0 ~ 3, - .default = 4 - ) - - l <- list() - l$min <- new_low - l$max <- new_upp - l$breaks <- seq(new_low, new_upp, by = new_range / div) - l -} -# n <- nice_plot_breaks(vec = c(-13, 117)) -# n diff --git a/man/nice_plot_breaks.Rd b/man/nice_plot_breaks.Rd deleted file mode 100644 index 7f00aa2..0000000 --- a/man/nice_plot_breaks.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/nice_plot_breaks.R -\name{nice_plot_breaks} -\alias{nice_plot_breaks} -\title{Generates Nice Plot Breaks and Limits from Data Range} -\usage{ -nice_plot_breaks(vec) -} -\arguments{ -\item{x}{An object of class train.} - -\item{sqrt}{Boolean value indicating whether assessment metrics should be -adjusted via a square root transformation. Default is FALSE.} -} -\value{ -A list of caret training performance data.frames, heatmaps, and - plots. -} -\description{ -This function uses caret grid training results to generate - performance data.frames, heatmaps, and other plots for comparing the - performance of models across their hyper-parameters and evaluating - interactions between different model hyper-parameters. -} -\examples{ -b <- nice_plot_breaks(x) -} diff --git a/man/pdp_compare.Rd b/man/pdp_compare.Rd index 43a696c..97b9977 100644 --- a/man/pdp_compare.Rd +++ b/man/pdp_compare.Rd @@ -1,21 +1,9 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pdp_compare.R, R/pdp_compare_bivariate.R +% Please edit documentation in R/pdp_compare.R \name{pdp_compare} \alias{pdp_compare} \title{Small Multiple PDPs and Importance Metrics} \usage{ -pdp_compare( - x, - var_vec, - scale = FALSE, - sqrt = TRUE, - trim = 0.1, - trellis = TRUE, - which_class = 2L, - prob = TRUE, - ... -) - pdp_compare( x, var_vec, @@ -61,21 +49,11 @@ function is on a scale similar to the logit. Default is TRUE.} \item{...}{Other parameters to pass to the partial function.} } \value{ -A list of partial dependence plots with adjusted y-axes so all - are on an identical scale. This list includes a comparative facet plot and - pdp importance values for assessing true affect of predictors on response. - A list of partial dependence plots with adjusted y-axes so all are on an identical scale. This list includes a comparative facet plot and pdp importance values for assessing true affect of predictors on response. } \description{ -This function takes a randomForest object, generates partial - dependence plots for predictors and converts them to small multiples for - appropriate comparison. Output is a list containing a comparative grid - of PDPs, individual partial dependence plots, and PDP-derived - importance values for assessing effect of predictors on response. - This function takes a randomForest object, generates partial dependence plots for predictors and converts them to small multiples for appropriate comparison. Output is a list containing a comparative grid @@ -87,12 +65,6 @@ mtcars.rf <- randomForest::randomForest(formula = mpg ~ ., data = mtcars) car_pd <- pdp_compare(x = mtcars.rf) car_pd$full car_pd$imp -gridExtra::grid.arrange(car_pd$wt, car_pd$disp, - car_pd$hp, car_pd$cyl, nrow = 2) -mtcars.rf <- randomForest::randomForest(formula = mpg ~ ., data = mtcars) -car_pd <- pdp_compare(x = mtcars.rf) -car_pd$full -car_pd$imp gridExtra::grid.arrange(car_pd$wt, car_pd$disp, car_pd$hp, car_pd$cyl, nrow = 2) }