This function takes a fitted mobility model and calculates goodness of fit metrics. Model objects produced by the fit_prob_travel, fit_gravity, fit_mobility or summarize_mobility functions are accepted. If the Deviance Information Criterin (DIC) was calculated in the supplied model object, it is included in output. When plot_check = TRUE, two plots are shown containing the posterior distribution of trip counts compared to observed data and a Normal Q-Q plot showing the quantiles of model residuals against those expected from a Normal distribution. Goodness of fit metrics include:

DIC

Deviance Information Criterion

RMSE

Root Mean Squared Error

MAPE

Mean Absolute Percent Error

R2

R-squared

check_mobility(M, D = NULL, N = NULL, mod, plot_check = TRUE)

Arguments

M

named matrix of trip counts among all \(ij\) location pairs

D

named matrix of distances among all \(ij\) location pairs

N

named vector of population sizes for all locations

mod

model output from either the fit_ functions or summarize_mobility function

plot_check

logical indicating whether to plot the Posterior Predictive Check and Normal Q-Q Plot (default = TRUE)

Value

a list of goodness of fit measures

See also

Examples

M <- mobility_matrices$M D <- mobility_matrices$D N <- mobility_matrices$N total <- rowSums(M, na.rm=TRUE) mod_travel <- summarize_mobility( fit_prob_travel(total-diag(M), total) )
#> These missing locations will inherit population mean:
#> C F I J
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 6 #> Unobserved stochastic nodes: 9 #> Total graph size: 26 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>
mod_gravity <- summarize_mobility( fit_gravity(M, D, N) )
#> ::Fitting gravity model for 10 origins and 10 destinations::
#> Using uniformative priors
#> 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 #> #>
mod_mobility <- summarize_mobility( fit_mobility(M, D, N) )
#> Estimating probability of travel outside origin...
#> These missing locations will inherit population mean:
#> C F I J
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 6 #> Unobserved stochastic nodes: 9 #> Total graph size: 26 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>
#> Complete.
#> Estimating travel among destinations with gravity model...
#> ::Fitting gravity model for 10 origins and 10 destinations::
#> Using uniformative priors
#> 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 #> #>
#> Complete.
check_mobility(M=M, mod=mod_travel)
#> $MAE #> [1] 0.000129315 #> #> $MAPE #> [1] 0.001209039 #> #> $R2 #> [1] 0.9999999 #>
check_mobility(M=M, D=D, N=N, mod=mod_gravity)
#> $RMSE #> [1] 776.7367 #> #> $MAPE #> [1] 4.82373 #> #> $R2 #> [1] 0.9047785 #>
check_mobility(M=M, D=D, N=N, mod=mod_mobility)
#> $RMSE #> [1] 301.6076 #> #> $MAPE #> [1] 1.124274 #> #> $R2 #> [1] 0.961084 #>