This function fits a full mobility model to the supplied movement matrix using Bayesian MCMC inference. The full mobility model uses the fit_prob_travel function to estimate the probability of travel outside the origin location and the fit_gravity function to estimate travel to all destination locations. Unlike fit_gravity, fit_mobility requires the diagonal of movement matrix M to be filled.

fit_mobility(
  M,
  D,
  N,
  n_chain = 2,
  n_burn = 1000,
  n_samp = 1000,
  n_thin = 1,
  prior = NULL,
  DIC = FALSE,
  parallel = FALSE
)

Arguments

M

named matrix of trip counts among all \(ij\) location pairs

D

named matrix of distances among all \(ij\) location pairs

N

named vector of population sizes for all locations (either N or both n_orig and n_dest must be supplied)

n_chain

number of MCMC sampling chains

n_burn

number of iterations to discard before sampling of chains begins (burn in)

n_samp

number of iterations to sample each chain

n_thin

interval to thin samples

prior

a list object containing shape and rate parameters to be used as priors

DIC

logical indicating whether or not to calculate the Deviance Information Criterion (DIC) (default = FALSE)

parallel

logical indicating whether or not to run MCMC chains in parallel or sequentially (default = FALSE)

Value

a runjags model object containing fitted gravity model paramters

See also

Examples

M <- mobility_matrices$M D <- mobility_matrices$D N <- mobility_matrices$N mod <- 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.