scrap/gravity.movement: Use the gravity model to predict movements across a...

gravity.movementR Documentation

Use the gravity model to predict movements across a landscape.

Description

Given a (dense) distance matrix distance giving the euclidean distances beween all pairs of sites, a vector of population sizes at these sites population, and a set of parameters theta, use the function flux to predict movement between all sites using a version of the gravity model (Viboud et al. 2006).

The model can be sped up by setting minpop and maxrange, see gravity.flux for details. If progress = TRUE a text progress bar is displayed and starting and total times reported.

Note that this is a pretty shitty prototype at the moment and will be re-written in a much more efficient way in the future!

Usage

  gravity.movement(distance, population, theta, minpop = 0, maxrange = Inf, progress = TRUE)

Arguments

distance

a distance matrix giving the euclidean distance between pairs of sites

population

a vector giving the population at all sites

theta

a vector of parameters in the order scalar, exponent on donor pop, exponent on recipient pop, exonent on distance

minpop

the minimum population size to consider (by default 1, consider all sites)

maxrange

the maximum distance between sites to consider (by default Inf, consider all sites)

progress

whether to display a progress bar and start and end times - can be useful for big model runs

Value

A (dense) symmetric matrix giving predicted movements between all sites

See Also

gravity.flux

Examples


# generate random coordinates and populations
n <- 30
coords <- matrix(runif(n * 2), ncol = 2)
pop <- round(runif(n) * 1000)

# calculate the distance between pairs of sites
d <- as.matrix(dist(coords))

# predict movement between them using the radiation model
move <- gravity.movement(d, pop,theta=c(1e-4,0.6,0.3,3))

# plot the points
plot(coords, pch = 16, cex = pop / 500,
     col = 'grey40', axes = FALSE,
     xlab = '', ylab = '')

# and add arrows showing movement
for(i in 2:n) {
  for(j in  (i - 1):n) {
    arrows(coords[i, 1],
           coords[i, 2],
           coords[j, 1],
           coords[j, 2],
           lwd = 2,
           length = 0.1,
           col = rgb(0, 0, 1, move[i, j] / (max(move) + 1)))
  }
}

SEEG-Oxford/movement documentation built on April 17, 2023, 4:17 p.m.