Introducing the R Package CIM

R Markdown

This post introduces our recently published R package, CIM, to measure the impacts of migration on local population structures. We developed the methodology in this paper in 2018. This paper is one of the top ten most viewed articles in Population Studies

Installing

install.packages("CIM")
library(CIM)

This package enables quantifying the impact of internal migration on age, gender, educational population structures and inequality.

Example

Here I provide a short example of how this can be used to measure the impact of internal migration on residential age segregation in the Greater London Metropolitan Area, England, drawing on one-year migration data by age bands (i.e. 1-14, 15-29, 30-34, 45-64 and 65+) at the local authority level, 2011 UK Censuses. Local authorities comprising outside the Greater London Metropolitan Area are collapsed into a single area, labelled “the Rest of the UK”. I use the same approach employed by Rodríguez-Vignoli and Rowe (2017) to measure the impact of internal migration on residential educational segregation in the Greater Santiago, Chile.

Computation

Compute and print the CIM outputs

  CIM.duncan <- CIM(pop65over, pop1_14, pop15_29, pop30_44, pop45_64, calculation = "duncan", numerator = 1, DuncanAll= TRUE)
  CIM.duncan$duncan_index

Interpretation

The CIM for the Duncan index of dissimilarity indicates that internal migration has contributed to increase age segregation of the population aged 65 and over in the Greater London Metropolitan Area by 2.81% between 2010 and 2011 i.e. from 16.2% in 2010 to 19% in 2011.

Visualisation

To visualise where the population aged 65 and over in the Greater London Metropolitan Area is concentrating, we can map differences in the spatial distribution of this population across local authority districts.

First install and load the needed packages

install.packages(c("rgdal", "dplyr", "tmap"))
library(rgdal)
library(dplyr)
library(tmap)

NOTE: Download a shapefile containing the Greater London Local Authority Districts from the shapefile folder from this github repository

NOTE: The Local Authority Districts for the City of London and Westminster in our shapefile are combined to make our shapefile consistent with our migration data.

Read the shapefile.

Greater_London <- readOGR(dsn = ".", layer = "Greater_London_districts", stringsAsFactors = FALSE)

Plot the shapefile

  plot(Greater_London)

Obtain the differences in the spatial distribution of the population aged 65 and over across local authority districts using the CIM.Duncan function:

  CIM.duncan <- CIM(pop65over, pop1_14, pop15_29, pop30_44, pop45_64, calculation = "duncan", numerator = 1, DuncanAll= TRUE)
  Dun_65over <- CIM.duncan$duncan_results

Visualise the results

  head(Dun_65over)

Append these data to the shapefile using the local authority names as joiner

  Duncan_65p <- merge(Greater_London, Dun_65over, by.x = "name", by.y = 0)
  head(Duncan_65p@data)

Set to a static map view and create a map using tmap

  tmap_mode('plot')
  tm_shape(Duncan_65p) +
  tm_polygons("ASShareFV_diff", style="quantile",border.alpha = 0.1, palette = "YlOrRd", 
             title="ASShareFV_diff")+
  tm_compass(position = c("left", "bottom")) +
  tm_scale_bar(position = c("left", "bottom"))

Or, even better we can create an interactive map! by setting an interactive map view

  tmap_mode('view')
  tm_shape(Duncan_65p) +
  tm_polygons("ASShareFV_diff", style="quantile",border.alpha = 0.1, palette = "YlOrRd", 
               title="ASShareFV_diff")+
  tm_compass(position = c("left", "bottom")) +
  tm_scale_bar(position = c("left", "bottom"))
Avatar
Francisco Rowe
Senior Lecturer in Quantitative Human Geography

My research interests include human mobility and migration; economic geography and spatial inequality; computational social science.

Related