::p_load(tidyverse, sf, sfdep, tmap) pacman
In-class_Ex05
Importing Data
<- st_read(dsn = "data", layer="study_area") %>% st_transform(crs = 3829) studyArea
Reading layer `study_area' from data source
`/Users/yashica/Desktop/xtc0/IS415-GAA/In-class_Ex/In-class_Ex05/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
<- st_read(dsn = "data", layer="stores") %>% st_transform(crs = 3829) stores
Reading layer `stores' from data source
`/Users/yashica/Desktop/xtc0/IS415-GAA/In-class_Ex/In-class_Ex05/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
Visualising the sf layers
tmap_mode("view")
tm_shape(studyArea) +
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)
<- include_self(
nb st_knn(st_geometry(stores), 6)
#choose 6 and include yourself so total is 7. In the end, you'll get 3 and 4 so no even split which is good
)
<- st_kernel_weights(nb,
wt
stores,"gaussian",
adaptive = TRUE)
<- stores %>%
FamilyMart filter(Name == "Family Mart") #select out all the stores with the name "Family Mart as dataframe
<- FamilyMart$Name
A
<- stores %>%
SevenEleven filter(Name == "7-Eleven")
<- SevenEleven$Name
B
<- local_colocation(A, B, nb, wt, 49)
LCLQ #now all the parameter values you have
#A is target
#B is the neighbour i want to find if A is colocated with it
<- cbind(stores, LCLQ)
LCLQ_stores #doing a combination: LCLQ is appended over to stores. Cannot do a relational join coz these 2 layers have no unique identifier (only 1,2,3,4...)
#LHS should be store coz we want the geometry. Will always inherit the property of the first value.
tmap_mode("view")
Pls make sure to check the number of events. Should be 1409.
In in-class exercise 5, we saw the graph and now we’re learning how to deal with colocation.
Colocation quotient and pvalue - please find yourself.