pacman::p_load(sf, spNetwork, tmap, classInt, viridis, tidyverse)In-Class Exercise 3.1: Kernel Density Estimation
In-class Exercise
In-class exercise 3.1
0.0 Class Notes
Spatial Point Patterns
Points as events, relates to activities
Issues with points: Highly affected by the size of the ‘dots’. KDE is more consistent
The points MUST be a population. Cannot be a sample or we will have sample bias.
KDE Setup
- Choose bandwidth
- Choose a kernel
NKDE: Network-Constrained Kernel Density Estimation
- Constrained by network
TNKDE: Temporal Network Kernel Density Estimate
- Accounts for both time and location
1.0 Setup
1.1 Dependencies
1.2 Importing and Changing CRS
network <- st_read(dsn="data/geospatial", layer="Punggol_St")Reading layer `Punggol_St' from data source
`/Users/matthewho/Work/Y3S2/IS415/Website/IS415/InClassEx/ICE3/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 2642 features and 2 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 34038.56 ymin: 40941.11 xmax: 38882.85 ymax: 44801.27
Projected CRS: SVY21 / Singapore TM
childcare <- st_read(dsn="data/geospatial", layer="Punggol_CC")Reading layer `Punggol_CC' from data source
`/Users/matthewho/Work/Y3S2/IS415/Website/IS415/InClassEx/ICE3/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 61 features and 1 field
Geometry type: POINT
Dimension: XYZ
Bounding box: xmin: 34423.98 ymin: 41503.6 xmax: 37619.47 ymax: 44685.77
z_range: zmin: 0 zmax: 0
Projected CRS: SVY21 / Singapore TM
tmap_mode('view')
tm_shape(childcare) +
tm_dots() +
tm_shape(network) +
tm_lines()tmap_mode('plot')Mindist = 0.5 * first param
lixels <- lixelize_lines(network, 750, mindist = 375)samples <- lines_center(lixels)densities <- nkde(network,
events=childcare,
w=rep(1, nrow(childcare)),
samples=samples,
kernel_name="quartic",
bw=300, div="bw",
method="simple",
digits=1,
tol=1,
grid_shape=c(1,1),
max_depth = 8,
agg=5,
sparse=TRUE,
verbose = FALSE)samples$density <- densities
lixels$density <- densitiessamples$density <- samples$density*1000
lixels$density <- lixels$density*1000tmap_mode('view')
tm_shape(lixels) +
tm_lines(col="density") +
tm_shape(childcare) +
tm_dots()tmap_mode('plot')