Package 'banter'

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>.
Authors: Eric Archer [aut, cre], Taiki Sakai [aut]
Maintainer: Eric Archer <[email protected]>
License: GNU General Public License
Version: 0.9.6
Built: 2024-10-30 06:52:30 UTC
Source: CRAN

Help Index


BioAcoustic EveNT ClassifiER

Description

banter

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381


Add a BANTER Detector Model

Description

Add a detector model to a BANTER classifier.

Usage

addBanterDetector(
  x,
  data,
  name,
  ntree,
  sampsize = 1,
  importance = FALSE,
  num.cores = 1
)

removeBanterDetector(x, name)

Arguments

x

a banter_model object.

data

detector data.frame or named list of detector data.frames. If a data.frame, then name must be provided.

name

detector name.

ntree

number of trees.

sampsize

number or fraction of samples to use in each tree. If < 1, then it will be used to select this fraction of the smallest sample size.

importance

retain importance scores in model? Defaults to FALSE and will be ignored if num.cores > 1.

num.cores

number of cores to use for Random Forest model. Set to NULL to use the maximum number detected on your system - 1.

Value

a banter_model object with the detector model added or removed.

Author(s)

Eric Archer [email protected]

References

Rankin, S., Archer, F., Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add the 'bp' (burst pulse) detector model
bant.mdl <- addBanterDetector(
  x = bant.mdl, 
  data = train.data$detectors$bp, 
  name = "bp",
  ntree = 50, sampsize = 1, num.cores = 1
)
bant.mdl

# remove the 'bp' detector model
bant.mdl <- removeBanterDetector(bant.mdl, "bp")
bant.mdl

BANTER Guide

Description

Open a browser window displaying "BANTER: A User’s Guide to Acoustic Classification".

Usage

banterGuide()

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381


Extract Random Forest Model

Description

Extract BANTER event or detector Random Forest model.

Usage

getBanterModel(x, model = "event")

Arguments

x

a banter_model object.

model

name of model to extract. Default is "event" to extract the event-level model. Can also be the name of a detector.

Value

a randomForest model object.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)

# extract the event randomForest model
event.rf <- getBanterModel(bant.mdl)
event.rf

# extract the burst pulse (bp) detector model
bp.rf <- getBanterModel(bant.mdl, "bp")
bp.rf

Extract Random Forest Model Data

Description

Extract BANTER event data used for the Random Forest model.

Usage

getBanterModelData(x)

Arguments

x

a banter_model object.

Value

the event data frame used to build the input model x.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)

event.df <- getBanterModelData(bant.mdl)
head(event.df)

Detector Names

Description

Return names of detectors loaded in BANTER model.

Usage

getDetectorNames(x)

Arguments

x

a banter_model object.

Value

a vector of names.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)
getDetectorNames(bant.mdl)

Sample Size

Description

Return sample sizes used for a BANTER model.

Usage

getSampSize(x, model = "event")

Arguments

x

a banter_model object.

model

name of model to extract. Default is "event" to return values for the event-level model. Can also be name of a detector.

Value

a vector of sample sizes.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 2, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)

# sample size for the event model
getSampSize(bant.mdl)

# sample size for the burst pulse (bp) detector model
getSampSize(bant.mdl, "bp")

Initialize BANTER model

Description

Initialize a BANTER model with event data.

Usage

initBanterModel(x)

Arguments

x

a data.frame of events. Every row is a unique event. Must have columns named event.id and species. All other columns will be used as predictor variables for the BANTER event classifier model.

Value

a banter_model object without any detector models.

Note

Values in the column species are passed through the make.names function on creation to ensure they don't include invalid characters.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
bant.mdl

Model Percent Correct

Description

Extract percent correctly classified by species for detector and event models.

Usage

modelPctCorrect(x)

Arguments

x

a banter_model object.

Value

a data.frame with the percent correctly classified for each model in x.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)
modelPctCorrect(bant.mdl)

Number and Proportion of Calls

Description

Return the number and proportion of calls in BANTER detector models.

Usage

numCalls(x, by = c("species", "event"))

propCalls(x, by = c("species", "event"))

Arguments

x

a banter_model object.

by

return summary by "species" or "event".

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)

# number of calls by species and event
numCalls(bant.mdl, "species")
numCalls(bant.mdl, "event")

# proportion of calls by species and event
propCalls(bant.mdl, "species")
propCalls(bant.mdl, "event")

Number of Events

Description

Return the number of events in a BANTER model by species.

Usage

numEvents(x, model = "event")

Arguments

x

a banter_model object.

model

name of model to extract. Default is "event" to summarize the event-level model. Can also be name of a detector.

Value

a data.frame giving the number of events available for each species.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)

# number of events in event model
numEvents(bant.mdl)

# number of events in burst pulse (bp) detector model
numEvents(bant.mdl, "bp")

Plot BANTER Detector Traces

Description

Plot traces of OOB error rates for detector Random Forest models.

Usage

plotDetectorTrace(x, detector = NULL)

Arguments

x

a banter_model object.

detector

names of models to plot. If set to NULL, traces for all models will be shown.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

See Also

plotTrace

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)

plotDetectorTrace(bant.mdl)

Predict BANTER events

Description

Predict species of events for novel data from a BANTER model.

Usage

predict(object, ...)

## S3 method for class 'banter_model'
predict(object, new.data, ...)

## S4 method for signature 'banter_model'
predict(object, new.data, ...)

Arguments

object

a banter_model object.

...

unused.

new.data

a list of event and detector data that has the same predictors as in the banter_model. It must contain elements called events and detectors. The events element must be a data.frame that has a column called event.id and the same predictor columns as the event data used to initialize the banter model (see initBanterModel). The detectors element must be a named list with the same detectors used to build the model (see addBanterDetector).

Value

A list with the following elements:

events

the data frame used in the event model for predictions.

predict.df

data.frame of predicted species and assignment probabilities for each event.

detector.freq

data.frame giving the number of events available for each detector.

validation.matrix

if species is a column in new.data, a table giving the classification rate for each event

Note

At least one detector in the model must be present in new.data. Any detectors in the training model that are absent will have all species proportions and the the detector propoprtion set to 0. If a column called species is in new.data, columns for the original species designation and if that matches predicted (correct) will be added to the predict.df data.frame of the output.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 2, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)

# predict test data
data(test.data)
test.pred <- predict(bant.mdl, test.data)
test.pred

Run BANTER Model

Description

Build full event classifier model

Usage

runBanterModel(x, ntree, sampsize = 1)

Arguments

x

a banter_model object.

ntree

number of trees.

sampsize

number or fraction of samples to use in each tree.

Value

a banter_model object with the complete BANTER model.

Author(s)

Eric Archer [email protected]

References

Rankin, S., Archer, F., Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)
summary(bant.mdl)

Subsample Detections

Description

Extract a random subsample of detections for each event and detector.

Usage

subsampleDetections(data, n)

Arguments

data

a detector data.frame or list of detector data.frames.

n

a value giving the number (n >= 1) or fraction (n between 0 and 1) of detections per event per detector to select. Detections are randomly selected without replacement. If n is greater than the number of detections in an event, all detections for that event will be retained.

Value

a detector data.frame or list of detector data.frames with no more than n detections per event per detector.

Author(s)

Eric Archer [email protected]

References

Rankin, S., Archer, F., Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)

# initial number of detections per event per detector
sapply(train.data$detectors, function(x) table(x$event.id))

# select half of all detectors
detect.half <- subsampleDetections(train.data$detectors, 0.5)
sapply(detect.half, function(x) table(x$event.id))

# select 20 detections
detect.20 <- subsampleDetections(train.data$detectors, 20)
sapply(detect.20, function(x) table(x$event.id))

# select 10 detections fro 'ec' detector
ec.10 <- subsampleDetections(train.data$detectors$ec, 10)
table(ec.10$event.id)

BANTER Classifier Model Summary

Description

Display summaries for event and detector models

Usage

summary(object, ...)

## S3 method for class 'banter_model'
summary(object, model = "event", n = 0.5, bins = 20, ...)

## S4 method for signature 'banter_model'
summary(object, model = "event", n = 0.5, bins = 20, ...)

Arguments

object

a banter_model object.

...

ignored.

model

name of model to summarize. Default is "event" to summarize the event-level model. Can also be name of a detector.

n

number of final iterations to summarize OOB error rate for. If between 0 and 1 is taken as a proportion of chain.

bins

number of bins in inbag histogram.

Value

In the plot that is created, the upper panel shows the trace of the Random Forest model OOB rate across sequential trees in the forest. The lower plot shows a frequency histogram of the number of times each sample was inbag (used as training data in a tree in the forest). The vertical red lines indicate the expected inbag rate for samples of each species.

Author(s)

Eric Archer [email protected]

References

Rankin, S. , Archer, F. , Keating, J. L., Oswald, J. N., Oswald, M. , Curtis, A. and Barlow, J. (2017), Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381

Examples

data(train.data)
# initialize BANTER model with event data
bant.mdl <- initBanterModel(train.data$events)
# add all detector models
bant.mdl <- addBanterDetector(
  bant.mdl, train.data$detectors, 
  ntree = 50, sampsize = 1, num.cores = 1
)
# run BANTER event model
bant.mdl <- runBanterModel(bant.mdl, ntree = 1000, sampsize = 1)
summary(bant.mdl)

Testing events and detectors

Description

A list of events and call data from detectors for testing BANTER model

Usage

data(test.data)

Format

list


Training events and detectors

Description

A list of events and call data from detectors for training BANTER model

Usage

data(train.data)

Format

list