Learn R Programming

TDLM (version 1.0.0)

gof: Compute goodness-of-fit measures between observed and simulated OD matrices

Description

This function returns a data.frame where each row provides one or several goodness-of-fit measures between a simulated and an observed Origin-Destination matrix.

Usage

gof(
  sim,
  obs,
  measures = "all",
  distance = NULL,
  bin_size = 2,
  use_proba = FALSE,
  check_names = FALSE
)

Value

A data.frame providing one or several goodness-of-fit measure(s) between simulated OD(s) and an observed OD. Each row corresponds to a matrix sorted according to the list (or list of list) elements (names are used if provided).

Arguments

sim

an object of class TDLM (output of run_law_model(), run_law() or run_model()). A matrix or a list of matrices can also be used (see Note).

obs

a squared matrix representing the observed mobility flows.

measures

a vector of string(s) indicating which goodness-of-fit measure(s) to chose (see Details). If "all" is specified, then all measures will be calculated.

distance

a squared matrix representing the distance between locations. Only necessary for the distance-based measures.

bin_size

a numeric value indicating the size of bin used to discretize the distance distribution to compute CPC_d (2 "km" by default).

use_proba

a boolean indicating if the proba matrix should be used instead of the simulated OD matrix to compute the measure(s). Only valid for the output from run_law_model() with argument write_proba = TRUE (see Note).

check_names

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

Author

Maxime Lenormand (maxime.lenormand@inrae.fr)

Details

With nn the number of locations, T_ijT_ij the observed flow between location ii and location jj (argument obs), T_ijT_ij a simulated flow between location ii and location jj (a matrix from argument sim), N=_i,j=1^n T_ijN=_i,j=1^n T_ij the sum of observed flows and N=_i,j=1^n T_ijT=_i,j=1^n T_ij the sum of simulated flows.

Several goodness-of-fit measures have been considered measures = c("CPC", "NRMSE", "KL", "CPL", "CPC_d", "KS"). The Common Part of Commuters Gargiulo2012,Lenormand2012,Lenormand2016TDLM,

CPC(T,T) = 2_i,j=1^n min(T_ij,T_ij)N + N CPC(T,T) = 2_i,j=1^n min(T_ij,T_ij)N + N

the Normalized Root Mean Square Error (NRMSE),

NRMSE(T,T) = _i,j=1^n (T_ij-T_ij)^2N NRMSE(T,T) = _i,j=1^n (T_ij-T_ij)^2N

the Kullback–Leibler divergence Kullback1951TDLM,

KL(T,T) = _i,j=1^n T_ijN(T_ijNNT_ij) KL(T,T) = _i,j=1^n T_ijN(T_ijNNT_ij)

the Common Part of Links (CPL) Lenormand2016TDLM,

CPL(T,T) = 2_i,j=1^n 1_T_ij>0 1_T_ij>0_i,j=1^n 1_T_ij>0 + _i,j=1^n 1_T_ij>0 CPL(T,T) = 2_i,j=1^n 1_T_ij>0 1_T_ij>0_i,j=1^n 1_T_ij>0 + _i,j=1^n 1_T_ij>0

the Common Part of Commuters based on the disance Lenormand2016TDLM, noted CPC_d. Let us consider N_kN_k (and N_kN_k) the sum of observed (and simulated) flows at a distance comprised in the bin [bin_size*k-bin_size, bin_size*k[.

CPC_d(T,T) = 2_k=1^ min(N_k,N_k)N+N CPC_d(T,T) = 2_k=1^ min(N_k,N_k)N+N

and the Kolmogorv-Smirnov statistic and p-value Massey1951TDLM , noted KS. It is based on the observed and simulated flow distance distribution and computed with the ks_test function from the Ecume package.

References

Lenormand2016TDLM

Gargiulo2012TDLM

Lenormand2012TDLM

Kullback1951TDLM

Massey1951TDLM

See Also

run_law_model() run_law() run_model() run_law_model() check_format_names()

Examples

Run this code
data(mass)
data(distance)
data(od)

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

res <- run_law_model(
  law = "GravExp", mass_origin = mi, mass_destination = mj,
  distance = distance, opportunity = NULL, param = 0.01,
  model = "DCM", nb_trips = NULL, out_trips = Oi, in_trips = Dj,
  average = FALSE, nbrep = 1, maxiter = 50, mindiff = 0.01,
  write_proba = FALSE,
  check_names = FALSE
)

gof(
  sim = res, obs = od, measures = "CPC", distance = NULL, bin_size = 2,
  use_proba = FALSE,
  check_names = FALSE
)


Run the code above in your browser using DataLab