View source: R/suggest_recapture.R
suggest_recapture | R Documentation |
For animals tagged with archival tags, this function highlights putative, unrecorded recapture events (when tagged individuals may have been captured by recreational anglers). To do this, the function bins each individual's time series into a series of time windows. In each window, the function identifies all of the time steps when the individual's depth was shallower than a specified threshold
: these are ‘putative capture events’. Windows that contain putative capture event(s) are termed capture windows. For each capture window, the depth time series can be inspected visually to clarify whether or not movement into shallow water is likely to reflect capture (e.g., if putative capture events occurred at a reasonable time of day and the shape of changes in depth are consistent with that expected to be caused by capture). The function returns a list, with one element for each capture window, that contains the depth time series within that window.
suggest_recapture( data, fct = NULL, threshold = 1, window = 60 * 60 * 12, plot = TRUE, pretty_axis_args = list(side = 3:2), buffer = 60 * 60, add_threshold_markers = list(col = "blue", lty = 3), add_additional = NULL, prompt = TRUE, prompt_warning = 100, ... )
data |
A dataframe of depth time series. This must contain a POSIXct vector of time stamps (‘timestamp’) and a numeric vector of absolute depths (‘depth’). A column can be included to distinguish levels of a grouping factor (e.g., individuals) (see |
fct |
(optional) A character that defines the name of a column in |
threshold |
A number that defines the depth threshold; depth(s) shallower than |
window |
A number that defines the duration (s) of capture windows. |
plot |
A logical input that defines whether or not to plot, for each capture window, depth (which is internally negated for plotting) against time, with putative capture events flagged. |
pretty_axis_args |
If |
buffer |
A number, or a vector of two numbers, used to adjust the time (s) of the first and last putative capture events in each capture window to define x axis limits. For example, |
add_threshold_markers |
(optional) If |
add_additional |
(optional) If |
prompt |
If |
prompt_warning |
If |
... |
Additional arguments passed to |
This function was motivated by the need to identify putative, unrecorded recreational angling events for tagged flapper skate (Dipturus intermedius) during individuals' time at liberty. The skate are typically targeted by recreational anglers over areas of deep (> 100 m) water, so angling events are visible as dramatic spikes in the depth time series caused by ascent into shallow water.
For each individual's time series, the function groups observations into a series of window
s and identifies all of the time steps within each window when the depth was shallower than the threshold
. For each capture window (a window that contains putative capture event(s)), a dataframe of the depth time series/putative capture events within that window is returned. If plot = TRUE
, for each window, a plot of the depth time series also returned with all moments when the depth was shallower than the threshold flagged for visible inspection. Putative capture events can then be evaluated according to the time of day when they occurred, the shape of the depth time series or other relevant factors.
The function returns a list, with one element for each capture window, that contains the depth time series within that window. If plot = TRUE
, for each window, a plot of the depth time series also returned.
Edward Lavender
define_recapture
defines the precise time of known capture events.
#### Example (1): Implement function with default options # One potential capture event identified events <- suggest_recapture(data = dat_flapper, fct = "id", prompt = FALSE) utils::str(events) #### Example (2): Adjust capture threshold events <- suggest_recapture(data = dat_flapper, fct = "id", threshold = 10, prompt = FALSE) #### Example (3) Adjust capture window size # Adjust capture window events <- suggest_recapture(data = dat_flapper, fct = "id", threshold = 20, window = 60*60*24*7, prompt = FALSE) # Adjust plot x limits via buffer events <- suggest_recapture(data = dat_flapper, fct = "id", threshold = 20, window = 60*60*24*7, buffer = 60*60*24*2, prompt = FALSE) #### Example (4): Customise plot ## Adjust vertical flags via add_threshold_markers events <- suggest_recapture(data = dat_flapper, add_threshold_markers = list(col = "red"), fct = "id", prompt = FALSE) ## Use add_additional e.g, to provide useful plot titles # Define a function, which must depend on an index and the data, to add plot titles # These will depend on the capture window index and # ... we will add a * to flag putative events that occurred during the day # ... (which are more likely to reflect actual capture events). add_main <- function(index, data){ # Define title title <- paste0("[", index, "]") # Identify events during the day and add this to title day <- data[data$depth <= 5, ] if(nrow(day) > 0){ day$hour <- hour_dbl(day$timestamp) day <- day[day$hour >= 8 & day$hour <= 20, ] } if(nrow(day) > 0){ title <- paste0(title, "*") } # Add plot title to plot mtext(side = 3, text = title, line = 1.25, font = 2) } # Implement function events <- suggest_recapture(data = dat_flapper, threshold = 10, fct = "id", add_additional = add_main, prompt = FALSE) ## Pass additional arguments via ... events <- suggest_recapture(data = dat_flapper, fct = "id", prompt = FALSE, type = "l")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.