Compute the "median" of a collection of spatial interaction models
Source:R/sim_stats.R
median.sim_list.RdThis function computes all pairwise distances between spatial interaction
models (SIMs) of its x parameter, using sim_distance() with the specified
distance parameters. Then it returns the "median" of the collection defined
as the SIM that is in average the closest to all the other SIMs. Tie breaking
uses the order of the SIMs in the collection.
Arguments
- x
a collection of spatial interaction models, an object of class
sim_list- na.rm
not used
- flows
"full"(default),"destination"or"attractiveness", see details.- method
the distance measure to be used. Currently only
"euclidean"is supported- return_distances
should the distances computed to find the median be returned as a
distancesattribute of the resulting object? (defaults toFALSE)- ...
additional parameters (not used currently)
Details
As distance calculation can be slow in a large collection of SIMs, the
distance object can be returned as a distances attribute of the median SIM
by setting the return_distances parameter to TRUE. In addition, the
returned SIM has always two attributes:
indexgives the index of the mode in the originalsim_listdistortiongives the mean of the distances from the median SIM to all the other SIMs
Examples
positions <- matrix(rnorm(15 * 2), ncol = 2)
distances <- as.matrix(dist(positions))
production <- rep(1, 15)
attractiveness <- rep(1, 15)
all_flows <- grid_blvim(distances,
production,
c(1.1, 1.25, 1.5),
c(1, 2, 3),
attractiveness,
epsilon = 0.1
)
all_flows_median <- median(all_flows)
attr(all_flows_median, "index")
#> [1] 5
attr(all_flows_median, "distortion")
#> [1] 1.417701
median(all_flows, flows = "destination")
#> Spatial interaction model with 15 origin locations and 15 destination locations
#> • Model: Wilson's production constrained
#> • Parameters: return to scale (alpha) = 1.25 and inverse cost scale (beta) = 2
#> ℹ The BLV model converged after 900 iterations.
median(all_flows, flows = "attractiveness")
#> Spatial interaction model with 15 origin locations and 15 destination locations
#> • Model: Wilson's production constrained
#> • Parameters: return to scale (alpha) = 1.25 and inverse cost scale (beta) = 2
#> ℹ The BLV model converged after 900 iterations.