Learn R Programming

migest (version 2.0.5)

index_distance: Summary indices of migration distance

Description

Summary indices of migration distance

Usage

index_distance(
  m = NULL,
  d = NULL,
  orig = "orig",
  dest = "dest",
  flow = "flow",
  dist = "dist",
  long = TRUE
)

Value

A tibble with 3 summary measures where

mean

Mean migration distance from Bell et. al. (2002) - not discussed in text but given in Table 6

median

Mean migration distance from Bell et. al. (2002)

decay

Distance decay parameter obtained from a Poisson regression model (flow ~ orig + dest + log(dist))

Arguments

m

A matrix or data frame of origin-destination flows. For matrix the first and second dimensions correspond to origin and destination respectively. For a data frame ensure the correct column names are passed to orig, dest and flow.

d

A matrix or data frame of origin-destination distances. For matrix the first and second dimensions correspond to origin and destination respectively. For a data frame ensure the correct column names are passed to orig, dest and dist. Region names should match those in m.

orig

Character string of the origin column name (when m is a data frame rather than a matrix)

dest

Character string of the destination column name (when m is a data frame rather than a matrix)

flow

Character string of the flow column name (when m is a data frame rather than a matrix)

dist

Character string of the distance column name (when dist is a data frame rather than a matrix)

long

Logical to return a long data frame with index values all in one column

Examples

Run this code
# single year
index_distance(
  m = subset(korea_gravity, year == 2020),
  d = subset(korea_gravity, year == 2020),
  dist = "dist_cent"
)

# multiple years
library(dplyr)
library(tidyr)
library(purrr)

korea_gravity %>%
  select(year, orig, dest, flow, dist_cent) %>%
  group_nest(year) %>%
  mutate(i = map2(
    .x = data, .y = data,
    .f = ~index_distance(m = .x, d = .y, dist = "dist_cent", long = FALSE)
  )) %>%
  select(-data) %>%
  unnest(i)

Run the code above in your browser using DataLab