Construct Movement Matrices for Unstructured or CTMC Movement
Get_Movement.RdGenerates movement matrices for a population model based on either unstructured
multinomial logit movement or a Continuous Time Markov Chain (CTMC) formulation.
Also calculates a movement penalty if applicable. For CTMC movement, projection
years are supported: covariate lookups are capped at the last historical year
(n_yrs), so CTMC parameters are frozen at their final historical values
during projection unless ctmc_move_dat is extended with projection-year rows.
Usage
Get_Movement(
move_type,
do_recruits_move,
n_pop,
n_regions,
n_yrs,
n_proj_yrs_devs,
n_ages,
n_sexes,
n_seas,
move_pars,
move_devs,
use_fixed_movement,
Fixed_Movement = NULL,
ctmc_move_dat = NULL,
preference_formula = NULL,
diffusion_formula = NULL,
log_move_diffusion_pars,
move_preference_pars,
area_r,
adjacency_mat,
ctmc_diffusion_bounds,
ctmc_diffusion_eps = 0.1,
seasdur = rep(1, n_seas),
ctmc_scale_by_seasdur = 0,
expm_nsub = 0
)Arguments
- move_type
Integer flag indicating movement type: 0 = unstructured Markov, 1 = CTMC movement.
- do_recruits_move
Integer flag: 0 = recruits (age 1) do not move, 1 = recruits move.
- n_pop
Number of populations.
- n_regions
Number of spatial regions.
- n_yrs
Number of years in the observed (historical) data.
- n_proj_yrs_devs
Number of projected years. Extends the year dimension of the movement array beyond
n_yrs; CTMC covariate lookups are capped atn_yrsunlessctmc_move_datcontains projection-year rows.- n_ages
Number of age classes.
- n_sexes
Number of sexes.
- n_seas
Number of seasons.
- move_pars
Array of movement parameters for unstructured (multinomial logit) movement, dimensioned
[pop, from_region, counter, year, seas, age, sex].counterindexes then_regions - 1non-reference destinations. Ignored whenmove_type == 1oruse_fixed_movement == 1.- move_devs
Array of origin-destination movement deviations, dimensioned
[pop, origin_region, counter, year, seas, age, sex], wherecounterindexes adjacent non-diagonal destinations from each origin region. Applied as multiplicative offsets (exp(move_devs)) to off-diagonal diffusion rates in CTMC movement, or as additive offsets to logit-scale parameters in unstructured movement. Always indexed on the actual (possibly projected) year.- use_fixed_movement
Integer flag: 0 = estimate movement, 1 = use fixed matrix.
- Fixed_Movement
Fixed movement matrix used when
use_fixed_movement == 1, dimensioned[pop, from_region, to_region, year, seas, age, sex]. Ignored otherwise.- ctmc_move_dat
Data.frame of CTMC covariates. Required when
move_type == 1. Must include columnspop,regions,years,seas,ages,sexes, and any covariates referenced indiffusion_formulaorpreference_formula.- preference_formula
R formula specifying preference (taxis) covariates for CTMC movement. Required when
move_type == 1.- diffusion_formula
R formula specifying diffusion covariates for CTMC movement. Required when
move_type == 1.- log_move_diffusion_pars
Log-scale diffusion parameters (\(\theta_k\)) for CTMC movement. Exponentiated and squared internally (
exp(2 * log_theta)). Required whenmove_type == 1.- move_preference_pars
Preference (taxis) parameters (\(\gamma_k\)) for CTMC movement, on the natural scale. Required when
move_type == 1.- area_r
Numeric vector of region areas (length
n_regions) used to scale diffusion rates. Required whenmove_type == 1.- adjacency_mat
Square
[n_regions x n_regions]matrix defining connectivity among regions (1 = adjacent, 0 = not adjacent). Required whenmove_type == 1.- ctmc_diffusion_bounds
How the off-diagonal generator entries are kept non-negative (a valid generator). Every form is evaluated on the adjacency edges only, so non-edges stay exactly zero. Taking \(d\) as the preference gradient \(\gamma_i - \gamma_j\) along the edge from \(j\) to \(i\) and \(\theta_j\) as the diffusion rate out of \(j\):
"none"(or0)\(q = \theta_j + d\), unbounded. Valid only where diffusion outweighs taxis everywhere.
"softplus"(or1)softplus of \(\theta_j + d\) with width
ctmc_diffusion_eps. Smooth, but an edge where taxis cancels diffusion has a floor ofeps * log(2), so the width is a minimum exchange rate and not only a smoothing constant."upwind"(or2)discontinuous Galerkin / finite volume upwind flux, \(q = \theta_j + \max(d, 0)\): diffusion is kept whole and only the down-gradient half of the taxis flux is added, so positivity never depends on the two cancelling.
- ctmc_diffusion_eps
Positive numeric width of the softplus used when
ctmc_diffusion_boundsis"softplus". Default 0.1.- seasdur
Numeric vector of length
n_seasgiving season durations (summing to 1). Used to scale the CTMC generator whenctmc_scale_by_seasdur == 1. Defaults torep(1, n_seas), which reproduces the unscaled behavior.- ctmc_scale_by_seasdur
Integer flag controlling the time units of the CTMC generator.
1= treat \(Q\) as an annual rate and exponentiate \(Q \cdot \mathrm{seasdur}[s]\) for each season;0= treat \(Q\) as a per season rate and exponentiate it once per season irrespective of season duration. Only affectsmove_type == 1withn_seas > 1. Defaults to0here so that callers passing an unscaled generator get the arithmetic they expect; the user facing default is1, set bySetup_Mod_Movement.- expm_nsub
Integer controlling how the CTMC generator is exponentiated into movement fractions:
0(default) usesMatrix::expm, a value \(n \ge 1\) uses the implicit backward Euler scheme \((I - Q\Delta/n)^{-n}\), which is cheaper to differentiate but is a first-order approximation. Only read whenmove_type == 1anduse_fixed_movement == 0. Seemat_exp.
Value
A list with components:
MovementArray of movement fractions dimensioned
[pop, from_region, to_region, year, seas, age, sex]. Populated for all three movement configurations.MrateInstantaneous rate matrix (generator \(Q\)) dimensioned
[pop, from_region, to_region, year, seas, age, sex]. Populated only whenmove_type == 1anduse_fixed_movement == 0;NULLotherwise. Stored unscaled by season duration, so that consumers combining it with mortality must applyseasdur[seas]themselves (seebuild_seas_operator).move_penNumeric movement penalty used for regularization. For CTMC movement, equal to \(\sum_k \gamma_k^2\), a ridge on the preference coefficients applied once (not per stratum) that pins the otherwise unidentified level and spread. Zero for unstructured or fixed movement.
Details
Three movement configurations are supported:
Fixed movement (
use_fixed_movement == 1):Fixed_Movementis used directly with no estimation.Unstructured multinomial logit movement (
move_type == 0): movement fractions are estimated via a softmax transform ofmove_pars + move_devs.CTMC movement (
move_type == 1): a generator matrix \(Q = D + Z\) is constructed from diffusion (\(D\)) and taxis (\(Z\)) components, then exponentiated viamat_exp(eitherMatrix::expmor the implicit solve, perexpm_nsub) to obtain movement fractions. During projection years (y > n_yrs), covariate lookups are capped atn_yrs(i.e., CTMC base parameters are frozen at their last historical values), whilemove_devscontinue to use the actual projected year index.