Description Usage Arguments Value Author(s) See Also Examples
View source: R/hmob_model_funcs.R
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) )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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) |
a runjags model object containing fitted gravity model paramters
John Giles
Other model:
fit.jags()
,
fit.prob.travel()
,
rjags.combine()
,
rjags.mcmc.list()
,
summarize.hmob()
Other gravity:
fit.prob.travel()
,
sim.gravity.duration()
,
sim.gravity()
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.