Skip to content
Merged
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$
.DS_Store
^\.github$
^\.DS_Store$
^appveyor\.yml$
^appveyor\.yml$
^CRAN-SUBMISSION$
Empty file modified .github/.gitignore
100644 → 100755
Empty file.
Empty file modified .github/workflows/R-CMD-check.yaml
100644 → 100755
Empty file.
Empty file modified .gitignore
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: 0.9.8
Date: 2025-06-11 04:11:57 UTC
SHA: bab66da242d793907acfe612a135d37e0aded140
15 changes: 7 additions & 8 deletions DESCRIPTION
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Title: BioAcoustic eveNT classifiER
Description: Create a hierarchical acoustic event species classifier out of
multiple call type detectors as described in
Rankin et al (2017) <doi:10.1111/mms.12381>.
Version: 0.9.6
Version: 0.9.8
Authors@R: c(
EA = person("Eric", "Archer", email = "eric.archer@noaa.gov", role = c("aut", "cre")),
TS = person("Taiki", "Sakai", email = "taiki.sakai@noaa.gov", role = c("aut")))
EA = person("Eric", "Archer", email = "eric.ivan.archer@gmail.com", role = c("aut", "cre")),
SR = person("Shannon", "Rankin", email = "shannon.rankin@noaa.gov", role = c("aut")))
URL: https://github.com/SWFSC/banter
BugReports: https://github.com/SWFSC/banter/issues
Depends:
R (>= 4.1.0),
magrittr
R (>= 4.1.0)
Imports:
dplyr (>= 1.0.6),
ggplot2 (>= 3.3.3),
Expand All @@ -26,7 +27,5 @@ Imports:
tidyr (>= 1.1.1)
Suggests: testthat
License: GNU General Public License
RoxygenNote: 7.2.3
URL: https://github.com/ericarcher/banter
BugReports: https://github.com/ericarcher/banter/issues
RoxygenNote: 7.3.2
Encoding: UTF-8
1 change: 0 additions & 1 deletion NAMESPACE
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ export(runBanterModel)
export(subsampleDetections)
exportMethods(predict)
exportMethods(summary)
importFrom(magrittr,"%>%")
importFrom(methods,new)
importFrom(rlang,.data)
26 changes: 13 additions & 13 deletions R/addBanterDetector.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ removeBanterDetector <- function(x, name) {
start <- Sys.time()

# Combine event data with call ids in detector
df <- x@data %>%
dplyr::select(.data$event.id, .data$species) %>%
dplyr::inner_join(data, by = "event.id") %>%
dplyr::mutate(species = as.character(.data$species)) %>%
as.data.frame
df <- x@data |>
dplyr::select(.data$event.id, .data$species) |>
dplyr::inner_join(data, by = "event.id") |>
dplyr::mutate(species = as.character(.data$species)) |>
as.data.frame()

# Check if any columns need to be removed because of missing data
to.remove <- sapply(df, function(i) any(is.na(i)))
Expand All @@ -143,12 +143,12 @@ removeBanterDetector <- function(x, name) {
if(is.null(sampsize)) return(NULL)

# Remove missing species and format columns
df <- df %>%
dplyr::filter(.data$species %in% names(sampsize)) %>%
dplyr::mutate(species = factor(.data$species)) %>%
dplyr::mutate(id = paste0(.data$event.id, ".", .data$call.id)) %>%
tibble::column_to_rownames("id") %>%
as.data.frame() %>%
df <- df |>
dplyr::filter(.data$species %in% names(sampsize)) |>
dplyr::mutate(species = factor(.data$species)) |>
dplyr::mutate(id = paste0(.data$event.id, ".", .data$call.id)) |>
tibble::column_to_rownames("id") |>
as.data.frame() |>
droplevels()

# Setup number of cores
Expand All @@ -157,7 +157,7 @@ removeBanterDetector <- function(x, name) {

# Create random forest parameter list
params <- list(
predictors = df %>%
predictors = df |>
dplyr::select(-.data$event.id, -.data$call.id, -.data$species),
response = df$species,
sampsize = sampsize,
Expand Down Expand Up @@ -206,4 +206,4 @@ removeBanterDetector <- function(x, name) {
proximity = FALSE,
norm.votes = FALSE
)
}
}
5 changes: 2 additions & 3 deletions R/banter-package.R
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' banter
#'
#' @docType package
#' @name banter-package
#' @aliases banter
#' @title BioAcoustic EveNT ClassifiER
Expand All @@ -9,10 +8,10 @@
#' of dolphins in the California Current using whistles, echolocation clicks,
#' and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381
#' @importFrom rlang .data
#' @importFrom magrittr %>%
#' @importFrom methods new
#' @keywords package
NULL
"_PACKAGE"

.onAttach <- function(libname, pkgname) {
packageStartupMessage(
Expand Down Expand Up @@ -46,4 +45,4 @@ NULL
#' @usage data(test.data)
#' @format list
#' @keywords datasets
NULL
NULL
Empty file modified R/banterGuide.R
100644 → 100755
Empty file.
Empty file modified R/banter_detector.R
100644 → 100755
Empty file.
Empty file modified R/banter_model.R
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion R/getBanterModel.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param model name of model to extract. Default is \code{"event"}
#' to extract the event-level model. Can also be the name of a detector.
#'
#' @return a \code{\link{randomForest}} model object.
#' @return a \code{\link[randomForest]{randomForest}} model object.
#'
#' @author Eric Archer \email{eric.archer@@noaa.gov}
#'
Expand Down
Empty file modified R/getBanterModelData.R
100644 → 100755
Empty file.
Empty file modified R/getDetectorNames.R
100644 → 100755
Empty file.
Empty file modified R/getSampSize.R
100644 → 100755
Empty file.
Empty file modified R/initBanterModel.R
100644 → 100755
Empty file.
14 changes: 7 additions & 7 deletions R/internals.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,18 @@
#'
.meanVotes <- function(x) {
df <- sapply(names(x), function(d) {
x[[d]] %>%
x[[d]] |>
tidyr::pivot_longer(
-.data$event.id,
names_to = "species",
values_to = "prob"
) %>%
dplyr::mutate(species = paste0(d, ".", .data$species)) %>%
dplyr::group_by(.data$event.id, .data$species) %>%
) |>
dplyr::mutate(species = paste0(d, ".", .data$species)) |>
dplyr::group_by(.data$event.id, .data$species) |>
dplyr::summarize(prob.mean = mean(.data$prob), .groups = "drop")
}, simplify = FALSE) %>%
dplyr::bind_rows() %>%
}, simplify = FALSE) |>
dplyr::bind_rows() |>
tidyr::pivot_wider(names_from = "species", values_from = "prob.mean")

replace(df, is.na(df), 0)
}
}
12 changes: 6 additions & 6 deletions R/modelPctCorrect.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ modelPctCorrect <- function(x) {
model = model,
stringsAsFactors = FALSE
)
}) %>%
dplyr::bind_rows() %>%
}) |>
dplyr::bind_rows() |>
dplyr::mutate(
model = factor(.data$model, levels = c(names(x@detectors), "event"))
) %>%
tidyr::pivot_wider(names_from = "model", values_from = "pct.correct") %>%
dplyr::mutate(species = factor(.data$species, levels = c(spp, "Overall"))) %>%
) |>
tidyr::pivot_wider(names_from = "model", values_from = "pct.correct") |>
dplyr::mutate(species = factor(.data$species, levels = c(spp, "Overall"))) |>
dplyr::arrange(.data$species)
}
}
32 changes: 16 additions & 16 deletions R/numCalls.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ numCalls <- function(x, by = c("species", "event")) {
if(is.null(x@detectors)) stop("no detectors loaded in model.")
by <- switch(match.arg(by), species = "species", event = "event.id")
df <- lapply(names(x@detectors), function(d) {
x@data %>%
dplyr::left_join(x@detectors[[d]]@ids, by = "event.id") %>%
dplyr::group_by(dplyr::across(by)) %>%
dplyr::summarize(n = sum(!is.na(.data$call.id)), .groups = "drop") %>%
x@data |>
dplyr::left_join(x@detectors[[d]]@ids, by = "event.id") |>
dplyr::group_by(dplyr::across(by)) |>
dplyr::summarize(n = sum(!is.na(.data$call.id)), .groups = "drop") |>
dplyr::mutate(detector = paste0("num.", d))
}) %>%
dplyr::bind_rows() %>%
}) |>
dplyr::bind_rows() |>
tidyr::pivot_wider(names_from = "detector", values_from = "n")

replace(df, is.na(df), 0) %>%
replace(df, is.na(df), 0) |>
as.data.frame()
}

Expand All @@ -58,17 +58,17 @@ numCalls <- function(x, by = c("species", "event")) {
propCalls <- function(x, by = c("species", "event")) {
df <- numCalls(x, by)
by <- colnames(df)[1]
df %>%
df |>
tidyr::pivot_longer(
-dplyr::all_of(by),
names_to = "detector",
values_to = "n"
) %>%
dplyr::group_by(dplyr::across(by)) %>%
dplyr::mutate(prop = .data$n / sum(.data$n, na.rm = TRUE)) %>%
dplyr::ungroup() %>%
dplyr::select(-.data$n) %>%
dplyr::mutate(detector = gsub("num.", "prop.", .data$detector)) %>%
tidyr::pivot_wider(names_from = "detector", values_from = "prop") %>%
) |>
dplyr::group_by(dplyr::across(by)) |>
dplyr::mutate(prop = .data$n / sum(.data$n, na.rm = TRUE)) |>
dplyr::ungroup() |>
dplyr::select(-.data$n) |>
dplyr::mutate(detector = gsub("num.", "prop.", .data$detector)) |>
tidyr::pivot_wider(names_from = "detector", values_from = "prop") |>
as.data.frame()
}
}
9 changes: 4 additions & 5 deletions R/numEvents.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#' # number of events in burst pulse (bp) detector model
#' numEvents(bant.mdl, "bp")
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#'
#' @export
Expand All @@ -42,12 +41,12 @@ numEvents <- function(x, model = "event") {
df <- if(model == "event") {
x@data
} else {
x@data %>%
x@data |>
dplyr::filter(.data$event.id %in% x@detectors[[model]]@ids$event.id)
}
spp.fac <- factor(df$species, levels = sort(unique(x@data$species)))
table(species = spp.fac) %>%
as.data.frame() %>%
stats::setNames(c("species", "num.events")) %>%
table(species = spp.fac) |>
as.data.frame() |>
stats::setNames(c("species", "num.events")) |>
dplyr::mutate(species = as.character(.data$species))
}
Empty file modified R/plotDetectorTrace.R
100644 → 100755
Empty file.
52 changes: 26 additions & 26 deletions R/predict.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ predict.banter_model <- function(object, new.data, ...) {
# Get number of calls in each detector for each event
detector.num <- lapply(names(object@detectors), function(d) {
if(d %in% names(new.data$detectors)) {
new.data$events %>%
dplyr::left_join(new.data$detectors[[d]], by = "event.id") %>%
dplyr::group_by(.data$event.id) %>%
dplyr::summarize(n = sum(!is.na(.data$call.id)), .groups = "drop") %>%
new.data$events |>
dplyr::left_join(new.data$detectors[[d]], by = "event.id") |>
dplyr::group_by(.data$event.id) |>
dplyr::summarize(n = sum(!is.na(.data$call.id)), .groups = "drop") |>
dplyr::mutate(detector = paste0("prop.", d))
} else { # detector not present in new.data, proportion = 0
tibble::tibble(
Expand All @@ -135,16 +135,16 @@ predict.banter_model <- function(object, new.data, ...) {
detector = paste0("prop.", d)
)
}
}) %>%
}) |>
dplyr::bind_rows()

# Convert number to proportion of calls
detector.prop <- detector.num %>%
dplyr::group_by(.data$event.id) %>%
dplyr::mutate(n = .data$n / sum(.data$n, na.rm = TRUE)) %>%
dplyr::ungroup() %>%
detector.prop <- detector.num |>
dplyr::group_by(.data$event.id) |>
dplyr::mutate(n = .data$n / sum(.data$n, na.rm = TRUE)) |>
dplyr::ungroup() |>
tidyr::pivot_wider(names_from = "detector", values_from = "n")
detector.prop <- replace(detector.prop, is.na(detector.prop), 0) %>%
detector.prop <- replace(detector.prop, is.na(detector.prop), 0) |>
as.data.frame()

# Calculate mean votes for each event
Expand All @@ -154,38 +154,38 @@ predict.banter_model <- function(object, new.data, ...) {
object@detectors[[d]]@model,
new.data$detectors[[d]],
type = "prob"
) %>%
as.data.frame() %>%
) |>
as.data.frame() |>
dplyr::bind_cols(event.id = new.data$detectors[[d]]$event.id)
} else { # detector not present in model - fill with 0's
spp <- colnames(object@detectors[[d]]@model$votes)
vote.0 <- matrix(0, nrow = length(unique.events), ncol = length(spp))
colnames(vote.0) <- spp
dplyr::bind_cols(as.data.frame(vote.0), event.id = unique.events)
}
}, simplify = FALSE) %>%
}, simplify = FALSE) |>
.meanVotes()

# Construct data.frame to predict
df <- new.data$events %>%
dplyr::left_join(detector.prop, by = "event.id") %>%
df <- new.data$events |>
dplyr::left_join(detector.prop, by = "event.id") |>
dplyr::left_join(detector.votes, by = "event.id")

# add call rate columns if duration is present and there is no missing data
if("duration" %in% colnames(df)) {
if(all(!is.na(df$duration))) {
df <- df %>%
df <- df |>
dplyr::left_join(
detector.num %>%
detector.num |>
dplyr::left_join(
dplyr::select(df, "event.id", "duration"),
by = "event.id"
) %>%
) |>
dplyr::mutate(
detector = gsub("prop.", "rate.", .data$detector),
n = .data$n / .data$duration
) %>%
dplyr::select(-.data$duration) %>%
) |>
dplyr::select(-.data$duration) |>
tidyr::pivot_wider(names_from = "detector", values_from = "n"),
by = "event.id"
)
Expand All @@ -206,11 +206,11 @@ predict.banter_model <- function(object, new.data, ...) {
predict(object@model, df, type = "prob"),
stringsAsFactors = FALSE
),
detector.freq = detector.num %>%
dplyr::mutate(detector = gsub("prop.", "", .data$detector)) %>%
dplyr::group_by(.data$detector) %>%
dplyr::summarize(num.events = sum(.data$n > 0)) %>%
dplyr::ungroup() %>%
detector.freq = detector.num |>
dplyr::mutate(detector = gsub("prop.", "", .data$detector)) |>
dplyr::group_by(.data$detector) |>
dplyr::summarize(num.events = sum(.data$n > 0)) |>
dplyr::ungroup() |>
as.data.frame(stringsAsFactors = FALSE)
)

Expand All @@ -237,4 +237,4 @@ predict.banter_model <- function(object, new.data, ...) {
#' @name predict
#' @rdname predict
#' @aliases predict,banter_model-method
methods::setMethod("predict", "banter_model", predict.banter_model)
methods::setMethod("predict", "banter_model", predict.banter_model)
Loading
Loading