Learn R Programming

blvim (version 0.1.1)

flows_df: Extract the flow matrix from a spatial interaction model object in data frame format

Description

Extract the flow matrix from a spatial interaction model object in data frame format

Usage

flows_df(sim, ...)

Value

a data frame of flows between origin locations and destination locations with additional content if available (see Details).

Arguments

sim

a spatial interaction model object

...

additional parameters (not used currently)

Details

This function extracts the flow matrix in a long format. Each row contains the flow between an origin location and a destination location. The resulting data frame has at least three columns:

  • origin_idx: identifies the origin location by its index from 1 to the number of origin locations

  • destination_idx: identifies the destination location by its index from 1 to the number of destination locations

  • flow: the flow between the corresponding location

In addition, if location information is available, it will be included in the data frame as follows:

  • location names are included using columns origin_name or destination_name

  • positions are included using 2 or 3 columns (per location type, origin or destination) depending on the number of dimensions used for the location. The names of the columns are by default origin_x, origin_y and origin_z ( and equivalent names for destination location) unless coordinate names are specified in the location positions. In this latter case, the names are prefixed by origin_ or destination_. For instance, if the destination location position coordinates are named "longitude" and "latitude", the resulting columns will be destination_longitude and destination_latitude.

See Also

location_positions(), location_names(), flows()

Examples

Run this code
distances <- french_cities_distances[1:10, 1:10] / 1000 ## convert to km
production <- log(french_cities$population[1:10])
attractiveness <- log(french_cities$area[1:10])
## rescale to production
attractiveness <- attractiveness / sum(attractiveness) * sum(production)
## simple case (no positions and default names)
model <- static_blvim(distances, production, 1.5, 1 / 500, attractiveness)
head(flows_df(model))
## with location data
positions <- as.matrix(french_cities[1:10, c("th_longitude", "th_latitude")])
model <- static_blvim(distances, production, 1.5, 1 / 500, attractiveness,
  origin_data = list(positions = positions),
  destination_data = list(positions = positions)
)
head(flows_df(model))
## with names
origin_names(model) <- french_cities$name[1:10]
destination_names(model) <- french_cities$name[1:10]
head(flows_df(model))

Run the code above in your browser using DataLab