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.920 |
Built: | 2025-01-04 05:27:38 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 )
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 )
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 |
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). |
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.
Evaluate movement MMPP log-likelihood
ctmc_n2ll(par, data_list, check_rho = NULL, debug = 0, ...)
ctmc_n2ll(par, data_list, check_rho = NULL, debug = 0, ...)
par |
Parameter vector |
data_list |
List of required data objects to evaluate likelihood |
check_rho |
Check if rho is too big for uniformitazation calculation of expQ. Value is the size of rho to check. |
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.
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, check_rho = NULL, 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, check_rho = NULL, 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 |
check_rho |
Check if rho is too big for uniformitazation calculation of expQt. Value is the size for which rho is too big, causing likelihood calculation error. |
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
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 moveMMPP 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 moveMMPP 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 |
—. |
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.
SpatRaster
stackConvert ctmm telemetry data object to a terra SpatRaster
stack
proc_telem( data, cell_data, time_unit = "hours", return_type = "sparse", max_err = NULL, trunc = 1e-08 )
proc_telem( data, cell_data, time_unit = "hours", return_type = "sparse", max_err = NULL, trunc = 1e-08 )
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. |
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
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, |