| Title: | Model Animal Movement With Continuous-Time Markov Chains |
|---|---|
| Description: | Model animal movement using continuous-time Markov chain models. |
| Authors: | Devin S. Johnson [aut, cre], James T. Thorson [aut], Janelle J. Badger [aut] |
| Maintainer: | Devin S. Johnson <[email protected]> |
| License: | CC0 |
| Version: | 0.0.0.936 |
| Built: | 2026-06-03 06:48:58 UTC |
| Source: | https://github.com/dsjohnson/walk |
Define specifics for model structure and fitting control
ctmc_model(form = ~1, link = "soft_plus", a = 1, L = 0, U = 0) ctmc_control( q_r = ctmc_model(), q_m = ctmc_model(), p = FALSE, delta = "uniform", form = "mult", norm = TRUE, clip = 0 )ctmc_model(form = ~1, link = "soft_plus", a = 1, L = 0, U = 0) ctmc_control( q_r = ctmc_model(), q_m = ctmc_model(), p = FALSE, delta = "uniform", form = "mult", norm = TRUE, clip = 0 )
form |
The form of the rate matrix entries. Can be one of: |
link |
A link funtion for the residency or movement model. One of |
a |
Scale parameter for the |
L |
Lower bound for general logit link |
U |
Upper bound for general logit link |
q_r |
A named list for the residency model. Must contain elements: |
q_m |
A named list for the movement portion of the model. See |
p |
Logical. Should a zero-inflation parameter be used. Necessary when there might be outliers when the location likelihood does not overlap likely locations. |
delta |
Vector of probabilities for the initial location. Can be one of |
norm |
Should the movement portion be adjusted to sum to 1. This is the parameterization suggested by Hewitt et al. (2023). |
clip |
Positive value for the maximum movement rate for all cells. All cells with modeled total movement rates above this value will be truncated to |
Hewitt, J., Gelfand, A. E., & Schick, R. S. (2023). Time-discretization approximation enriches continuous-time discrete-space models for animal movement. The Annals of Applied Statistics, 17:740-760.
Bhattacharyya distance for 2 raster probability densities
bc_raster(r, s)bc_raster(r, s)
r |
SpatRaster object |
s |
SpatRaster object |
Computes Bhattacharyya distance for 2 raster UDs.
Evaluate movement MMPP log-likelihood
ctmc_n2ll(par, data_list, debug = 0, ...)ctmc_n2ll(par, data_list, debug = 0, ...)
par |
Parameter vector |
data_list |
List of required data objects to evaluate likelihood |
debug |
For developers only, leave in the default setting. |
... |
Extra wiggle room for ignored arguments. |
Devin S. Johnson
Create sparse representations of design matrices for movement and resight models
dm_q_m(formula, ddl) dm_q_r(formula, ddl)dm_q_m(formula, ddl) dm_q_r(formula, ddl)
formula |
An |
ddl |
Design data list |
This function is not designed for end-users but is exported for posterity.
This function allows the user to calculate the clipping value for the CTMC rate matrix Q, such that Prob(residency in a cell < (time unit)/f) = prob at the maximum movement rate. This allows a definition, or sorts, for non-habitat. That is, if an animal would move so fast through a cell at to almost certainly reside in a cell less than (time unit)/f length of time. Then it is essentially not habitat for the individual.
find_clip(f, prob = 0.9, upper = 1000)find_clip(f, prob = 0.9, upper = 1000)
f |
Fraction of time unit in processed telemetry data |
prob |
Cummulative probability of residency time |
upper |
The maximum value for the clip value |
Fit CTMC movement model to telemetry data
fit_ctmc( walk_data, model_parameters = ctmc_control(), pen_fun = NULL, hessian = TRUE, reals = FALSE, start = NULL, method = "nlminb", fit = TRUE, eq_prec = 1e-08, debug = 0, ... )fit_ctmc( walk_data, model_parameters = ctmc_control(), pen_fun = NULL, hessian = TRUE, reals = FALSE, start = NULL, method = "nlminb", fit = TRUE, eq_prec = 1e-08, debug = 0, ... )
walk_data |
A design data list produced by the function |
model_parameters |
A named list giving specifications for the model. See |
pen_fun |
An optional penalty function. Should be on the scale of a log-prior distribution. |
hessian |
Logical. Should the Hessian matrix be calculated to obtain the parameter variance-covariance matrix. |
reals |
Calculate real values for expected residency, cell transition probabilities, and outlier proportion for observations. |
start |
Optional starting values for the parameter must be a list of the
form |
method |
Optimization method. See |
fit |
Logical. Should the likelihood be optimized? |
eq_prec |
Error rate of matrix exponential calculation. Defaults to |
debug |
Integer from 1-4. Opens browser() at various points in the function call. Mostly for package developers. |
... |
Additional arguments passed to the optimization function
|
Devin S. Johnson
General inverse logit function
gen_invLogit(x, L = 0, U = 1)gen_invLogit(x, L = 0, U = 1)
x |
numeric value |
L |
Lower bound |
U |
Upper bound |
Takes fitted model and produces a summary of the beta estimates.
get_betas(par, V = NULL, data_list)get_betas(par, V = NULL, data_list)
par |
Model estimated parameters |
V |
Optional variance-covariance matrix for the parameters. If none is given no standard errors will be provided for the real parameter estimates |
data_list |
The data list from a fitted model object |
Devin S. Johnson
Find gradient field of a elevation raster
get_grad(r, scale = TRUE)get_grad(r, scale = TRUE)
r |
SpatRaster object |
scale |
Logical, Should the gradient be scaled by resolution of the coordinates. Defaults
to |
Get the limiting utilization distribution of the CTMC movement process
get_lim_ud(fit = NULL, hpd = NULL, method = "lu", ...)get_lim_ud(fit = NULL, hpd = NULL, method = "lu", ...)
fit |
A fitted model object from |
hpd |
A vector of probabilities. Will return columns with highest probability area for each specified probability. E.g.,
|
method |
Method used for eigen decomposition. One of |
... |
Extra arguments to pass to |
Devin S. Johnson
Get movement transition matrix from fitted moveMMP object
get_Q(fit, sparse = TRUE)get_Q(fit, sparse = TRUE)
fit |
A fitted model object from |
sparse |
Logical. Should the matrix be returned in a sparse format from the |
Devin S. Johnson
Produce design data for use in fitting MMPP movement models
make_walk_data( proc_data, cell_data, grad = NULL, rast_mask = NULL, directions = "rook", debug = 0, ... )make_walk_data( proc_data, cell_data, grad = NULL, rast_mask = NULL, directions = "rook", debug = 0, ... )
proc_data |
A sparse matrix with rows corresponding to time steps and columns corresponding to cells. The entries are probabilities that the animal is located in the corresponding cell and time. |
cell_data |
A |
grad |
A character vector of names of |
rast_mask |
Raster mask for inaccessible cells when |
directions |
Neighborhood structure, one of |
debug |
Debugging level: 1-3 mainly for package developers. |
... |
Ignored arguments. |
Predict Movement Path From Fitted CTMC Model
predict_ctmc( fit, walk_data, aux_timestamp = NULL, trunc_tol = 1e-08, debug = 0, ... )predict_ctmc( fit, walk_data, aux_timestamp = NULL, trunc_tol = 1e-08, debug = 0, ... )
fit |
A fitted model object produced by |
walk_data |
A design data list produced by the function |
aux_timestamp |
Additional POSIX times for which location prediction is desired. |
trunc_tol |
Level for truncating small location prediction probabilities. |
debug |
Developer debugging. |
... |
Aditional arguments passed to internal function |
Devin S. Johnson
Hewitt, J., Gelfand, A. E., & Schick, R. S. (2023). Time-discretization approximation enriches continuous-time discrete-space models for animal movement. The Annals of Applied Statistics, 17:740-760.
ctmm telemetry data object to a SpatRaster stack from the terra package.Convert ctmm telemetry data object to a SpatRaster stack from the terra package.
proc_telem( data, cell_data, time_unit = "hours", return_type = "sparse", max_err = NULL, trunc = 1e-08, return_inadmissible = FALSE )proc_telem( data, cell_data, time_unit = "hours", return_type = "sparse", max_err = NULL, trunc = 1e-08, return_inadmissible = FALSE )
data |
A |
cell_data |
A |
time_unit |
Unit of measurement for numeric conversion of the POSIX timestamps
in the telemetry data. Defaults to |
return_type |
Type of object returned. One if |
max_err |
The maximum error in meters. If unspecified it will be set to 4 times the maximum error standard deviation as determined by the UERE and HDOP of the telemetry data. |
trunc |
The smallest probability value that is considered to be > 0. Defaults to 1.0e-8. |
return_inadmissible |
Logical. If there are locations outside the admissible areas of movement return the observations and raster cell numbers. |
This function takes the HDOP information in the telemetry object to
produce a SpatRaster likelihood surface over the SpatRaster defined by
the raster argument for each location. This can then be passed to
CTMC HMM fitting functions.
Devin S. Johnson
Fill raster holes and NAs with local interpolation
raster_fill(r)raster_fill(r)
r |
SpatRaster object |
Uses focal means to infill holes and NAs
Z transform a raster
raster_z(r)raster_z(r)
r |
A spatRaster object from the terra package |
Denote cells where the animal cannot travel
set_barrier_mask(x, y, overlap = 0.95)set_barrier_mask(x, y, overlap = 0.95)
x |
a polygon object that denotes places where the animal cannot travel |
y |
A |
overlap |
The amount of overlap betwen the raster cell and polygon such that the cell is considered
"inside" the polygon. Defaults to |
Soft-plus function
softPlus(x, a = 1)softPlus(x, a = 1)
x |
numeric value |
a |
scale parameter, |