Skip to content
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
3 changes: 2 additions & 1 deletion .Rbuildignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ tar.gz$
^appveyor\.yml$
^\.github$
.DS_Store
^revdep$
^revdep$
^CRAN-SUBMISSION$
Empty file modified .github/.gitignore
100644 → 100755
Empty file.
Empty file modified .github/workflows/R-CMD-check.yaml
100644 → 100755
Empty file.
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 2.5.5
Date: 2025-06-08 18:57:19 UTC
SHA: 5f47d4cf5aa147c9f310e2917e566d2480ddd527
11 changes: 5 additions & 6 deletions DESCRIPTION
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,7 +20,6 @@ Imports:
ggplot2 (>= 3.3),
grDevices,
gridExtra,
magrittr (>= 2.0),
methods,
parallel,
randomForest (>= 4.6),
Expand Down Expand Up @@ -55,4 +54,4 @@ Collate:
LazyData: TRUE
License: GPL (>= 2)
Encoding: UTF-8
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export(plotTrace)
export(plotVotes)
export(rfPermute)
export(rfPermuteTutorial)
importFrom(magrittr,"%>%")
importFrom(methods,new)
importFrom(randomForest,importance)
importFrom(randomForest,randomForest)
Expand Down
Empty file modified R/balancedSampsize.R
100644 → 100755
Empty file.
Empty file modified R/casePredictions.R
100644 → 100755
Empty file.
Empty file modified R/classPriors.R
100644 → 100755
Empty file.
Empty file modified R/cleanRFdata.R
100644 → 100755
Empty file.
20 changes: 10 additions & 10 deletions R/confusionMatrix.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Empty file modified R/dataSets.R
100644 → 100755
Empty file.
20 changes: 10 additions & 10 deletions R/importance.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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() +
Expand All @@ -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(
Expand Down Expand Up @@ -236,4 +236,4 @@ plotImportance <- function(x, plot.type = c("bar", "heatmap"), imp.type = NULL,
}
}
invisible(imp.plot)
}
}
Empty file modified R/internals.R
100644 → 100755
Empty file.
Empty file modified R/pctCorrect.R
100644 → 100755
Empty file.
10 changes: 5 additions & 5 deletions R/plotImpPreds.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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") +
Expand All @@ -80,4 +80,4 @@ plotImpPreds <- function(x, df, class.col, imp.type = NULL, max.vars = 16,

if(plot) print(p)
invisible(p)
}
}
2 changes: 1 addition & 1 deletion R/plotInbag.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions R/plotNull.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -85,12 +85,12 @@ 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")
}, simplify = FALSE, USE.NAMES = TRUE)

if(plot) for(p in g) print(p)
invisible(g)
}
}
16 changes: 8 additions & 8 deletions R/plotPredictedProbs.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ 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") +
ggplot2::theme(legend.title = ggplot2::element_blank())

if(plot) print(p)
invisible(p)
}
}
8 changes: 4 additions & 4 deletions R/plotProximity.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}
}
20 changes: 11 additions & 9 deletions R/plotTrace.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -59,4 +61,4 @@ plotTrace <- function(x, pct.correct = TRUE, plot = TRUE) {
}
if(plot) print(p)
invisible(p)
}
}
Empty file modified R/plotVotes.R
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion R/rfPermute-package.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#'
#' @importFrom randomForest randomForest
#' @importFrom rlang .data
#' @importFrom magrittr %>%
#' @importFrom methods new
#'
.onAttach <- function(libname, pkgname) {
Expand Down
1 change: 0 additions & 1 deletion R/rfPermute.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ predict.rfPermute <- function(object, ...) predict(as.randomForest(object), ...)


#' @rdname rfPermute
#' @importFrom stats predict
#' @export
#'
rfPermuteTutorial <- function() {
Expand Down
Empty file modified R/summary.R
100644 → 100755
Empty file.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Empty file modified appveyor.yml
100644 → 100755
Empty file.
Empty file modified data/symb.metab.rda
100644 → 100755
Empty file.
Empty file modified inst/rfPermute_Tutorial.html
100644 → 100755
Empty file.
Empty file modified man/balancedSampsize.Rd
100644 → 100755
Empty file.
Empty file modified man/casePredictions.Rd
100644 → 100755
Empty file.
Empty file modified man/classPriors.Rd
100644 → 100755
Empty file.
Empty file modified man/cleanRFdata.Rd
100644 → 100755
Empty file.
Empty file modified man/combineRP.Rd
100644 → 100755
Empty file.
Empty file modified man/confusionMatrix.Rd
100644 → 100755
Empty file.
Empty file modified man/importance.Rd
100644 → 100755
Empty file.
Empty file modified man/pctCorrect.Rd
100644 → 100755
Empty file.
Empty file modified man/plotImpPreds.Rd
100644 → 100755
Empty file.
Empty file modified man/plotInbag.Rd
100644 → 100755
Empty file.
Empty file modified man/plotNull.Rd
100644 → 100755
Empty file.
Empty file modified man/plotPredictedProbs.Rd
100644 → 100755
Empty file.
Empty file modified man/plotProximity.Rd
100644 → 100755
Empty file.
Empty file modified man/plotTrace.Rd
100644 → 100755
Empty file.
Empty file modified man/plotVotes.Rd
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions man/rfPermute-package.Rd
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file modified man/summary.Rd
100644 → 100755
Empty file.
Empty file modified man/symb.metab.Rd
100644 → 100755
Empty file.
Loading