diff --git a/.Rbuildignore b/.Rbuildignore old mode 100644 new mode 100755 index 7ef3a46..9fd098b --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,4 +10,5 @@ tar.gz$ ^appveyor\.yml$ ^\.github$ .DS_Store -^revdep$ \ No newline at end of file +^revdep$ +^CRAN-SUBMISSION$ diff --git a/.github/.gitignore b/.github/.gitignore old mode 100644 new mode 100755 diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml old mode 100644 new mode 100755 diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION new file mode 100644 index 0000000..fbdcfac --- /dev/null +++ b/CRAN-SUBMISSION @@ -0,0 +1,3 @@ +Version: 2.5.5 +Date: 2025-06-08 18:57:19 UTC +SHA: 5f47d4cf5aa147c9f310e2917e566d2480ddd527 diff --git a/DESCRIPTION b/DESCRIPTION old mode 100644 new mode 100755 index dba61d1..90ca4d0 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,11 +7,11 @@ Description: Estimate significance of importance metrics metrics for each predictor variable and p-value of observed. Provides summary and visualization functions for 'randomForest' results. -Version: 2.5.4 +Version: 2.5.6 Authors@R: c( - EA = person("Eric", "Archer", email = "eric.archer@noaa.gov", role = c("aut", "cre"))) -URL: https://github.com/EricArcher/rfPermute -BugReports: https://github.com/EricArcher/rfPermute/issues + EA = person("Eric", "Archer", email = "eric.ivan.archer@gmail.com", role = c("aut", "cre"))) +URL: https://github.com/SWFSC/rfPermute +BugReports: https://github.com/SWFSC/rfPermute/issues Depends: R (>= 4.1.0) Imports: @@ -20,7 +20,6 @@ Imports: ggplot2 (>= 3.3), grDevices, gridExtra, - magrittr (>= 2.0), methods, parallel, randomForest (>= 4.6), @@ -55,4 +54,4 @@ Collate: LazyData: TRUE License: GPL (>= 2) Encoding: UTF-8 -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 diff --git a/NAMESPACE b/NAMESPACE index d06f4cb..c743829 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,7 +27,6 @@ export(plotTrace) export(plotVotes) export(rfPermute) export(rfPermuteTutorial) -importFrom(magrittr,"%>%") importFrom(methods,new) importFrom(randomForest,importance) importFrom(randomForest,randomForest) diff --git a/R/balancedSampsize.R b/R/balancedSampsize.R old mode 100644 new mode 100755 diff --git a/R/casePredictions.R b/R/casePredictions.R old mode 100644 new mode 100755 diff --git a/R/classPriors.R b/R/classPriors.R old mode 100644 new mode 100755 diff --git a/R/cleanRFdata.R b/R/cleanRFdata.R old mode 100644 new mode 100755 diff --git a/R/confusionMatrix.R b/R/confusionMatrix.R old mode 100644 new mode 100755 index 3f7f731..f20df0f --- a/R/confusionMatrix.R +++ b/R/confusionMatrix.R @@ -88,8 +88,8 @@ plotConfMat <- function(x, title = NULL, plot = TRUE) { if(rf$type == "regression") stop("'rf' must be of a classification model") conf <- .confMat(rf) - pct.correct <- (100 * sum(diag(conf)) / sum(conf)) %>% - round(0) %>% + pct.correct <- (100 * sum(diag(conf)) / sum(conf)) |> + round(0) |> paste0("% correct") title <- if(is.null(title)) { pct.correct @@ -99,18 +99,18 @@ plotConfMat <- function(x, title = NULL, plot = TRUE) { freq <- rowSums(conf) rownames(conf) <- paste0(names(freq), " (", freq, ")") - p <- conf %>% - prop.table(1) %>% - as.data.frame %>% - tibble::rownames_to_column("observed") %>% - tidyr::gather("predicted", "prop", -.data$observed) %>% + p <- conf |> + prop.table(1) |> + as.data.frame() |> + tibble::rownames_to_column("observed") |> + tidyr::gather("predicted", "prop", -.data$observed) |> dplyr::mutate( observed = factor(.data$observed), observed = stats::reorder(.data$observed, dplyr::desc(.data$observed)), predicted = factor(.data$predicted) - ) %>% - ggplot2::ggplot(ggplot2::aes_string("predicted", "observed")) + - ggplot2::geom_raster(ggplot2::aes_string(fill = "prop")) + + ) |> + ggplot2::ggplot(ggplot2::aes(x = .data$predicted, y = .data$observed)) + + ggplot2::geom_raster(ggplot2::aes(fill = .data$prop)) + ggplot2::scale_fill_viridis_c( option = "magma", direction = -1, diff --git a/R/dataSets.R b/R/dataSets.R old mode 100644 new mode 100755 diff --git a/R/importance.R b/R/importance.R old mode 100644 new mode 100755 index 25128a9..31c8f76 --- a/R/importance.R +++ b/R/importance.R @@ -137,12 +137,12 @@ plotImportance <- function(x, plot.type = c("bar", "heatmap"), imp.type = NULL, pval = if(inherits(x, "rfPermute")) { x$pval[rownames(imp.mat), i, sc] } else Inf - ) %>% - tibble::rownames_to_column("pred") %>% + ) |> + tibble::rownames_to_column("pred") |> dplyr::mutate( is.sig = .data$pval <= alpha, pred = stats::reorder(.data$pred, .data$imp) - ) %>% + ) |> dplyr::arrange(-.data$imp) if(sig.only) imp.df <- imp.df[imp.df$is.sig, ] n <- min(n, nrow(imp.df)) @@ -151,7 +151,7 @@ plotImportance <- function(x, plot.type = c("bar", "heatmap"), imp.type = NULL, ggplot2::ggplot( imp.df, - ggplot2::aes_string(x = "pred", y = "imp", fill = "is.sig") + ggplot2::aes(x = .data$pred, y = .data$imp, fill = .data$is.sig) ) + ggplot2::geom_bar(stat = "identity") + ggplot2::coord_flip() + @@ -174,17 +174,17 @@ plotImportance <- function(x, plot.type = c("bar", "heatmap"), imp.type = NULL, preds <- rev(rev(preds)[1:n]) imp.df <- data.frame(imp.mat[preds, imp.type, drop = FALSE], check.names = FALSE) if(ranks) for(i in imp.type) imp.df[[i]] <- rank(-imp.df[[i]]) - imp.df <- imp.df %>% - tibble::rownames_to_column("pred") %>% - tidyr::pivot_longer(-.data$pred, names_to = "type") %>% + imp.df <- imp.df |> + tibble::rownames_to_column("pred") |> + tidyr::pivot_longer(-.data$pred, names_to = "type") |> dplyr::mutate( type = factor(.data$type, levels = imp.type), pred = factor(.data$pred, levels = preds) ) # create plot - g <- ggplot2::ggplot(imp.df, ggplot2::aes_string("type", "pred")) + - ggplot2::geom_raster(ggplot2::aes_string(fill = "value")) + + g <- ggplot2::ggplot(imp.df, ggplot2::aes(x = .data$type, y = .data$pred)) + + ggplot2::geom_raster(ggplot2::aes(fill = .data$value)) + ggplot2::theme(panel.background = ggplot2::element_blank()) g <- g + if(ranks) { ggplot2::scale_fill_gradient2( @@ -236,4 +236,4 @@ plotImportance <- function(x, plot.type = c("bar", "heatmap"), imp.type = NULL, } } invisible(imp.plot) -} \ No newline at end of file +} diff --git a/R/internals.R b/R/internals.R old mode 100644 new mode 100755 diff --git a/R/pctCorrect.R b/R/pctCorrect.R old mode 100644 new mode 100755 diff --git a/R/plotImpPreds.R b/R/plotImpPreds.R old mode 100644 new mode 100755 index 31a34a5..603b922 --- a/R/plotImpPreds.R +++ b/R/plotImpPreds.R @@ -68,10 +68,10 @@ plotImpPreds <- function(x, df, class.col, imp.type = NULL, max.vars = 16, df$.class. <- factor(df[[class.col]]) df <- df[, c(".class.", imp.vars)] - p <- df %>% - tidyr::pivot_longer(-.data$.class., names_to = "var") %>% - dplyr::mutate(var = factor(.data$var, levels = imp.vars)) %>% - ggplot2::ggplot(ggplot2::aes_string(".class.", "value")) + + p <- df |> + tidyr::pivot_longer(-.data$.class., names_to = "var") |> + dplyr::mutate(var = factor(.data$var, levels = imp.vars)) |> + ggplot2::ggplot(ggplot2::aes(x = .data$.class., y = .data$value)) + ggplot2::geom_violin(alpha = violin.alpha) + ggplot2::geom_jitter(size = size, alpha = point.alpha, width = 0.25, height = 0) + ggplot2::facet_wrap(~ var, scales = "free_y") + @@ -80,4 +80,4 @@ plotImpPreds <- function(x, df, class.col, imp.type = NULL, max.vars = 16, if(plot) print(p) invisible(p) -} \ No newline at end of file +} diff --git a/R/plotInbag.R b/R/plotInbag.R old mode 100644 new mode 100755 index 8dc829f..3f39008 --- a/R/plotInbag.R +++ b/R/plotInbag.R @@ -72,7 +72,7 @@ plotInbag <- function(x, bins = 10, replace = TRUE, sampsize = NULL, pct <- ((rf$ntree - rf$oob.times) / rf$ntree) * 100 bins <- max(bins, floor(length(pct) / 5)) p <- data.frame(pct = pct) |> - ggplot2::ggplot(ggplot2::aes_string("pct")) + + ggplot2::ggplot(ggplot2::aes(x = .data$pct)) + ggplot2::geom_histogram(bins = bins) + ggplot2::labs( x = "Percent of trees where sample was inbag", diff --git a/R/plotNull.R b/R/plotNull.R old mode 100644 new mode 100755 index a1ef574..4c3eff4 --- a/R/plotNull.R +++ b/R/plotNull.R @@ -65,17 +65,17 @@ plotNull <- function(x, preds = NULL, imp.type = NULL, scale = TRUE, imp.type ) - df <- sapply(imp.type, function(i) x$null.dist[[sc]][pr, i, ]) %>% - as.data.frame() %>% - tidyr::gather("imp.type", "importance") %>% + df <- sapply(imp.type, function(i) x$null.dist[[sc]][pr, i, ]) |> + as.data.frame() |> + tidyr::gather("imp.type", "importance") |> dplyr::mutate(imp.type = factor(labels[imp.type], levels = labels)) - obs <- imp[pr, imp.type, drop = FALSE] %>% - as.data.frame() %>% - tibble::rownames_to_column("predictor") %>% - tidyr::gather("imp.type", "importance", -.data$predictor) %>% + obs <- imp[pr, imp.type, drop = FALSE] |> + as.data.frame() |> + tibble::rownames_to_column("predictor") |> + tidyr::gather("imp.type", "importance", -.data$predictor) |> dplyr::mutate(imp.type = factor(labels[imp.type], levels = labels)) - p <- ggplot2::ggplot(df, ggplot2::aes_string("importance")) + p <- ggplot2::ggplot(df, ggplot2::aes(x = .data$importance)) p <- if(plot.type == "hist") { p + ggplot2::geom_histogram() + ggplot2::ylab("Count") } else { @@ -85,7 +85,7 @@ plotNull <- function(x, preds = NULL, imp.type = NULL, scale = TRUE, ggplot2::xlab("Importance") + ggplot2::ggtitle(pr) + ggplot2::geom_vline( - ggplot2::aes_string(xintercept = "importance"), + ggplot2::aes(xintercept = .data$importance), color = "red", data = obs ) + ggplot2::facet_wrap(~ imp.type, scales = "free") @@ -93,4 +93,4 @@ plotNull <- function(x, preds = NULL, imp.type = NULL, scale = TRUE, if(plot) for(p in g) print(p) invisible(g) -} \ No newline at end of file +} diff --git a/R/plotPredictedProbs.R b/R/plotPredictedProbs.R old mode 100644 new mode 100755 index 39e6603..6a6c6af --- a/R/plotPredictedProbs.R +++ b/R/plotPredictedProbs.R @@ -25,16 +25,16 @@ plotPredictedProbs <- function(x, bins = 30, plot = TRUE) { rf <- as.randomForest(x) if(rf$type == "regression") stop("'rf' must be of a classification model") - p <- rf$votes %>% - as.data.frame %>% + p <- rf$votes |> + as.data.frame() |> cbind( class = as.character(rf$y), predicted = as.character(rf$predicted) - ) %>% - tidyr::gather("pred.class", "prob", -.data$class, -.data$predicted) %>% - dplyr::filter(.data$predicted == .data$pred.class) %>% - dplyr::mutate(correct = .data$class == .data$predicted) %>% - ggplot2::ggplot(ggplot2::aes_string("prob", fill = "class")) + + ) |> + tidyr::gather("pred.class", "prob", -.data$class, -.data$predicted) |> + dplyr::filter(.data$predicted == .data$pred.class) |> + dplyr::mutate(correct = .data$class == .data$predicted) |> + ggplot2::ggplot(ggplot2::aes(.data$prob, fill = .data$class)) + ggplot2::geom_histogram(bins = bins) + ggplot2::facet_wrap(~ predicted) + ggplot2::labs(x = "Assignment probability", y = "Frequency") + @@ -42,4 +42,4 @@ plotPredictedProbs <- function(x, bins = 30, plot = TRUE) { if(plot) print(p) invisible(p) -} \ No newline at end of file +} diff --git a/R/plotProximity.R b/R/plotProximity.R old mode 100644 new mode 100755 index edf2da6..cd3d601 --- a/R/plotProximity.R +++ b/R/plotProximity.R @@ -153,12 +153,12 @@ plotProximity <- function(x, dim.x = 1, dim.y = 2, class.cols = NULL, if(legend.type == "label") { g <- g + ggplot2::geom_label( ggplot2::aes_(label = ~class), - data = mds.df %>% - dplyr::group_by(.data$class) %>% + data = mds.df |> + dplyr::group_by(.data$class) |> dplyr::summarize( x = mean(.data$x), y = mean(.data$y) - ) %>% + ) |> dplyr::ungroup(), fill = "white", alpha = label.alpha, @@ -193,4 +193,4 @@ plotProximity <- function(x, dim.x = 1, dim.y = 2, class.cols = NULL, if(plot) print(g) invisible(list(prox.mds = prox.mds, g = g)) -} \ No newline at end of file +} diff --git a/R/plotTrace.R b/R/plotTrace.R old mode 100644 new mode 100755 index 7688a70..cf5f2c5 --- a/R/plotTrace.R +++ b/R/plotTrace.R @@ -28,15 +28,17 @@ plotTrace <- function(x, pct.correct = TRUE, plot = TRUE) { names(class.cols) <- names(class.lines) <- c("OOB", levels(rf$y)) df <- as.data.frame(rf$err.rate) - df %>% - dplyr::mutate(trees = 1:dplyr::n()) %>% - tidyr::gather("class", "error", -.data$trees) %>% + df |> + dplyr::mutate(trees = 1:dplyr::n()) |> + tidyr::gather("class", "error", -.data$trees) |> dplyr::mutate( class = factor(.data$class, levels = colnames(df)), error = if(pct.correct) (1 - .data$error) * 100 else .data$error * 100 - ) %>% - ggplot2::ggplot(ggplot2::aes_string("trees", "error", color = "class")) + - ggplot2::geom_line(ggplot2::aes_string(linetype = "class")) + + ) |> + ggplot2::ggplot( + ggplot2::aes(x = .data$trees, y = .data$error, color = .data$class) + ) + + ggplot2::geom_line(ggplot2::aes(linetype = .data$class)) + ggplot2::scale_color_manual(values = class.cols) + ggplot2::scale_linetype_manual(values = class.lines) + ggplot2::labs( @@ -45,8 +47,8 @@ plotTrace <- function(x, pct.correct = TRUE, plot = TRUE) { ) + ggplot2::theme(legend.title = ggplot2::element_blank()) } else if(utils::hasName(rf, "mse")) { - data.frame(trees = 1:length(rf$mse), error = rf$mse) %>% - ggplot2::ggplot(ggplot2::aes_string("trees", "error")) + + data.frame(trees = 1:length(rf$mse), error = rf$mse) |> + ggplot2::ggplot(ggplot2::aes(x = .data$trees, y = .data$error)) + ggplot2::geom_line() + ggplot2::labs(x = "Trees", y = "Mean Squared Error") } else NULL @@ -59,4 +61,4 @@ plotTrace <- function(x, pct.correct = TRUE, plot = TRUE) { } if(plot) print(p) invisible(p) -} \ No newline at end of file +} diff --git a/R/plotVotes.R b/R/plotVotes.R old mode 100644 new mode 100755 diff --git a/R/rfPermute-package.R b/R/rfPermute-package.R old mode 100644 new mode 100755 index ff7d5b6..4823b5a --- a/R/rfPermute-package.R +++ b/R/rfPermute-package.R @@ -8,7 +8,6 @@ #' #' @importFrom randomForest randomForest #' @importFrom rlang .data -#' @importFrom magrittr %>% #' @importFrom methods new #' .onAttach <- function(libname, pkgname) { diff --git a/R/rfPermute.R b/R/rfPermute.R index f0110eb..af4a3ef 100755 --- a/R/rfPermute.R +++ b/R/rfPermute.R @@ -270,7 +270,6 @@ predict.rfPermute <- function(object, ...) predict(as.randomForest(object), ...) #' @rdname rfPermute -#' @importFrom stats predict #' @export #' rfPermuteTutorial <- function() { diff --git a/R/summary.R b/R/summary.R old mode 100644 new mode 100755 diff --git a/README.md b/README.md index 8aa827c..41744b7 100755 --- a/README.md +++ b/README.md @@ -59,7 +59,15 @@ devtools::install_github('EricArcher/rfPermute') ## Changelog -### version 2.5.4 (on CRAN) +### version 2.5.6 (devel) + +* switched aes_string() for aes() in ggplot plots + +### version 2.5.5 (on CRAN) + +* move of package to SWFSC/rfPermute as main GitHub repository + +### version 2.5.4 * fixed print.rfPermute output for regression models. diff --git a/appveyor.yml b/appveyor.yml old mode 100644 new mode 100755 diff --git a/data/symb.metab.rda b/data/symb.metab.rda old mode 100644 new mode 100755 diff --git a/inst/rfPermute_Tutorial.html b/inst/rfPermute_Tutorial.html old mode 100644 new mode 100755 diff --git a/man/balancedSampsize.Rd b/man/balancedSampsize.Rd old mode 100644 new mode 100755 diff --git a/man/casePredictions.Rd b/man/casePredictions.Rd old mode 100644 new mode 100755 diff --git a/man/classPriors.Rd b/man/classPriors.Rd old mode 100644 new mode 100755 diff --git a/man/cleanRFdata.Rd b/man/cleanRFdata.Rd old mode 100644 new mode 100755 diff --git a/man/combineRP.Rd b/man/combineRP.Rd old mode 100644 new mode 100755 diff --git a/man/confusionMatrix.Rd b/man/confusionMatrix.Rd old mode 100644 new mode 100755 diff --git a/man/importance.Rd b/man/importance.Rd old mode 100644 new mode 100755 diff --git a/man/pctCorrect.Rd b/man/pctCorrect.Rd old mode 100644 new mode 100755 diff --git a/man/plotImpPreds.Rd b/man/plotImpPreds.Rd old mode 100644 new mode 100755 diff --git a/man/plotInbag.Rd b/man/plotInbag.Rd old mode 100644 new mode 100755 diff --git a/man/plotNull.Rd b/man/plotNull.Rd old mode 100644 new mode 100755 diff --git a/man/plotPredictedProbs.Rd b/man/plotPredictedProbs.Rd old mode 100644 new mode 100755 diff --git a/man/plotProximity.Rd b/man/plotProximity.Rd old mode 100644 new mode 100755 diff --git a/man/plotTrace.Rd b/man/plotTrace.Rd old mode 100644 new mode 100755 diff --git a/man/plotVotes.Rd b/man/plotVotes.Rd old mode 100644 new mode 100755 diff --git a/man/rfPermute-package.Rd b/man/rfPermute-package.Rd old mode 100644 new mode 100755 index 67f3e2e..8f34525 --- a/man/rfPermute-package.Rd +++ b/man/rfPermute-package.Rd @@ -10,13 +10,13 @@ Random Forest Predictor Importance Significance and Model Diagnostics. \seealso{ Useful links: \itemize{ - \item \url{https://github.com/EricArcher/rfPermute} - \item Report bugs at \url{https://github.com/EricArcher/rfPermute/issues} + \item \url{https://github.com/SWFSC/rfPermute} + \item Report bugs at \url{https://github.com/SWFSC/rfPermute/issues} } } \author{ -\strong{Maintainer}: Eric Archer \email{eric.archer@noaa.gov} +\strong{Maintainer}: Eric Archer \email{eric.ivan.archer@gmail.com} } \keyword{internal} diff --git a/man/summary.Rd b/man/summary.Rd old mode 100644 new mode 100755 diff --git a/man/symb.metab.Rd b/man/symb.metab.Rd old mode 100644 new mode 100755