This function fits a variety of mobility models to a supplied movement matrix (M) and covariates (D and N) using Bayesian MCMC inference. The function specifies the type of mobility model and serves as a wrapper for the fit_jags function.

mobility(
  data,
  model,
  type,
  hierarchical = FALSE,
  n_chain = 2,
  n_burn = 1000,
  n_samp = 1000,
  n_thin = 1,
  DIC = FALSE,
  parallel = FALSE
)

Arguments

data

a list containing mobility data and covariates. The list object must include EITHER M, D, and N OR M, D, N_orig, and N_dest. Details about each item are as follows:

M

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

D

named matrix of distances between 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_orig

named vector of population sizes for each origin

N_dest

named vector of population sizes for each destination

model

character vector indicating which mobility model to fit to the data. Mobility models include: 'gravity', 'radiation', and 'departure-diffusion'.

type

character vector indicating the particular sub-type of mobility model to fit.

Gravity model types include:

basic, transport, power, exp, power_norm, exp_norm, and Marshall

Radiation model types include:

basic and finite

Departure-diffusion model types include:

power, exp, and radiation

See model list vignette for more detailed description of each model type.

hierarchical

Applies only to the 'departure-diffusion' model. A logical argument indicating whether or not to fit \(\tau\) as a single parameter or hierarchically (as \(\tau_{pop}\) and \(\tau_i\)).

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

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

An object of class mobility.model containing model information, data, and fitted model parameters

See also

Other model: check(), compare(), fit_jags(), fit_prob_travel(), predict(), residuals(), summary()

Author

John Giles

Examples

mod <- mobility(data=mobility_matrices, model='gravity', type='transport')
#> ::Fitting transport gravity model for 10 origins and 10 destinations::
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 70 #> Unobserved stochastic nodes: 32 #> Total graph size: 417 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>
mod <- mobility(data=mobility_matrices, model='radiation', type='finite')
#> ::Fitting finite radiation model for 10 origins and 10 destinations::
mod <- mobility(data=mobility_matrices, model='departure-diffusion', type='power')
#> ::Fitting power departure-diffusion model for 10 origins and 10 destinations::
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 70 #> Unobserved stochastic nodes: 34 #> Total graph size: 970 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>