In-Class Exercise 5: Local Co-location Quotient

Author

Jennifer Poernomo

Published

February 6, 2023

Modified

March 24, 2023

Import Packages

pacman::p_load(sf, tidyverse, tmap, sfdep)

Import Dataset

Taiwan has two projection systems: one is Taiwan’s local version and one is related to China’s projection system.

study_area <- st_read(dsn = "data", layer = "study_area") %>%
  st_transform(crs = 3829)
Reading layer `study_area' from data source 
  `C:\Jenpoer\IS415-GAA\In-Class-Exercises\chapter-05\data' using driver `ESRI Shapefile'
Simple feature collection with 7 features and 7 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: 121.4836 ymin: 25.00776 xmax: 121.592 ymax: 25.09288
Geodetic CRS:  TWD97
stores <- st_read(dsn = "data", layer = "stores") %>%
  st_transform(crs = 3829)
Reading layer `stores' from data source 
  `C:\Jenpoer\IS415-GAA\In-Class-Exercises\chapter-05\data' using driver `ESRI Shapefile'
Simple feature collection with 1409 features and 4 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 121.4902 ymin: 25.01257 xmax: 121.5874 ymax: 25.08557
Geodetic CRS:  TWD97

Visualise the layers

tmap_mode("view")
tm_shape(study_area) +
  tm_polygons() +
  tm_shape(stores) +
  tm_dots(col="Name",
          size = 0.01,
          border.col = "black",
          border.lwd = 0.5) +
  tm_view(set.zoom.limits = c(12, 16))

Local Colocation Quotients (LCLQ)

Find 6 nearest neighbors + 1 (itself) - so that you can have an uneven split

nb <- include_self(st_knn(st_geometry(stores), 6))

Calculate weight matrix

wt <- st_kernel_weights(nb, stores, "gaussian", adaptive=TRUE)

Extract categories

family_mart <- stores %>% filter(Name == "Family Mart")
A <- family_mart$Name
seven_eleven <- stores %>% filter(Name == "7-Eleven")
B <- seven_eleven$Name

Derive local co-location quotient

  • A: Target

  • B: Neighbour that we want to find out is co-located or not

49 is the number of simulations. It will come up with the p-value immediately.

LCLQ <- local_colocation(A, B, nb, wt, 49)

Combine the stores and the LCLQ table

LCLQ_stores <- cbind(stores, LCLQ)

Visualise which data points have signs of co-location

tmap_mode("view")
tm_shape(study_area) +
  tm_polygons() +
  tm_shape(LCLQ_stores) +
  tm_dots(col="X7.Eleven",
          size = 0.01,
          border.col = "black",
          border.lwd = 0.5) +
  tm_view(set.zoom.limits = c(12, 16))