
Estimate mobility flows based on different trip distribution laws and models
Source:R/run_law_model.R
run_law_model.RdThis function estimates mobility flows using different distribution laws and models. As described in Lenormand et al. (2016), the function uses 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 based on this law.
Usage
run_law_model(
law = "Unif",
mass_origin,
mass_destination = mass_origin,
distance = NULL,
opportunity = NULL,
param = NULL,
model = "UM",
nb_trips = 1000,
out_trips = NULL,
in_trips = out_trips,
average = FALSE,
nbrep = 3,
maxiter = 50,
mindiff = 0.01,
write_proba = FALSE,
check_names = FALSE
)Arguments
- law
A
characterindicating which law to use (see Details).- mass_origin
A
numericvector representing the mass at the origin (i.e. demand).- mass_destination
A
numericvector representing the mass at the destination (i.e. attractiveness).- distance
A squared
matrixrepresenting the distance between locations (see Details).- opportunity
A squared
matrixrepresenting the number of opportunities between locations (see Details). Can be easily computed withextract_opportunities().- param
A
numericvector or a singlenumericvalue used to adjust the importance ofdistanceoropportunityassociated with the chosen law. Not necessary for the original radiation law or the uniform law (see Details).- model
A
characterindicating which model to use.- nb_trips
A
numericvalue indicating the total number of trips. Must be anintegerifaverage = FALSE(see Details).- out_trips
A
numericvector representing the number of outgoing trips per location. Must be a vector of integers ifaverage = FALSE(see Details).- in_trips
A
numericvector representing the number of incoming trips per location. Must be a vector of integers ifaverage = FALSE(see Details).- average
A
booleanindicating if the average mobility flow matrix should be generated instead of thenbrepmatrices based on random draws (see Details).- nbrep
An
integerindicating the number of replications associated with the model run. Note thatnbrep = 1ifaverage = TRUE(see Details).- maxiter
An
integerindicating the maximal number of iterations for adjusting the Doubly Constrained Model (see Details).- mindiff
A
numericstrictly positive value indicating the stopping criterion for adjusting the Doubly Constrained Model (see Details).- write_proba
A
booleanindicating if the estimation of the probability to move from one location to another obtained with the distribution law should be returned along with the flow estimations.- check_names
A
booleanindicating whether the location IDs used as matrix rownames and colnames should be checked for consistency (see Note).
Value
An object of class TDLM. A list of list of matrices containing for each
parameter value the nbrep simulated matrices and the matrix of
probabilities (called proba) if write_proba = TRUE. If
length(param) = 1 or law = "Rad" or law = "Unif" only a list of
matrices will be returned.
Details
First, we compute the matrix proba estimating the probability to observe a
trip from one location to another. This probability is based on the demand
(argument mass_origin) and the attractiveness (argument
mass_destination). Note that the population is typically used as a
surrogate for both quantities (this is why mass_destination = mass_origin
by default). It also depends on the distance between locations
(argument distance) OR the number of opportunities between locations
(argument opportunity) depending on the chosen law. Both the effect of the
distance and the number of opportunities can be adjusted with a parameter
(argument param) except for the original radiation law and the uniform law.
In this package we consider eight probabilistic laws described in details in Lenormand et al. (2016). Four gravity laws (Barthelemy, 2011), three intervening opportunity laws (Schneider, 1959; Simini et al., 2012; Yang et al., 2014) and a uniform law.
Gravity law with an exponential distance decay function (
law = "GravExp"). The argumentsmass_origin,mass_destination(optional),distanceandparamwill be used.Normalized gravity law with an exponential distance decay function (
law = "NGravExp"). The argumentsmass_origin,mass_destination(optional),distanceandparamwill be used.Gravity law with a power distance decay function (
law = "GravPow"). The argumentsmass_origin,mass_destination(optional),distanceandparamwill be used.Normalized gravity law with a power distance decay function (
law = "NGravPow"). The argumentsmass_origin,mass_destination(optional),distanceandparamwill be used.Schneider's intervening opportunities law (
law = "Schneider"). The argumentsmass_origin,mass_destination(optional),opportunityandparamwill be used.Radiation law (
law = "Rad"). The argumentsmass_origin,mass_destination(optional) andopportunitywill be used.Extended radiation law (
law = "RadExt"). The argumentsmass_origin,mass_destination(optional),opportunityandparamwill be used.Uniform law (
law = "Unif"). The argumentmass_originwill be used to extract the number of locations.
Second, we propose four constrained models to generate the flows from these
distribution of probability as described in Lenromand et al. (2016).
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 (argument out_trips) AND/OR the number of in-coming
(argument in_trips) according to the model. The sum of out-going trips
should be equal to the sum of in-coming trips.
Unconstrained model (
model = "UM"). Onlynb_tripswill be preserved (argumentsout_tripsandin_tripswill not be used).Production constrained model (
model = "PCM"). Onlyout_tripswill be preserved (argumentsnb_tripsandin_tripswill not be used).Attraction constrained model (
model = "ACM"). Onlyin_tripswill be preserved (argumentsnb_tripsandout_tripswill not be used).Doubly constrained model (
model = "DCM"). Bothout_tripsandin_tripswill be preserved (argumentsnb_tripswill not be used). The doubly constrained model is based on an Iterative Proportional Fitting process (Deming & Stephan, 1940). The argumentsmaxiter(50 by default) andmindiff(0.01 by default) can be used to tune the model.mindiffis the minimal tolerated relative error between the simulated and observed marginals.maxiterensures that the algorithm stops even if it has not converged toward themindiffwanted 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.
Note
All inputs should be based on the same number of
locations, sorted in the same order. It is recommended to use the location ID
as matrix rownames and matrix colnames and to set
check_names = TRUE to verify that everything is consistent before running
this function (check_names = FALSE by default). Note that the function
check_format_names() can be used to validate all inputs
before running the main package's functions.
References
Barthelemy M (2011). Spatial Networks. Physics Reports 499, 1-101.
Deming WE & Stephan FF (1940) On a Least Squares Adjustment of a Sample Frequency Table When the Expected Marginal Totals Are Known. Annals of Mathematical Statistics 11, 427-444.
Lenormand M, Bassolas A, Ramasco JJ (2016) Systematic comparison of trip distribution laws and models. Journal of Transport Geography 51, 158-169.
Schneider M (1959) Gravity models and trip distribution theory. Papers of the regional science association 5, 51-58.
Simini F, González MC, Maritan A & Barabási A (2012) A universal model for mobility and migration patterns. Nature 484, 96-100.
Yang Y, Herrera C, Eagle N & González MC (2014) Limits of Predictability in Commuting Flows in the Absence of Data for Calibration. Scientific Reports 4, 5662.
See also
For more details illustrated with a practical example, see the vignette: https://rtdlm.github.io/TDLM/articles/TDLM.html#run-functions.
Associated functions:
run_law(), run_model(), gof().
Author
Maxime Lenormand (maxime.lenormand@inrae.fr)
Examples
data(mass)
data(distance)
mi <- as.numeric(mass[, 1])
mj <- mi
N <- 1000
res <- run_law_model(law = "GravExp",
mass_origin = mi,
mass_destination = mj,
distance = distance,
opportunity = NULL,
param = 0.01,
model = "UM",
nb_trips = N,
out_trips = NULL,
in_trips = NULL,
average = TRUE,
nbrep = 2,
maxiter = 50,
mindiff = 0.01,
write_proba = FALSE,
check_names = FALSE)
print(res)
#> Argument Value
#> 1 Law GravExp
#> 2 Model UM
#> 3 #Replications 1 (average)
#> 4 #Parameters 1
#> 5 Parameter 0.01