This function uses the gravity model formula to simulate a connectivity matrix based on the supplied model parameters. The
gravity model formula uses a Gamma distribution as the dispersal kernel in the denominator. A null model (where all model parameters = 1) can be
simulated by supplying only population sizes (N
) and pairwise distances (D
).
sim_gravity( D, N, theta = 1, omega_1 = 1, omega_2 = 1, gamma = 1, n = 1, mod = NULL, counts = FALSE )
D | matrix giving distances among the origins and destinations |
---|---|
N | vector of population sizes |
theta | scalar giving the proportionality constant of gravity formula (default = 1) |
omega_1 | scalar giving exponential scaling of origin population size (default = 1) |
omega_2 | scalar giving exponential scaling of destination population size (default = 1) |
gamma | scalar giving the dispersal kernel paramater (default = 1) |
n | number of simulations (requires argument |
mod | a gravity model object produced by the |
counts | logical indicating whether or not to return a count variable by scaling the connectivity matrix by origin population size (\(N_i\)) (default = FALSE) |
a matrix with values between 0 and 1 (if counts = FALSE
) or positive integers (if counts = TRUE
). If n > 1
then returns and array with 3 dimensions
Other simulation:
sim_mobility()
,
sim_param()
,
sim_prob_travel()
Other gravity:
fit_gravity()
n <- 5 ids <- LETTERS[1:n] # Distance matrix D <- get_distance_matrix(x=rnorm(n, 100, 5), y=rnorm(n, 20, 2), id=ids) # Vector of population sizes N <- rpois(n, 1000) names(N) <- ids # Simulate null model connectivity matrix pi_hat <- sim_gravity(D=D, N=N) # Simulate connectivity matrix given gravity model parameters pi_hat <- sim_gravity(D=D, N=N, theta=14, omega_1=13, omega_2=0.7, gamma=1.5) # Simulate many realizations of trip counts based on fitted model parameters M <- mobility_matrices$M D <- mobility_matrices$D N <- mobility_matrices$N mod <- summarize_mobility( fit_gravity(M, D, N) )#>#>#> 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 #> #>M_hat <- sim_gravity(D=D, N=N, n=5, mod=mod, counts=TRUE)