Learn R Programming

TDLM (version 1.0.0)

run_model: Estimate mobility flows based on different trip distribution models

Description

This function estimates mobility flows using different distribution models. As described in Lenormand2016;textualTDLM, we propose a two-step approach to generate mobility flows by separating the trip distribution law, gravity or intervening opportunities, from the modeling approach used to generate the flows from this law. This function only uses the second step to generate mobility flow based on a matrix of probabilities using different models.

Usage

run_model(
  proba,
  model = "UM",
  nb_trips = 1000,
  out_trips = NULL,
  in_trips = out_trips,
  average = FALSE,
  nbrep = 3,
  maxiter = 50,
  mindiff = 0.01,
  check_names = FALSE
)

Value

An object of class TDLM. A list of matrices containing the nbrep simulated matrices.

Arguments

proba

a squared matrix of probability. The sum of the matrix element must be equal to 1. It will be normalized automatically if it is not the case.

model

a character indicating which model to use.

nb_trips

a numeric value indicating the total number of trips. Must be an integer if average = FALSE (see Details).

out_trips

a numeric vector representing the number of outgoing trips per location. Must be a vector of integers if average = FALSE (see Details).

in_trips

a numeric vector representing the number of incoming trips per location. Must be a vector of integers if average = FALSE (see Details).

average

a boolean indicating if the average mobility flow matrix should be generated instead of the nbrep matrices based on random draws (see Details).

nbrep

an integer indicating the number of replications associated to the model run. Note that nbrep = 1 if average = TRUE (see Details).

maxiter

an integer indicating the maximal number of iterations for adjusting the Doubly Constrained Model (see Details).

mindiff

a numeric strictly positive value indicating the stopping criterion for adjusting the Doubly Constrained Model (see Details).

check_names

a boolean indicating if the ID location are used as vector names, matrix rownames and colnames and if they should be checked (see Note).

Author

Maxime Lenormand (maxime.lenormand@inrae.fr)

Details

We propose four constrained models to generate the flow from the matrix of probabilities. These models respect different level of constraints. These constraints can preserve the total number of trips (argument nb_trips) OR the number of out-going trips O_iO_i (argument out_trips) AND/OR the number of in-coming D_jD_j (argument in_trips) according to the model. The sum of out-going trips _i O_i_i O_i should be equal to the sum of in-coming trips _j D_j_j D_j.

  1. Unconstrained model (model = "UM"). Only nb_trips will be preserved (arguments out_trips and in_trips will not be used).

  2. Production constrained model (model = "PCM"). Only out_trips will be preserved (arguments nb_trips and in_trips will not be used).

  3. Attraction constrained model (model = "ACM"). Only in_trips will be preserved (arguments nb_trips and out_trips will not be used).

  4. Doubly constrained model (model = "DCM"). Both out_trips and in_trips will be preserved (arguments nb_tripswill not be used). The doubly constrained model is based on an Iterative Proportional Fitting process Deming1940TDLM. The arguments maxiter (50 by default) and mindiff (0.01 by default) can be used to tune the model. mindiff is the minimal tolerated relative error between the simulated and observed marginals. maxiter ensures that the algorithm stops even if it has not converged toward the mindiff wanted value.

By default, when average = FALSE, nbrep matrices are generated from proba with multinomial random draws that will take different forms according to the model used. In this case, the models will deal with positive integers as inputs and outputs. Nevertheless, it is also possible to generate an average matrix based on a multinomial distribution (based on an infinite number of drawings). In this case, the models' inputs can be either positive integer or real numbers and the output (nbrep = 1 in this case) will be a matrix of positive real numbers.

References

Lenormand2016TDLM

Deming1940TDLM

See Also

gof() run_law_model() run_law() check_format_names()

Examples

Run this code
data(mass)
data(od)

proba <- od / sum(od)

Oi <- as.numeric(mass[, 2])
Dj <- as.numeric(mass[, 3])

res <- run_model(
  proba = proba,
  model = "DCM", nb_trips = NULL, out_trips = Oi, in_trips = Dj,
  average = FALSE, nbrep = 3, maxiter = 50, mindiff = 0.01,
  check_names = FALSE
)

# print(res)

Run the code above in your browser using DataLab