::p_load(sf, sfdep, tmap, plotly, tidyverse, zoo) pacman
In-class_Ex07: Emerging Hot Spot Analysis: sfdep methods
Overview
Emerging Hot Spot Analysis (EHSA) is a spatio-temporal analysis method for revealing and describing how hot spot and cold spot areas evolve over time. The analysis consist of four main steps:
- Building a space-time cube,
- Calculating Getis-Ord local Gi* statistic for each bin by using an FDR correction,
- Evaluating these hot and cold spot trends by using Mann-Kendall trend test,
- Categorising each study area location by referring to the resultant trend z-score and p-value for each location with data, and with the hot spot z-score and p-value for each bin.
Getting Started
Installing and Loading the R Packages
As usual, p_load()
of pacman package will be used to check if the necessary packages have been installed in R, if yes, load the packages on R environment.
Five R packages are need for this in-class exercise, they are: sf, sfdep, tmap, and tidyverse.
The Data
For the purpose of this in-class exercise, the Hunan data sets will be used. There are two data sets in this use case, they are:
- Hunan, a geospatial data set in ESRI shapefile format, and
- Hunan_GDPPC, an attribute data set in csv format. Before getting started, reveal the content of Hunan_GDPPC.csv by using Notepad and MS Excel.
Importing geospatial data
In the code chunk below, st_read() of sf package is used to import Hunan shapefile into R.
<- st_read(dsn = "data/geospatial",
hunan layer = "Hunan")
Reading layer `Hunan' from data source
`C:\michellefaithl\is415-gaa-michellefaith\In-class_Ex\In-class_ex07\data\geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 88 features and 7 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 108.7831 ymin: 24.6342 xmax: 114.2544 ymax: 30.12812
Geodetic CRS: WGS 84
Importing attribute table
In the code chunk below, read_csv()
of readr is used to import Hunan_GDPPC.csv into R.
<- read_csv("data/aspatial/Hunan_GDPPC.csv") GDPPC
Creating a Time Series Cube
In the code chunk below, spacetime()
of sfdep ised used to create an spatio-temporal cube.
<- spacetime(GDPPC, hunan,
GDPPC_st .loc_col = "County",
.time_col = "Year")
Next, is_spacetime_cube()
of sfdep package will be used to verify if GDPPC_st is indeed an space-time cube object.
is_spacetime_cube(GDPPC_st)
[1] TRUE