fit.gravity: Fit gravity model to movement matrix

Description Usage Arguments Value Author(s) See Also Examples

View source: R/hmob_model_funcs.R

Description

This function fits gravity model parameters to a supplied movement matrix using Bayesian MCMC inference. The function defines the model and serves as a wrapper for the run.jags function in the runjags package. Gravity model formula:

θ * ( N_i^ω_1 N_j^ω_2 / f(d_ij) )

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
fit.gravity(
  M,
  D,
  N = NULL,
  N.orig = NULL,
  N.dest = NULL,
  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.orig

named vector of population sizes for each origin

N.dest

named vector of population sizes for each destination.

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

a runjags model object containing fitted gravity model paramters

Author(s)

John Giles

See Also

Other model: fit.jags(), fit.prob.travel(), rjags.combine(), rjags.mcmc.list(), summarize.hmob()

Other gravity: fit.prob.travel(), sim.gravity.duration(), sim.gravity()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
M <- load.obj(2, './data/movement_data_arrays_full.Rdata')            # M.route
D <- load.obj(1, './data/distance_matrix_named.rdata')                # distance.matrix
N <- load.obj(1, './data/N_pop.rdata')                                # N.pop

M <- M[1:5, 1:5]

districts <- attributes(M)$dimnames$origin 
D <- D[districts, districts]
N <- N[names(N) %in% districts]

out <- fit.gravity(M=M,
                   D=D,
                   N=N,
                   n.chain=2,
                   n.adapt=1000,
                   n.burn=4000,
                   n.samp=4000,
                   n.thin=1,
                   parallel=F)

summary(out)

gilesjohnr/hmob documentation built on Aug. 8, 2020, 1:26 a.m.