Title: | Auxillary functions for using the {ctmm} package efficiently |
---|---|
Description: | Utility functions to augment the the {ctmm} package. The additional function are targeted toward analysis of marine mammal telemetry, but can be used or easily modified for other situations. |
Authors: | Devin S. Johnson [aut, cre], Josh London [aut] |
Maintainer: | Devin S. Johnson <[email protected]> |
License: | CC0 |
Version: | 0.0.0.9107 |
Built: | 2025-01-04 06:28:51 UTC |
Source: | https://github.com/dsjohnson/ctmmUtils |
ctmm
PackageThis package is a collection of functions that enhance the ctmm
package for
for analysis of animal telemetry data.
Package: | ctmmUtils |
Type: | Package |
Version: | 0.0.0.9106 |
Date: | December 3, 2024 |
License: | CC0 |
LazyLoad: | yes |
This software package is developed and maintained by scientists at the NOAA Fisheries Pacific Islands Fisheries Science Center and should be considered a fundamental research communication. The recommendations and conclusions presented here are those of the authors and this software should not be construed as official communication by NMFS, NOAA, or the U.S. Dept. of Commerce. In addition, reference to trade names does not imply endorsement by the National Marine Fisheries Service, NOAA. While the best efforts have been made to insure the highest quality, tools such as this are under constant development and are subject to change.
Devin S. Johnson and Josh M. London Maintainer: Devin S. Johnson <[email protected]>
Safe method for calculating an AKDE with a barrier
akde_barrier( data, CTMM, VMM = NULL, R = list(), barrier = NULL, barrier_in = FALSE, debias = TRUE, weights = FALSE, smooth = TRUE, error = 0.001, res = 10, grid = NULL, ... )
akde_barrier( data, CTMM, VMM = NULL, R = list(), barrier = NULL, barrier_in = FALSE, debias = TRUE, weights = FALSE, smooth = TRUE, error = 0.001, res = 10, grid = NULL, ... )
data |
2D timeseries telemetry data represented as a telemetry object or list of objects. |
CTMM |
A ctmm movement model from the output of ctmm.fit or list of objects. |
VMM |
An optional vertical ctmm object for 3D home-range calculation. |
R |
A named list of raster covariates if CTMM contains an RSF model. |
barrier |
An 'sf' polygon data frame for enforcing hard boundaries |
barrier_in |
Locations are assumed to be inside the 'sf' polygons if 'barrier_in=TRUE' and outside of 'barrier' if 'barrier_in=FALSE'. |
debias |
Debias the distribution for area estimation (AKDEc). |
weights |
Optimally weight the data to account for sampling bias (See 'bandwidth' for akde details). |
smooth |
"Smooth" out errors from the data. |
error |
Target probability error. |
res |
Number of grid points along each axis, relative to the bandwidth. |
grid |
Optional grid specification via raster, UD, or list of arguments (See ‘Details’ in 'akde'). |
... |
Convert Wildlife Computers data imported with 'read_wc_dirs' to a 'telemetry' object from the 'ctmm' package.
as_telem(x, ...)
as_telem(x, ...)
x |
An sf data frame output by the function 'read_wc_dirs'. |
... |
Additional arguments to be passed to 'as.telemetry' |
Josh M. London, Devin S. Johnson
Parallel fitting of ctmm OUF family models
ctmm_select_parallel(tdata, ...)
ctmm_select_parallel(tdata, ...)
tdata |
A list of telemetry data objects. |
... |
Additional arguments (besides 'data' and 'CTMM'!) passed to 'ctmm.select' |
Calculates the appropriate cellsize
argument for making
a hexagon grid with st_make_grid
.
hex_size(area = NULL, radius = NULL, sep = NULL)
hex_size(area = NULL, radius = NULL, sep = NULL)
area |
A value (m^2) for the resulting area of a full hexagon cell |
radius |
The value for the distance (m) from the centroids to the edge of full hexagon cells. |
sep |
The distance (m) between centoids of the hexagon grid. |
Devin S. Johnson
See https://github.com/r-spatial/sf/issues/1505
Creates a data table that indicates the times of different phases of movement. This method uses changes in the overall dispersion rate of the animal from the 'base' time to detect changes in overall movement from small scale local movement to large scale migration.
migration_det( data, min_disp, max_num_mig = 1, min_phase_len = 3, grid_res = "day", base = "first", max_k = 100 )
migration_det( data, min_disp, max_num_mig = 1, min_phase_len = 3, grid_res = "day", base = "first", max_k = 100 )
data |
A 'telemytry' data object of locations (see 'as.telemetry') |
min_disp |
The minimum dispersion rate to be considered a migration interval, e.g. 10 for a 10km dispersion minimum. |
max_num_mig |
The maximum number of migration intervals. |
min_phase_len |
The minimum length of time that a migration or non-migration event will take, e.g., 7 implies a minimum of 7 time intervals for a phase. |
grid_res |
The temporal resolution at which migrations are detected. e.g., "day" (default) implies migration start and end is detected on a daily resolution. |
base |
The location at which dispersion is measured. Can be one of |
max_k |
The maximum degrees of freedom used by |
Devin S. Johnson
A function is created to evaluate the covariance function of the fitted OUF movement model
ouf_corfun(x)
ouf_corfun(x)
x |
A 'ctmm' object created by a call to |
The function returns a function to evaluate the covariance of the fitted
Ornstein-Ulenbeck Foraging movement model. The returned function has 2 arguments: (1) s
and (2) t
both vectors of times to evaluate the covariance function of the fitted
OUF model.
Devin S. Johnson
Using a correlation function created by ouf_corfun
from a fitted OUF related model a covariance (correlation) matrix is created for observations
at the user provided times.
ouf_covmat(x, times, inverse = FALSE)
ouf_covmat(x, times, inverse = FALSE)
x |
A |
times |
A vector of POSIX times at which the covariance matrix will be constructed. A 'telemetry' data object will also work. |
inverse |
Logical. Should the inverse covariance matrix be returned. Defaults to 'FALSE' |
Devin S. Johnson
Estimates the number of independent locations in a 'ctmm' data set using the mutual information method of Bartoszek (2016).
ouf_ess(x, times)
ouf_ess(x, times)
x |
A |
times |
A vector of POSIX times. A 'telemtry' data object will also work. |
This function uses the "mutual information" effective sample size of Bartoszek (2016) to calculate the equivalent number of independent animal locations. It also calculates individual contributions of each location using the regression effective sample size in Bartoszek (2016). The output is a named list with 'Ne' equal to the overall sample and 'w' is a vector of weights that sum to 1 overall. If you want the ESS value of each observation 'Ne * w' will provide it.
Devin S. Johnson
Bartoszek, K. (2016). Phylogenetic effective sample size. Journal of Theoretical Biology. 407:371-386. (See https://arxiv.org/pdf/1507.07113.pdf).
Parallel ESS calculation of ctmm OUF family models
ouf_ess_parallel(fits, tdata, ...)
ouf_ess_parallel(fits, tdata, ...)
fits |
A list of fitted 'ctmm' OUF family models |
tdata |
A list of telemetry data objects. |
... |
Additional arguments (besides 'data' and 'CTMM'!) passed to 'ctmm.select' |
PLot the animal dispersion from the base location over time. Points
are colored to reflect estimated migration and non-migration phases.
See migration_det
plot_disp(data, migr_tbl, interactive = FALSE)
plot_disp(data, migr_tbl, interactive = FALSE)
data |
Original data used by 'migration_det' call. |
migr_tbl |
Results table produced by 'migration_det'. |
interactive |
Logical. If 'TRUE' the 'plotly' package will be used to make the plot more interactive. |
Devin S. Johnson
Read and combine data downloaded from Wildlife Computers portal into individual directories.
read_wc_dirs(x, remove_duplicates = TRUE, default_ellipse = TRUE)
read_wc_dirs(x, remove_duplicates = TRUE, default_ellipse = TRUE)
x |
Directory containing the individual telemetry data directories. |
remove_duplicates |
Logical. Should observations with duplicated times be removed? The observation with the highest quality will be retained. |
default_ellipse |
Logical. Should a default set of Argos error ellipse values be added for 'FastGPS' and 'Argos' doppler locations? See 'set_default_ellipses' for further information. |
Devin S. Johnson, Josh M. London
This function will fill in missing ARGOS diagnostic ellipse data for either type of location, 'Argos' or 'FastGPS'. This is necessary for converting the data to 'telemetry' format for the 'ctmm' package. The default values used for non-KF Argos data (old location classes) are those in Vincent et al. (2002; Table 1 nonfilterd). For 'FastGPS' data, the values in Dujon et al. (2014; Table 1, 95%-tile unfiltered.).
Because Dujon et al. (2014) only used error magnitude, we assumed normally distributed error positions, . Thus, the error magitudes are Rayleigh distributed. So
we used the CDF of the Rayleigh distribution and the 95%-tile given in the table to solve for the appropriate
.
set_default_ellipses(x)
set_default_ellipses(x)
x |
An sf data frame output by the function 'read_wc_dirs'. |
sf::st_bbox
for a list of sf
or sfc
objects.sf::st_bbox
for a list of sf
or sfc
objects.
st_bbox_list(x, union = TRUE, as_sfc = FALSE)
st_bbox_list(x, union = TRUE, as_sfc = FALSE)
x |
A list of |
union |
Logical. Should the bounding box of the union be returned instead of a list of bounding boxes. |
as_sfc |
Logical. Should the bounding box (boxes) be returned as |
Devin S. Johnson
Expand an sf
bounding box by an expansion factor
st_expand(bbox, ef)
st_expand(bbox, ef)
bbox |
An |
ef |
Expansion factor, must be positive and length 1, 2 or 4.
If |
Josh M. London
Predicate function to use with st_filter
such that
such that elements of one spatial object are selected if
they are not contained at all in the other. See sf::st_within
st_not_within(x, y, sparse = TRUE, prepared = TRUE, ...)
st_not_within(x, y, sparse = TRUE, prepared = TRUE, ...)
x |
object of class sf, sfc or sfg |
y |
object of class sf, sfc or sfg; if missing, x is used |
sparse |
ogical; should a sparse index list be returned (TRUE) or a dense logical matrix? See sf::st_within. |
prepared |
ogical; prepare geometry for x, before looping over y? See sf::st_within. |
... |
passed on to s2_options |
Converts sf data with EPSG = 4326 from -180/180 specification to 0/360 for plotting with the mapview package etc.
st_to_360(x)
st_to_360(x)
x |
An sf data frame with EPSG=4326. |
Josh London
sf::st_union
for a list of sf
or sfc
objects.sf::st_union
for a list of sf
or sfc
objects.
st_union_list(x)
st_union_list(x)
x |
A list of |
Devin S. Johnson
Get UD Area Table
ud_area_table(uds, level.UD = 0.95, unit = NULL)
ud_area_table(uds, level.UD = 0.95, unit = NULL)
uds |
A named list of 'ctmm' 'UD' objects |
level.UD |
A vector of UD levels for computation |
unit |
Units for area estimates. Defaults to 'unit = "m^2"' |