Skip to contents

This 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.

Usage

# S3 method for class 'sim_list'
median(
  x,
  na.rm = FALSE,
  flows = c("full", "destination", "attractiveness"),
  method = c("euclidean"),
  return_distances = FALSE,
  ...
)

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 distances attribute of the resulting object? (defaults to FALSE)

...

additional parameters (not used currently)

Value

a spatial interaction model, an object of class sim with additional attributes

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:

  • index gives the index of the mode in the original sim_list

  • distortion gives 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.