::p_load(tidyverse, tmap, sf, sfdep) pacman
In-class Excerise 5: Advanced Spatial Point Patterns Analysis
1 Getting Started
2 Importing Data
<-st_read("data",
studyArealayer="study_area") |>
st_transform(crs=3829)
Reading layer `study_area' from data source
`/Users/pengyouyun/youyunpeng/IS415/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("data",
storeslayer="stores") |>
st_transform(crs=3829)
Reading layer `stores' from data source
`/Users/pengyouyun/youyunpeng/IS415/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)+ #always display polygons before points
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))
3 Local Colocation coefficient
for colocation coefficient
character or factor vector
neighbour list
<-include_self(
nbst_knn(st_geometry(stores), 6)# search for 6 nearest neighbours, using adaptive method, to always use even number, since we include self, always get one group to be more than another
)
<-st_kernel_weights(nb,
wt
stores,"gaussian",
adaptive=TRUE) #convert into a weight metrics, see table, under column value: shows the distance weight allocated for each neighbour
<-stores |>
FamilyMartfilter(Name == "Family Mart")
<- FamilyMart$Name
A
<-stores |>
SevenElevenfilter(Name == "7-Eleven")
<- SevenEleven$Name
B
<-local_colocation(A, B, nb, wt, 49) #A is my target, B is the neighbour im interested in, nb is nearest neighbour list, wt is the weight. We would immediately get p value from this
LCLQ
#NA means cannot find any useful index to work with
<-cbind(stores,LCLQ) # inorder to map data, we have to comnbine the stores and colocation values. we put stores as the first one, as we want to keep the geometric properties in the object
LCLQ_stores
# dont have unique identifier, ie cannot use left join or right join
tmap_mode("view")
tm_shape(studyArea) +
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))
#able to visualise the colocation points/isolated points
st_knn: identifies the k nearest neighbors for given point geometry