This function simulates a mobility matrix based on the supplied model parameters. The full mobility model estimates both quantity of travel within a location (along the matrix diagonal) as well as the quantity among all origins and destinations (off-diagonals). For multiple stochastic simulations, the mod argument must be supplied with a mobility model object produced by the fit_mobility function. If mean values are supplied to the named parameter arguments (theta, omega_1, omega_2, gamma, tau), a single point estimate of the mobility matrix will be returned. A null model (where all model parameters = 1) can be simulated by supplying only population sizes (N) and pairwise distances (D).

sim_mobility(
  D,
  N,
  theta = 1,
  omega_1 = 1,
  omega_2 = 1,
  gamma = 1,
  tau = 0.5,
  n = 1,
  mod = NULL,
  counts = FALSE
)

Arguments

D

matrix giving distances among the origins and destinations

N

vector of population sizes

theta

scalar giving the proportionality constant of gravity formula (default = 1)

omega_1

scalar giving exponential scaling of origin population size (default = 1)

omega_2

scalar giving exponential scaling of destination population size (default = 1)

gamma

scalar giving the dispersal kernel paramater (default = 1)

tau

scalar or vector giving the probability of travel outside origin

n

number of simulations (requires argument mod to be supplied with a gravity model object)

mod

a mobility model object produced by the fit_mobility or summarize_mobility functions

counts

logical indicating whether or not to return a count variable by scaling the mobility matrix by origin population size (\(N_i\)) (default = FALSE)

Value

a matrix with values between 0 and 1 (if counts = FALSE) or positive integers (if counts = TRUE). If n > 1 then returns and array with 3 dimensions

See also

Other simulation: sim_gravity(), sim_param(), sim_prob_travel()

Examples

M <- mobility_matrices$M D <- mobility_matrices$D N <- mobility_matrices$N # Simulate null model for given D and N # assumes 0.5 probability of traveling outside origin and null gravity # for probability of travel to all destinations sim_mobility(D, N)
#> destination #> origin A B C D E F #> A 0.50000000 0.04228902 0.016228557 0.054944961 0.04778214 0.028942627 #> B 0.04061993 0.50000000 0.042352380 0.022244158 0.07979472 0.092431100 #> C 0.03517051 0.09555755 0.500000000 0.022726628 0.09588919 0.091252679 #> D 0.10691082 0.04506073 0.020404694 0.500000000 0.05748019 0.033070544 #> E 0.04379109 0.07613472 0.040550015 0.027073502 0.50000000 0.109190848 #> F 0.03238173 0.10766356 0.047109560 0.019015584 0.13329944 0.500000000 #> G 0.05183875 0.03565771 0.011101908 0.017772384 0.03402451 0.022494263 #> H 0.02948079 0.02393654 0.007074728 0.010691498 0.01957669 0.013720973 #> I 0.01800880 0.01369618 0.004106690 0.006360484 0.01158442 0.008016011 #> J 0.06906613 0.04766421 0.022701606 0.053153127 0.08763882 0.040964373 #> destination #> origin G H I J #> A 0.10733147 0.11636505 0.05627544 0.029840732 #> B 0.07091490 0.09075203 0.04110977 0.019781000 #> C 0.04981600 0.06051903 0.02781153 0.021256886 #> D 0.07159984 0.08211373 0.03867391 0.044685536 #> E 0.06456312 0.07081786 0.03317634 0.034702515 #> F 0.05210825 0.06059412 0.02802558 0.019802171 #> G 0.50000000 0.19851332 0.11396029 0.014636856 #> H 0.10413069 0.50000000 0.28332573 0.008062351 #> I 0.07550782 0.35787823 0.50000000 0.004841370 #> J 0.07014165 0.07365476 0.03501532 0.500000000
# Simulate point estimates for some mean parameter values sim_mobility(D, N, theta = 3, omega_1 = 2, omega_2 = 0.7, gamma = 1.5, tau=rbeta(length(N), 2, 2))
#> destination #> origin A B C D E #> A 0.745898500 0.016684363 0.0060932169 0.0245340199 0.015859327 #> B 0.039000733 0.344141822 0.0656964238 0.0161621478 0.087527749 #> C 0.028972971 0.133636471 0.4096032114 0.0153900034 0.106316357 #> D 0.159608104 0.044980282 0.0210561297 0.3974071099 0.051288522 #> E 0.050513737 0.119263454 0.0712161416 0.0251106932 0.206076789 #> F 0.010634931 0.066403353 0.0295263037 0.0048939569 0.072401485 #> G 0.038836980 0.022818979 0.0060900529 0.0079724778 0.016833408 #> H 0.015047392 0.011338276 0.0027988408 0.0033606360 0.006637155 #> I 0.004521247 0.003088393 0.0007789867 0.0009704596 0.001901354 #> J 0.066089732 0.039023592 0.0197052594 0.0456289686 0.077001928 #> destination #> origin F G H I J #> A 0.011496112 0.06413836 0.06293443 0.03910470 0.0132569662 #> B 0.167791306 0.08809104 0.11085040 0.06244051 0.0182978693 #> C 0.151765061 0.04782334 0.05566109 0.03203666 0.0187948432 #> D 0.034416182 0.08565485 0.09143970 0.05460525 0.0595438668 #> E 0.249280638 0.08854605 0.08841660 0.05237914 0.0491967599 #> F 0.751227021 0.02125718 0.02316962 0.01346484 0.0070213056 #> G 0.013913922 0.43872588 0.24770618 0.19905762 0.0080445083 #> H 0.005988364 0.09780975 0.14908544 0.70496310 0.0029710452 #> I 0.001682855 0.03800848 0.34089666 0.60728151 0.0008700571 #> J 0.037837640 0.06623107 0.06194785 0.03751529 0.5490186762
# Simulate multiple stochastic realizations of a mobility matrix from # fitted mobility model parameters mod <- summarize_mobility( fit_mobility(M, D, N) )
#> Estimating probability of travel outside origin...
#> These missing locations will inherit population mean:
#> C F I J
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 6 #> Unobserved stochastic nodes: 9 #> Total graph size: 26 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>
#> Complete.
#> Estimating travel among destinations with gravity model...
#> ::Fitting gravity model for 10 origins and 10 destinations::
#> Using uniformative priors
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 74 #> Unobserved stochastic nodes: 30 #> Total graph size: 1196 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>
#> Complete.
mod_sim <- sim_mobility(D, N, n=3, mod=mod, counts=TRUE)