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
4 changes: 3 additions & 1 deletion .Rbuildignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ tar.gz$
^appveyor\.yml$
^\.github$
.DS_Store
^revdep$
^revdep$
^CRAN-SUBMISSION$
^cran-comments\.md$
Empty file modified .github/.gitignore
100644 → 100755
Empty file.
80 changes: 22 additions & 58 deletions .github/workflows/R-CMD-check.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- main
- master
branches: [main, master]
pull_request:
branches:
- main
- master

name: R-CMD-check
name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
Expand All @@ -22,65 +19,32 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-pandoc@v1

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Restore R package cache
if: runner.os != 'Windows'
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}
extra-packages: any::rcmdcheck
needs: check

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
4 changes: 4 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Version: 2.5.6
Date: 2026-10-08 00:08:26 UTC
SHA:
87b4b813ad9c1f4b74734e775d016b4735864060
23 changes: 11 additions & 12 deletions DESCRIPTION
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
Package: rfPermute
Type: Package
Title: Estimate Permutation p-Values for Random Forest Importance Metrics
Description: Estimate significance of importance metrics
for a Random Forest model by permuting the response
variable. Produces null distribution of importance
metrics for each predictor variable and p-value of
observed. Provides summary and visualization functions for 'randomForest'
results.
Version: 2.5.4
Description: Estimate significance of importance metrics for a Random Forest
model by permuting the response variable. Produces null distribution of
importance metrics for each predictor variable and p-value of observed.
Provides summary and visualization functions for 'randomForest' results.
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,9 +18,9 @@ Imports:
ggplot2 (>= 3.3),
grDevices,
gridExtra,
magrittr (>= 2.0),
methods,
parallel,
pROC,
randomForest (>= 4.6),
rlang,
scales,
Expand Down Expand Up @@ -52,7 +50,8 @@ Collate:
plotVotes.R
balancedSampsize.R
cleanRFdata.R
rfROC.R
LazyData: TRUE
License: GPL (>= 2)
Encoding: UTF-8
RoxygenNote: 7.3.2
Config/roxygen2/version: 8.1.0
14 changes: 9 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ export(plotTrace)
export(plotVotes)
export(rfPermute)
export(rfPermuteTutorial)
importFrom(magrittr,"%>%")
export(rfROC)
importFrom(methods,new)
importFrom(randomForest,importance)
importFrom(randomForest,randomForest)
importFrom(randomForest,
importance,
randomForest
)
importFrom(rlang,.data)
importFrom(stats,na.fail)
importFrom(stats,predict)
importFrom(stats,
na.fail,
predict
)
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.
24 changes: 13 additions & 11 deletions R/confusionMatrix.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ confusionMatrix <- function(x, conf.level = 0.95, threshold = NULL) {
cm <- rbind(cm, Overall = rep(NA, ncol(cm)))
pct.correct <- (correct.n / all.n) * 100
cbind(
n = all.n,
cm,
pct.correct = pct.correct[rownames(cm)],
ci[rownames(cm), , drop = FALSE],
Expand All @@ -88,8 +89,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 +100,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 All @@ -121,7 +122,8 @@ plotConfMat <- function(x, title = NULL, plot = TRUE) {
ggplot2::guides(fill = ggplot2::guide_colorbar(title = "Proportion")) +
ggplot2::theme(
axis.text.x.top = ggplot2::element_text(angle = 45, hjust = 0),
panel.background = ggplot2::element_blank()
panel.background = ggplot2::element_blank(),
legend.key.height = ggplot2::unit(1, 'null')
)

if(plot) print(p)
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)
}
}
Loading
Loading