if (!require('pacman', character.only = T)){
install.packages('pacman')
}
Loading required package: pacman
library('pacman')
Teo Ren Jie
February 6, 2023
Firstly, the code below will check if pacman has been installed. If it has not been installed, R will download and install it, before activating it for use during this session.
Loading required package: pacman
Next, pacman assists us by helping us load R packages that we require, sf
, tidyverse
and tmap
.
Reading layer `study_area' from data source
`C:\renjie-teo\IS415-GAA\exercises\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
Reading layer `stores' from data source
`C:\renjie-teo\IS415-GAA\exercises\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
Warning in spdep::knearneigh(pnts, k): knearneigh: identical points found
Warning in spdep::knearneigh(pnts, k): knearneigh: kd_tree not available for
identical points
The variable nb stores the values of its neighbours. The number 6 defines 6 points including itself and 5 other neighbours.
The variable wt will balance weights according to distance to centre point. The further points will get lower weights.
FamilyMart <- stores %>%
filter(Name == "Family Mart")
A <- FamilyMart$Name
SevenEleven <- stores %>%
filter(Name == "7-Eleven")
B <- SevenEleven$Name
LCLQ <- local_colocation(A, B, nb, wt, 49) #49 = 50 simulations and immediately see p value
LCLQ_stores <- cbind(stores, LCLQ)
tmap_mode("view")
tmap mode set to interactive viewing