1. Assignment Overview

1.1. Objective

  • To gain understanding on the supply and demand of childcare and kindergarten services at planning subzone level.

  • To gain understanding on the geographic distribution of childcare and kindergarten in Singapore

1.2. Dataset

  • The latest childcare and kindergarten data sets from data.gov.sg. URA Master Plan 2014 Planning Subzone GIS data from data.gov.sg

  • Singapore Residents by Planning AreaSubzone, Age Group, Sex and Type of Dwelling, June 2011-2019. This data set is available at Singapore Department of Statistics.

2. Installing R Packages

Firstly, I will start with installing all the R packages that required for this take home assignment.

  • rgal, maptools, raster, spastat, tmap

This code chunk installs R packages such as rgal, maptools, raster, spastat, tmap

packages = c('rgdal', 'maptools', 'raster','spatstat', 'tmap', 'sf', 'tidyverse', 'gridExtra', 'plotly') 
for (p in packages){
  if(!require(p, character.only = T)){
  install.packages(p)
  }
  library(p,character.only = T)
}
## Loading required package: rgdal
## Loading required package: sp
## rgdal: version: 1.5-16, (SVN revision 1050)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
## Path to GDAL shared files: C:/Users/AUNG MYO NAING/Documents/R/win-library/4.0/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
## Path to PROJ shared files: C:/Users/AUNG MYO NAING/Documents/R/win-library/4.0/rgdal/proj
## Linking to sp version:1.4-2
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Loading required package: maptools
## Checking rgeos availability: FALSE
##      Note: when rgeos is not available, polygon geometry     computations in maptools depend on gpclib,
##      which has a restricted licence. It is disabled by default;
##      to enable gpclib, type gpclibPermit()
## Loading required package: raster
## Loading required package: spatstat
## Loading required package: spatstat.data
## Loading required package: nlme
## 
## Attaching package: 'nlme'
## The following object is masked from 'package:raster':
## 
##     getData
## Loading required package: rpart
## 
## spatstat 1.64-1       (nickname: 'Help you I can, yes!') 
## For an introduction to spatstat, type 'beginner'
## 
## Note: spatstat version 1.64-1 is out of date by more than 4 months; we recommend upgrading to the latest version.
## 
## Attaching package: 'spatstat'
## The following objects are masked from 'package:raster':
## 
##     area, rotate, shift
## Loading required package: tmap
## Loading required package: sf
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
## Loading required package: tidyverse
## Registered S3 method overwritten by 'cli':
##   method     from    
##   print.boxx spatstat
## -- Attaching packages --------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::collapse() masks nlme::collapse()
## x tidyr::extract()  masks raster::extract()
## x dplyr::filter()   masks stats::filter()
## x dplyr::lag()      masks stats::lag()
## x dplyr::select()   masks raster::select()
## Loading required package: gridExtra
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
## Loading required package: plotly
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:raster':
## 
##     select
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout

3. Data Preparation

3.1. Loading Datasets into SpatialDataFrame

Next, I will import following geospatial data into R using st_read() function of sf package and read_csv() of readr.

  • MP14_SUBZONE_WEB_PL - a polygon feature layer in ESRI shapefile format
  • Childcare : a point feature layer in KML File Format
  • Kindergarten : a point feature layer in KML File Format
  • Singapore Population Data in CSV Format
sf_subzone <- st_read(dsn = "data/geospatial", 
                  layer = "MP14_SUBZONE_WEB_PL")
## Reading layer `MP14_SUBZONE_WEB_PL' from data source `C:\IS415_Geospatial\TakeHomeAssignment_01\TakeHomeAssignment01\Data\Geospatial' using driver `ESRI Shapefile'
## Simple feature collection with 323 features and 15 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
## projected CRS:  SVY21
sf_childcare = st_read("data/geospatial/child-care-services-kml.kml")
## Reading layer `CHILDCARE' from data source `C:\IS415_Geospatial\TakeHomeAssignment_01\TakeHomeAssignment01\Data\Geospatial\child-care-services-kml.kml' using driver `KML'
## Simple feature collection with 1545 features and 2 fields
## geometry type:  POINT
## dimension:      XYZ
## bbox:           xmin: 103.6824 ymin: 1.248403 xmax: 103.9897 ymax: 1.462134
## z_range:        zmin: 0 zmax: 0
## geographic CRS: WGS 84
sf_kindergarten = st_read("data/geospatial/kindergartens-kml.kml")
## Reading layer `KINDERGARTENS' from data source `C:\IS415_Geospatial\TakeHomeAssignment_01\TakeHomeAssignment01\Data\Geospatial\kindergartens-kml.kml' using driver `KML'
## Simple feature collection with 448 features and 2 fields
## geometry type:  POINT
## dimension:      XYZ
## bbox:           xmin: 103.6887 ymin: 1.247759 xmax: 103.9717 ymax: 1.455452
## z_range:        zmin: 0 zmax: 0
## geographic CRS: WGS 84
popagesex <- read_csv("data/aspatial/respopagesextod2011to2019.csv")
## Parsed with column specification:
## cols(
##   PA = col_character(),
##   SZ = col_character(),
##   AG = col_character(),
##   Sex = col_character(),
##   TOD = col_character(),
##   Pop = col_double(),
##   Time = col_double()
## )

3.2. Checking the content and projection of loaded SpatialDataFrames

After importing the data, it is important to check to that the data has been imported correctly. Therefore, I will check the content of the loaded objects.

This code chunk check the content of the popagesex.

list(popagesex)
## [[1]]
## # A tibble: 883,728 x 7
##    PA        SZ               AG    Sex    TOD                         Pop  Time
##    <chr>     <chr>            <chr> <chr>  <chr>                     <dbl> <dbl>
##  1 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Males  HDB 1- and 2-Room Flats       0  2011
##  2 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Males  HDB 3-Room Flats             10  2011
##  3 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Males  HDB 4-Room Flats             30  2011
##  4 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Males  HDB 5-Room and Executive~    50  2011
##  5 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Males  HUDC Flats (excluding th~     0  2011
##  6 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Males  Landed Properties             0  2011
##  7 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Males  Condominiums and Other A~    40  2011
##  8 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Males  Others                        0  2011
##  9 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Femal~ HDB 1- and 2-Room Flats       0  2011
## 10 Ang Mo K~ Ang Mo Kio Town~ 0_to~ Femal~ HDB 3-Room Flats             10  2011
## # ... with 883,718 more rows

Observation: Based on the contents of popagesex data, there are a lot of unnecessary data that are not the interest of this assignment. Therefore, the data cleaning and transforming will need to be performed. _____________________________________________________________________________________________ This code chunk will check the first few contents and projection of sf_mpsz spatial data object by using st_crs() function of sf package.

head(sf_subzone, n=3)
## Simple feature collection with 3 features and 15 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 28160.23 ymin: 28369.47 xmax: 32362.39 ymax: 30247.18
## projected CRS:  SVY21
##   OBJECTID SUBZONE_NO    SUBZONE_N SUBZONE_C CA_IND      PLN_AREA_N PLN_AREA_C
## 1        1          1 MARINA SOUTH    MSSZ01      Y    MARINA SOUTH         MS
## 2        2          1 PEARL'S HILL    OTSZ01      Y          OUTRAM         OT
## 3        3          3    BOAT QUAY    SRSZ03      Y SINGAPORE RIVER         SR
##         REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR   Y_ADDR
## 1 CENTRAL REGION       CR 5ED7EB253F99252E 2014-12-05 31595.84 29220.19
## 2 CENTRAL REGION       CR 8C7149B9EB32EEFC 2014-12-05 28679.06 29782.05
## 3 CENTRAL REGION       CR C35FEFF02B13E0E5 2014-12-05 29654.96 29974.66
##   SHAPE_Leng SHAPE_Area                       geometry
## 1   5267.381  1630379.3 MULTIPOLYGON (((31495.56 30...
## 2   3506.107   559816.2 MULTIPOLYGON (((29092.28 30...
## 3   1740.926   160807.5 MULTIPOLYGON (((29932.33 29...
st_crs(sf_subzone)
## Coordinate Reference System:
##   User input: SVY21 
##   wkt:
## PROJCRS["SVY21",
##     BASEGEOGCRS["SVY21[WGS84]",
##         DATUM["World Geodetic System 1984",
##             ELLIPSOID["WGS 84",6378137,298.257223563,
##                 LENGTHUNIT["metre",1]],
##             ID["EPSG",6326]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["Degree",0.0174532925199433]]],
##     CONVERSION["unnamed",
##         METHOD["Transverse Mercator",
##             ID["EPSG",9807]],
##         PARAMETER["Latitude of natural origin",1.36666666666667,
##             ANGLEUNIT["Degree",0.0174532925199433],
##             ID["EPSG",8801]],
##         PARAMETER["Longitude of natural origin",103.833333333333,
##             ANGLEUNIT["Degree",0.0174532925199433],
##             ID["EPSG",8802]],
##         PARAMETER["Scale factor at natural origin",1,
##             SCALEUNIT["unity",1],
##             ID["EPSG",8805]],
##         PARAMETER["False easting",28001.642,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8806]],
##         PARAMETER["False northing",38744.572,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8807]]],
##     CS[Cartesian,2],
##         AXIS["(E)",east,
##             ORDER[1],
##             LENGTHUNIT["metre",1,
##                 ID["EPSG",9001]]],
##         AXIS["(N)",north,
##             ORDER[2],
##             LENGTHUNIT["metre",1,
##                 ID["EPSG",9001]]]]

Observation: It is observed that the sf_subzone is in SVY21 projection but the Coordinate Reference System (CRS) is WGS 84. Therefore, it will need to be converted to ESPG 3414. _____________________________________________________________________________________________ This code chunk will check the projection of sf_childcare spatial data object by using st_crs() of sf package.

st_crs(sf_childcare)
## Coordinate Reference System:
##   User input: WGS 84 
##   wkt:
## GEOGCRS["WGS 84",
##     DATUM["World Geodetic System 1984",
##         ELLIPSOID["WGS 84",6378137,298.257223563,
##             LENGTHUNIT["metre",1]]],
##     PRIMEM["Greenwich",0,
##         ANGLEUNIT["degree",0.0174532925199433]],
##     CS[ellipsoidal,2],
##         AXIS["geodetic latitude (Lat)",north,
##             ORDER[1],
##             ANGLEUNIT["degree",0.0174532925199433]],
##         AXIS["geodetic longitude (Lon)",east,
##             ORDER[2],
##             ANGLEUNIT["degree",0.0174532925199433]],
##     ID["EPSG",4326]]

Observation: Based on the result, it is observed that the sf_childcare’s current projection system is WGS 84. Therefore, it will need to be converted to ESPG 3414. _____________________________________________________________________________________________ This code chunk will check the projection of sf_kindergarten spatial data object using st_crs() of sf package.

st_crs(sf_kindergarten)
## Coordinate Reference System:
##   User input: WGS 84 
##   wkt:
## GEOGCRS["WGS 84",
##     DATUM["World Geodetic System 1984",
##         ELLIPSOID["WGS 84",6378137,298.257223563,
##             LENGTHUNIT["metre",1]]],
##     PRIMEM["Greenwich",0,
##         ANGLEUNIT["degree",0.0174532925199433]],
##     CS[ellipsoidal,2],
##         AXIS["geodetic latitude (Lat)",north,
##             ORDER[1],
##             ANGLEUNIT["degree",0.0174532925199433]],
##         AXIS["geodetic longitude (Lon)",east,
##             ORDER[2],
##             ANGLEUNIT["degree",0.0174532925199433]],
##     ID["EPSG",4326]]

Observation: Based on the result, it is observed that the sf_kindergarten’s current projection system is WGS 84. Therefore, it needs to be converted to ESPG 3414.

3.3. Assigning and transforming the projection of loaded SpatialDataFrames

Since all spatial data objects are in WGS84, they need to be assigned and transformed into CRS ESPG 3414.

This code chunk will assign EPSG 3414 to the projection of sf_subzone and save as a new object called sf_subzone3414.

sf_subzone3414 <- st_transform(sf_subzone, 3414)
st_crs(sf_subzone3414)
## Coordinate Reference System:
##   User input: EPSG:3414 
##   wkt:
## PROJCRS["SVY21 / Singapore TM",
##     BASEGEOGCRS["SVY21",
##         DATUM["SVY21",
##             ELLIPSOID["WGS 84",6378137,298.257223563,
##                 LENGTHUNIT["metre",1]]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["degree",0.0174532925199433]],
##         ID["EPSG",4757]],
##     CONVERSION["Singapore Transverse Mercator",
##         METHOD["Transverse Mercator",
##             ID["EPSG",9807]],
##         PARAMETER["Latitude of natural origin",1.36666666666667,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8801]],
##         PARAMETER["Longitude of natural origin",103.833333333333,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8802]],
##         PARAMETER["Scale factor at natural origin",1,
##             SCALEUNIT["unity",1],
##             ID["EPSG",8805]],
##         PARAMETER["False easting",28001.642,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8806]],
##         PARAMETER["False northing",38744.572,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8807]]],
##     CS[Cartesian,2],
##         AXIS["northing (N)",north,
##             ORDER[1],
##             LENGTHUNIT["metre",1]],
##         AXIS["easting (E)",east,
##             ORDER[2],
##             LENGTHUNIT["metre",1]],
##     USAGE[
##         SCOPE["unknown"],
##         AREA["Singapore"],
##         BBOX[1.13,103.59,1.47,104.07]],
##     ID["EPSG",3414]]

Observation: Based on the result, it can be seen that the sf_subzone3414 is successfully transformed to SVY21 Projection of CRS EPSG 3414. _____________________________________________________________________________________________ This code chunk will transform sf_childcare feature dataframe onto SVY21[EPSG3414] projected coordinate system with the use of st_transform() from sf package.

sf_childcare3414 <- st_transform(sf_childcare, 3414)
st_crs (sf_childcare3414)
## Coordinate Reference System:
##   User input: EPSG:3414 
##   wkt:
## PROJCRS["SVY21 / Singapore TM",
##     BASEGEOGCRS["SVY21",
##         DATUM["SVY21",
##             ELLIPSOID["WGS 84",6378137,298.257223563,
##                 LENGTHUNIT["metre",1]]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["degree",0.0174532925199433]],
##         ID["EPSG",4757]],
##     CONVERSION["Singapore Transverse Mercator",
##         METHOD["Transverse Mercator",
##             ID["EPSG",9807]],
##         PARAMETER["Latitude of natural origin",1.36666666666667,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8801]],
##         PARAMETER["Longitude of natural origin",103.833333333333,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8802]],
##         PARAMETER["Scale factor at natural origin",1,
##             SCALEUNIT["unity",1],
##             ID["EPSG",8805]],
##         PARAMETER["False easting",28001.642,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8806]],
##         PARAMETER["False northing",38744.572,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8807]]],
##     CS[Cartesian,2],
##         AXIS["northing (N)",north,
##             ORDER[1],
##             LENGTHUNIT["metre",1]],
##         AXIS["easting (E)",east,
##             ORDER[2],
##             LENGTHUNIT["metre",1]],
##     USAGE[
##         SCOPE["unknown"],
##         AREA["Singapore"],
##         BBOX[1.13,103.59,1.47,104.07]],
##     ID["EPSG",3414]]

Observation: After transforming, it can see that the projection coordinate system of simple feature dataframe sf_childcare has changed to SVY21 with Coordinate Reference System EPSG 3414. Therefore, it is good to continue with analysis. _____________________________________________________________________________________________ This code chunk will transform sf_kindergarten feature dataframe onto SVY21[EPSG3414] projected coordinate system using st_transform() from sf package.

sf_kindergarten3414 <- st_transform(sf_kindergarten, 3414)
st_crs (sf_kindergarten3414)
## Coordinate Reference System:
##   User input: EPSG:3414 
##   wkt:
## PROJCRS["SVY21 / Singapore TM",
##     BASEGEOGCRS["SVY21",
##         DATUM["SVY21",
##             ELLIPSOID["WGS 84",6378137,298.257223563,
##                 LENGTHUNIT["metre",1]]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["degree",0.0174532925199433]],
##         ID["EPSG",4757]],
##     CONVERSION["Singapore Transverse Mercator",
##         METHOD["Transverse Mercator",
##             ID["EPSG",9807]],
##         PARAMETER["Latitude of natural origin",1.36666666666667,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8801]],
##         PARAMETER["Longitude of natural origin",103.833333333333,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8802]],
##         PARAMETER["Scale factor at natural origin",1,
##             SCALEUNIT["unity",1],
##             ID["EPSG",8805]],
##         PARAMETER["False easting",28001.642,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8806]],
##         PARAMETER["False northing",38744.572,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8807]]],
##     CS[Cartesian,2],
##         AXIS["northing (N)",north,
##             ORDER[1],
##             LENGTHUNIT["metre",1]],
##         AXIS["easting (E)",east,
##             ORDER[2],
##             LENGTHUNIT["metre",1]],
##     USAGE[
##         SCOPE["unknown"],
##         AREA["Singapore"],
##         BBOX[1.13,103.59,1.47,104.07]],
##     ID["EPSG",3414]]

Observation: After transforming, it can see that the projection coordinate system of simple feature dataframe sf_kindergarten has changed to SVY21 with Coordinate Reference System EPSG 3414. Therefore, it is good to continue with analysis.

3.4. Data Wrangling

Since I am only interested in finding out the demand for childcare centers by Age of 2 to 6 years old at the planning subzone level in 2020, we will perform the following steps to derive the new set of data that meet this assignment’s requirement.

  • Extracting 2018 records only by using filter(): -2018 data is used for this assignment because we aim to find out the demand population for childcare services in 2020 since the dataset used for childcare centers is also in 2020. -Using the 2018 data for age group of 0-4 will also give us the population data of age group 2-6 years old by the year 2020.
  • Group by Planning Area, Subzone, and Age Group
  • Sum up the population area based on the group by criteria
  • Spread the age group by Age 0-4 and Age 5-9 and indicate the sum up population
  • Select by the population, subzone, age group 0-4

Note: Age group of 0-4 from 2018 is chosen with the

popagesex2018 <- popagesex%>%
  filter(Time == 2018)%>%
  group_by(PA, SZ, AG)%>% 
  summarize(`POP`=sum(`Pop`))%>%
  spread(AG, POP)%>%
  mutate(`2_to_6` = `0_to_4`)%>%
  select(`PA`, `SZ`,`2_to_6`)
## `summarise()` regrouping output by 'PA', 'SZ' (override with `.groups` argument)
head(popagesex2018, n=5)
## # A tibble: 5 x 3
## # Groups:   PA, SZ [5]
##   PA         SZ                     `2_to_6`
##   <chr>      <chr>                     <dbl>
## 1 Ang Mo Kio Ang Mo Kio Town Centre      180
## 2 Ang Mo Kio Cheng San                  1040
## 3 Ang Mo Kio Chong Boon                  890
## 4 Ang Mo Kio Kebun Bahru                 710
## 5 Ang Mo Kio Sembawang Hills             200

*Observation: After wrangling, it can be seen that the popagesex2018 now contains only 3 columns which are Planning Area, Subzone Name, the number of population belong to age group of 0-4 who will be the 2-6 years old by 2020.

3.5. Joining the attribute data and geospatial data

As the next step, I will be joining the attribute data and geospatial together to form a new dataframe that contains the transformed population data and subzone data.

  • Converting subzone names to capital letters using funs()
  • Using left_join() of dplyr to join the geographical data and attribute table using planning subzone name.

This code chunk will use left_join() to join the geospatial data of subzone with with attribute data population age group

popagesex2018 <- popagesex2018 %>%
mutate_at(.vars = vars(PA,SZ),.funs = funs(toupper))
## Warning: `funs()` is deprecated as of dplyr 0.8.0.
## Please use a list of either functions or lambdas: 
## 
##   # Simple named list: 
##   list(mean = mean, median = median)
## 
##   # Auto named with `tibble::lst()`: 
##   tibble::lst(mean, median)
## 
##   # Using lambdas
##   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
subzone_popagesex2018 <- left_join(sf_subzone3414, 
                                   popagesex2018, 
                                   by = c("SUBZONE_N" = "SZ"))
head(subzone_popagesex2018, n=5)
## Simple feature collection with 5 features and 17 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 25867.68 ymin: 28369.47 xmax: 32362.39 ymax: 30435.54
## projected CRS:  SVY21 / Singapore TM
##   OBJECTID SUBZONE_NO      SUBZONE_N SUBZONE_C CA_IND      PLN_AREA_N
## 1        1          1   MARINA SOUTH    MSSZ01      Y    MARINA SOUTH
## 2        2          1   PEARL'S HILL    OTSZ01      Y          OUTRAM
## 3        3          3      BOAT QUAY    SRSZ03      Y SINGAPORE RIVER
## 4        4          8 HENDERSON HILL    BMSZ08      N     BUKIT MERAH
## 5        5          3        REDHILL    BMSZ03      N     BUKIT MERAH
##   PLN_AREA_C       REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR
## 1         MS CENTRAL REGION       CR 5ED7EB253F99252E 2014-12-05 31595.84
## 2         OT CENTRAL REGION       CR 8C7149B9EB32EEFC 2014-12-05 28679.06
## 3         SR CENTRAL REGION       CR C35FEFF02B13E0E5 2014-12-05 29654.96
## 4         BM CENTRAL REGION       CR 3775D82C5DDBEFBD 2014-12-05 26782.83
## 5         BM CENTRAL REGION       CR 85D9ABEF0A40678F 2014-12-05 26201.96
##     Y_ADDR SHAPE_Leng SHAPE_Area              PA 2_to_6
## 1 29220.19   5267.381  1630379.3    MARINA SOUTH      0
## 2 29782.05   3506.107   559816.2          OUTRAM    230
## 3 29974.66   1740.926   160807.5 SINGAPORE RIVER      0
## 4 29933.77   3313.625   595428.9     BUKIT MERAH    370
## 5 30005.70   2825.594   387429.4     BUKIT MERAH    590
##                         geometry
## 1 MULTIPOLYGON (((31495.56 30...
## 2 MULTIPOLYGON (((29092.28 30...
## 3 MULTIPOLYGON (((29932.33 29...
## 4 MULTIPOLYGON (((27131.28 30...
## 5 MULTIPOLYGON (((26451.03 30...

Observation: After joining, it can be seen that the new subzone_popagesex2018 dataframe contains all the information from sf_subzone3414 and popagesex2018. Since all these information are in the one dataframe, it can be easily used to intersect with childcare and kindergartens layers to count the number of those services fall within each planning subzone level. This will allow us to find out the supply of those services within the subzone.

4. Geoprocessing

4.1. Calculating the supply of childcare center within each subzone

We will now calculate the number of childcare centers that fall within each subzone and show the summary result.

  • use st_intersects() to identify childcare located inside each planning subzone.
  • use length() to calculate the number of childcare center centers fall within each planning subzone.
  • use $ to list out the content of the newly derieved ‘Childcare_Count’ field in the subzone_popagesex2018 data table.
subzone_popagesex2018$`Childcare_Count` <- lengths(st_intersects(subzone_popagesex2018, sf_childcare3414))

subzone_popagesex2018$`Childcare_Count`
##   [1]  0  4  0  3  1  8  3  2  2  1  6  2  0  1  5  0  0  0  0  1  0  1  0  4  2
##  [26]  1  7  2  6  7  0  0  3  0  3  9  1  3  0  4  0  3  1  0  3  0  3  1  3  0
##  [51]  1  0  1  2  2  0  0  1  2  0  3  0  2  3  1  0  9  3  7  1  1  3  1  3  0
##  [76]  0  1  9  0  0  1  0  4  1  1  0  0  1  0  4  3  2  0  0  2  0  0  2  0  2
## [101]  6  0 11  0  2  2  1 17 13 15  0  0  5  5  0  5 14  9  5  0  1  0  0  0  4
## [126]  4  3  0  0  7  3  3  8  4  5  2  9  8  4  0  3  5  2  0  1 16  0  3 10  8
## [151]  6 18  7  4  0  5  3  0  2  6  4  0 22  2  8  0 18 10  2 12  5  7  3  3  9
## [176]  7 20  0  0  8  9 23  7  0  5 13  3  2 42  7  0  2 22  7  1  1  8  3 25 11
## [201]  0  7  0 10  3  9 13 11  0  4 20 10  8 14 11 11  5 14 11  5  0  9  3  8 10
## [226]  7  5  8  0  6 11  3  8  0  0 14  7  8 11  5  5 10  3  1  3 13  2  8  4  8
## [251]  3  0 12  7  4  0  0  5 10 23  0 12 15 11  0 11 19  0  2  0  0 27 15  0 15
## [276]  6  5  5  4  0  0 10 13 16  1  0 10  1  0 42 20  1  6  0  0  8  0  0  0  8
## [301]  0  0  1  0 15 13  6  9  2 11  0  0  0  1  0  0  2  0  0  2  0  0  0

Observation: In this, we can see that there are some planning subzone with no childcare service but there are also the subzone with the 42 number of childcare centers in a planning subzone itself. We can find out what is the name of subzone with the highest number of childcare centers and whether there is a large demand for the number of of service within the planning subzone.

4.1.1. Finding the planning subzone with the most number of childcare centers

This code chunk will use top_n() of dplyr package to list the planning subzone with the most number of childcare center.

top_n(subzone_popagesex2018, 1, `Childcare_Count`)
## Simple feature collection with 2 features and 18 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 23449.05 ymin: 35966 xmax: 42940.57 ymax: 47996.47
## projected CRS:  SVY21 / Singapore TM
##   OBJECTID SUBZONE_NO      SUBZONE_N SUBZONE_C CA_IND PLN_AREA_N PLN_AREA_C
## 1      189          2  TAMPINES EAST    TMSZ02      N   TAMPINES         TM
## 2      290          3 WOODLANDS EAST    WDSZ03      N  WOODLANDS         WD
##       REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR   Y_ADDR
## 1  EAST REGION       ER 21658EAAF84F4D8D 2014-12-05 41122.55 37392.39
## 2 NORTH REGION       NR C90769E43EE6B0F2 2014-12-05 24506.64 46991.63
##   SHAPE_Leng SHAPE_Area        PA 2_to_6                       geometry
## 1  10180.624    4339824  TAMPINES   5720 MULTIPOLYGON (((42196.76 38...
## 2   6603.608    2553464 WOODLANDS   4990 MULTIPOLYGON (((24786.75 46...
##   Childcare_Count
## 1              42
## 2              42

Observation: From the result, it is found that ‘Tampines East’ & ‘Woodlands East’ have the most number of childcare center in them. Both planning subzones have 42 childcare centers

4.1.2. Finding the planning subzone with the least number of childcare centers

This code chunk will use top_n() with -n of dplyr package to list the planning subzone with the least number of childcare center.

top_n(subzone_popagesex2018, -1, `Childcare_Count`)
## Simple feature collection with 96 features and 18 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
## projected CRS:  SVY21 / Singapore TM
## First 10 features:
##    OBJECTID SUBZONE_NO               SUBZONE_N SUBZONE_C CA_IND
## 1         1          1            MARINA SOUTH    MSSZ01      Y
## 2         3          3               BOAT QUAY    SRSZ03      Y
## 3        13          1             MARINA EAST    MESZ01      Y
## 4        16          1 JURONG ISLAND AND BUKOM    WISZ01      N
## 5        17          3                  SUDONG    WISZ03      N
## 6        18          2                 SEMAKAU    WISZ02      N
## 7        19          2          SOUTHERN GROUP    SISZ02      N
## 8        21         17          CITY TERMINALS    BMSZ17      N
## 9        23          1            STRAITS VIEW    SVSZ01      Y
## 10       31         11         CENTRAL SUBZONE    DTSZ11      Y
##          PLN_AREA_N PLN_AREA_C       REGION_N REGION_C          INC_CRC
## 1      MARINA SOUTH         MS CENTRAL REGION       CR 5ED7EB253F99252E
## 2   SINGAPORE RIVER         SR CENTRAL REGION       CR C35FEFF02B13E0E5
## 3       MARINA EAST         ME CENTRAL REGION       CR 782A2FAF53029A34
## 4   WESTERN ISLANDS         WI    WEST REGION       WR 699F7210FBF1AFA8
## 5   WESTERN ISLANDS         WI    WEST REGION       WR F718C723E08FBD51
## 6   WESTERN ISLANDS         WI    WEST REGION       WR E69207D4F76DEEA3
## 7  SOUTHERN ISLANDS         SI CENTRAL REGION       CR 5809FC547293EA2D
## 8       BUKIT MERAH         BM CENTRAL REGION       CR 9711879901A8487F
## 9      STRAITS VIEW         SV CENTRAL REGION       CR 21451799CA1AB6EF
## 10    DOWNTOWN CORE         DT CENTRAL REGION       CR 8EFE9EC1AEF2DA0A
##    FMEL_UPD_D   X_ADDR   Y_ADDR SHAPE_Leng SHAPE_Area               PA 2_to_6
## 1  2014-12-05 31595.84 29220.19   5267.381  1630379.3     MARINA SOUTH      0
## 2  2014-12-05 29654.96 29974.66   1740.926   160807.5  SINGAPORE RIVER      0
## 3  2014-12-05 32344.05 30103.25   6470.950  1844060.7      MARINA EAST      0
## 4  2014-12-05 13012.88 27225.87  68083.936 36707720.9  WESTERN ISLANDS      0
## 5  2014-12-05 15931.76 19579.07  24759.066  4207271.1  WESTERN ISLANDS      0
## 6  2014-12-05 21206.33 20465.81  18703.681  4963787.1  WESTERN ISLANDS      0
## 7  2014-12-05 29815.09 23412.59  25626.977  2206319.5 SOUTHERN ISLANDS      0
## 8  2014-12-05 28387.34 27536.57  16805.656  3449640.6      BUKIT MERAH      0
## 9  2014-12-05 30832.90 28194.08   5277.761  1127297.2     STRAITS VIEW      0
## 10 2014-12-05 30125.84 28683.04   5002.016  1070723.3    DOWNTOWN CORE     30
##                          geometry Childcare_Count
## 1  MULTIPOLYGON (((31495.56 30...               0
## 2  MULTIPOLYGON (((29932.33 29...               0
## 3  MULTIPOLYGON (((33214.62 29...               0
## 4  MULTIPOLYGON (((14557.7 304...               0
## 5  MULTIPOLYGON (((15772.59 21...               0
## 6  MULTIPOLYGON (((19843.41 21...               0
## 7  MULTIPOLYGON (((29712.51 23...               0
## 8  MULTIPOLYGON (((27891.15 28...               0
## 9  MULTIPOLYGON (((31269.21 28...               0
## 10 MULTIPOLYGON (((30436.73 29...               0

Observation: From the result, it is found that there are many subzones with no supply of childcare services. However, it can be understandable since there is also no demand for those services as most of them are not the residential areas. However, it is noticed that the particular subzone named ‘Downtown Core’ has a total of 30 children who age between 2 to 6 yet there is no childcare center available for them in that subzone. In this case, we can conclude that there is a mismatch between the demand and supply for childcare centers in this particular subzone. As the additional step, planning subzones with no childcare center are converted as missing values with the use of na_if() function. This is to ensure that when we plot the map, those subzones will be still be shaded but displayed as missing value.

4.2. Calculating the supply of kindergarten within each subzone

This code chunk will below will calculate the number of kindergartens within each subzone and show the summary result.

  • use st_intersects() to identify kindergartens located inside each planning subzone.
  • use length() to calculate the number of kindergartens fall within each planning subzone.
  • use $ to list out the content of the newly derived ‘Kindergarten_Count’ field in the subzone_popagesex2018 data table.
subzone_popagesex2018$`Kindergarten_Count` <- lengths(st_intersects(subzone_popagesex2018, sf_kindergarten3414))

subzone_popagesex2018$`Kindergarten_Count`
##   [1]  0  1  0  1  1  2  1  0  5  0  0  0  0  0  1  0  0  0  0  2  0  0  0  1  1
##  [26]  0  0  0  3  0  0  0  1  0  0  1  0  0  0  1  0  0  0  0  0  0  0  0  5  0
##  [51]  0  2  0  0  1  0  1  0  0  0  0  0  0  2  0  0  2  0  3  1  1  5  0  1  0
##  [76]  0  1  1  0  0  0  0  0  0  1  0  0  2  0  2  0  1  0  0  3  0  0  0  0  1
## [101]  2  0  2  0  1  0  1  7  2  3  0  0  0  0  0  3  7 11  1  1  0  0  0  0  1
## [126]  1  0  0  0  0  1  1  0  1  0  1  2  0  3  0  0  1  0  0  0  6  0  2  4  3
## [151]  1  5  3  0  0  2  1  0  0  1  1  0 10  1  9  0 10  2  2  3  3  4  1  2  0
## [176]  4  6  0  0  3  3  9  1  0  2  5  1  3 17  2  0  1  8  0  2  2  1  1  7  4
## [201]  0  4  0  1  1  1  5  3  0  2  2  7  0  3  3 10  1  4  1  1  0  2  1  2  0
## [226]  0  0  0  1  1  6  0  0  0  0  2  3  2  5  2  2  6  2  1  1  7  0  2  1  1
## [251]  0  0  4  2  0  0  0  4  3  4  0  1  4  3  0  1  2  0  0  0  0  3  3  0  5
## [276]  0  1  0  1  0  0  2  5  2  0  0  6  0  0  5  3  0  1  0  0  2  0  0  0  2
## [301]  0  0  0  0  2  3  2  1  0  2  0  0  0  0  0  0  0  0  0  1  0  0  0

Observaton: From this result, we can see that there are some planning subzone with no kindergarten when there are also the subzone with the the highest number of 17 kindergartens in a planning subzone. To better understand the meaning of it, We can find out what is the name of subzone with the highest number of kindergartens and what is the demand for kindergartens within the planning subzone.

4.2.1. Finding the planning subzone with the most number of kindergartens

This code chunk will use top_n() of dplyr package to list the planning subzone with the most number of kindergartens.

top_n(subzone_popagesex2018, 1, `Kindergarten_Count`)
## Simple feature collection with 1 feature and 19 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 39655.33 ymin: 35966 xmax: 42940.57 ymax: 38622.37
## projected CRS:  SVY21 / Singapore TM
##   OBJECTID SUBZONE_NO     SUBZONE_N SUBZONE_C CA_IND PLN_AREA_N PLN_AREA_C
## 1      189          2 TAMPINES EAST    TMSZ02      N   TAMPINES         TM
##      REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR   Y_ADDR SHAPE_Leng
## 1 EAST REGION       ER 21658EAAF84F4D8D 2014-12-05 41122.55 37392.39   10180.62
##   SHAPE_Area       PA 2_to_6                       geometry Childcare_Count
## 1    4339824 TAMPINES   5720 MULTIPOLYGON (((42196.76 38...              42
##   Kindergarten_Count
## 1                 17

Observation: From the result, it is found that ‘Tampines East’ has the most number of childcare centers in its subzone. It has a total supply of 17 kindergartens for 5720 children of age group 2 to 6 years old.

4.2.2. Finding the planning subzone with the least number of kindergartens

This code chunk will use top_n() with -n of dplyr package to list the planning subzone with the least number of childcare center.

top_n(subzone_popagesex2018, -1, `Kindergarten_Count`)
## Simple feature collection with 161 features and 19 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
## projected CRS:  SVY21 / Singapore TM
## First 10 features:
##    OBJECTID SUBZONE_NO               SUBZONE_N SUBZONE_C CA_IND      PLN_AREA_N
## 1         1          1            MARINA SOUTH    MSSZ01      Y    MARINA SOUTH
## 2         3          3               BOAT QUAY    SRSZ03      Y SINGAPORE RIVER
## 3         8          2             CLARKE QUAY    SRSZ02      Y SINGAPORE RIVER
## 4        10          7               QUEENSWAY    QTSZ07      N      QUEENSTOWN
## 5        11         12              KENT RIDGE    QTSZ12      N      QUEENSTOWN
## 6        12          6         ALEXANDRA NORTH    BMSZ06      N     BUKIT MERAH
## 7        13          1             MARINA EAST    MESZ01      Y     MARINA EAST
## 8        14          5        INSTITUTION HILL    RVSZ05      Y    RIVER VALLEY
## 9        16          1 JURONG ISLAND AND BUKOM    WISZ01      N WESTERN ISLANDS
## 10       17          3                  SUDONG    WISZ03      N WESTERN ISLANDS
##    PLN_AREA_C       REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR
## 1          MS CENTRAL REGION       CR 5ED7EB253F99252E 2014-12-05 31595.84
## 2          SR CENTRAL REGION       CR C35FEFF02B13E0E5 2014-12-05 29654.96
## 3          SR CENTRAL REGION       CR 48661DC0FBA09F7A 2014-12-05 29253.21
## 4          QT CENTRAL REGION       CR 3580D2AFFBEE914C 2014-12-05 24168.31
## 5          QT CENTRAL REGION       CR 601BA309A1AAC731 2014-12-05 23464.84
## 6          BM CENTRAL REGION       CR 4DC4BF8D86594CBF 2014-12-05 26548.25
## 7          ME CENTRAL REGION       CR 782A2FAF53029A34 2014-12-05 32344.05
## 8          RV CENTRAL REGION       CR C3C22D1EE31757BD 2014-12-05 28465.40
## 9          WI    WEST REGION       WR 699F7210FBF1AFA8 2014-12-05 13012.88
## 10         WI    WEST REGION       WR F718C723E08FBD51 2014-12-05 15931.76
##      Y_ADDR SHAPE_Leng SHAPE_Area              PA 2_to_6
## 1  29220.19   5267.381  1630379.3    MARINA SOUTH      0
## 2  29974.66   1740.926   160807.5 SINGAPORE RIVER      0
## 3  30222.86   2208.619   290184.7 SINGAPORE RIVER     10
## 4  30104.18   3454.239   631644.3      QUEENSTOWN      0
## 5  29725.37   7439.548  1826848.6      QUEENSTOWN     20
## 6  30519.39   2907.051   293706.4     BUKIT MERAH    120
## 7  30103.25   6470.950  1844060.7     MARINA EAST      0
## 8  30711.22   2842.526   392563.3    RIVER VALLEY    230
## 9  27225.87  68083.936 36707720.9 WESTERN ISLANDS      0
## 10 19579.07  24759.066  4207271.1 WESTERN ISLANDS      0
##                          geometry Childcare_Count Kindergarten_Count
## 1  MULTIPOLYGON (((31495.56 30...               0                  0
## 2  MULTIPOLYGON (((29932.33 29...               0                  0
## 3  MULTIPOLYGON (((29351.26 29...               2                  0
## 4  MULTIPOLYGON (((24472.11 29...               1                  0
## 5  MULTIPOLYGON (((23332.77 30...               6                  0
## 6  MULTIPOLYGON (((26231.96 30...               2                  0
## 7  MULTIPOLYGON (((33214.62 29...               0                  0
## 8  MULTIPOLYGON (((28481.45 30...               1                  0
## 9  MULTIPOLYGON (((14557.7 304...               0                  0
## 10 MULTIPOLYGON (((15772.59 21...               0                  0

Observation: From the result, it is found that there are 10 subzones with no kindergarten services. However, by looking at some subzones with no kindergarten center, it is also understandable that there is no supply because there is also no demand for those services as well for those subzones since no resident is living there. However, it is noticed that the particular subzones named ‘KENT RIDGE’, ‘BUKIT MERAH’ and “RIVER VALLEY” have demand for kindergartens yet there is no supply of kindergartens for the population in them. In this case, we can conculde that there is a mismatched between the demand and supply of childcare services at those planning subzones. As the additional step, planning subzones with no childcare center are converted as missing values with the use of na_if() function. This is to ensure that when we plot the map, those subzones will be still be shaded but displayed as missing value.

5.0. Choropleth Mapping

5.1. Replacing 0 with NA

This code chunk will replace the subzone with no supply of childcare and kindergarten as NA (missing value) for better visualization of map.

subzone_popagesex2018 <- subzone_popagesex2018 %>%
  mutate(`Childcare_Count` = na_if(`Childcare_Count`, 0), 
        `Kindergarten_Count` = na_if(`Kindergarten_Count`, 0))

5.2. Plotting the Supply of Childcare Centers in each subzone into Choropleth Map

This code chunk will plot the Choropleth map of supply of childcare center in planning subzone level

tm_shape(subzone_popagesex2018)+
  tm_fill("Childcare_Count",
          title = "Childcare Centers",
          style = "pretty",
          palette = "BuGn") +
  tm_layout(main.title = "Supply of Childcare Centers by Planning Subzone",
            main.title.position = "center",
            main.title.size = 1,
            frame = FALSE)+
  tm_borders(alpha = 0.5) 

Observation: From this Choropleth map, we can see that the planning subzones with no childcare centers are shown as missing value and shaded in grey. The map can be interpreted as the darker the color of the subzone, the higher the number of the childcare centers in it. Moreover, just like what we have observed previously, the map also shows that there are two planning subzones, ‘Tampines East’ & ‘Woodlands East’, with the 42 childcare centers and they are shaped in the dark green on the map. At the same time, it can also be observed that there are more planning subzones with supply of 1 to 10 childcare centers within the zone.

5.3. Plotting the Supply of Kindergarten in each subzone into Choropleth Map

This code chunk will plot the Choropleth map of supply of kindergartens in planning subzone level

  • fixed style is used as data classification methods since I wanted to group them in the same classification data ranges as the childcare center for better comparison between them for the interpretation.
tm_shape(subzone_popagesex2018)+
  tm_fill("Kindergarten_Count",
          title = "Kindergartens",
          style = "fixed",
          breaks = c(1, 11, 21, 31, 41),
          palette = "BuGn") +
  tm_layout(main.title = "Supply of Kindergarten Services by Planning Subzone",
            main.title.position = "center",
            main.title.size = 1,
            frame = FALSE)+
  tm_borders(alpha = 0.5)

Observation: From this Choropleth map, we can see that the planning subzones with no supply of kindergartens are shown as missing value and shaded in grey. The map can be interpreted as the darker the color of the subzone, the higher the number of the kindergartens located in it. Based on that definition, we can see that there is only one planning subzone with the highest supply of kindergaten and that subzone has 11 to 20 kindergartens in it. Based on the information we gathered through top_n(), we know that the subzone with the highest number of kindergarten is ‘Tampines East’ and it has 17 kindergartens. Beside, we can also observe from the map that there are many planning subzones with supply of 1 to 10 kindergartens within the subzone.However, there is no planning subzone with more than 20 kindergartens located in them.

5.4. Calculating the number of population to be served by each childcare center

The code chunk will create a new field ‘Pop_per_Childcare’ to find out the numbers of population need to be served by each childcare center.

subzone_popagesex2018 <- subzone_popagesex2018 %>%
  mutate(`Pop_per_Childcare` = `2_to_6`/`Childcare_Count`)
head(subzone_popagesex2018, n=5)
## Simple feature collection with 5 features and 20 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 25867.68 ymin: 28369.47 xmax: 32362.39 ymax: 30435.54
## projected CRS:  SVY21 / Singapore TM
##   OBJECTID SUBZONE_NO      SUBZONE_N SUBZONE_C CA_IND      PLN_AREA_N
## 1        1          1   MARINA SOUTH    MSSZ01      Y    MARINA SOUTH
## 2        2          1   PEARL'S HILL    OTSZ01      Y          OUTRAM
## 3        3          3      BOAT QUAY    SRSZ03      Y SINGAPORE RIVER
## 4        4          8 HENDERSON HILL    BMSZ08      N     BUKIT MERAH
## 5        5          3        REDHILL    BMSZ03      N     BUKIT MERAH
##   PLN_AREA_C       REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR
## 1         MS CENTRAL REGION       CR 5ED7EB253F99252E 2014-12-05 31595.84
## 2         OT CENTRAL REGION       CR 8C7149B9EB32EEFC 2014-12-05 28679.06
## 3         SR CENTRAL REGION       CR C35FEFF02B13E0E5 2014-12-05 29654.96
## 4         BM CENTRAL REGION       CR 3775D82C5DDBEFBD 2014-12-05 26782.83
## 5         BM CENTRAL REGION       CR 85D9ABEF0A40678F 2014-12-05 26201.96
##     Y_ADDR SHAPE_Leng SHAPE_Area              PA 2_to_6
## 1 29220.19   5267.381  1630379.3    MARINA SOUTH      0
## 2 29782.05   3506.107   559816.2          OUTRAM    230
## 3 29974.66   1740.926   160807.5 SINGAPORE RIVER      0
## 4 29933.77   3313.625   595428.9     BUKIT MERAH    370
## 5 30005.70   2825.594   387429.4     BUKIT MERAH    590
##                         geometry Childcare_Count Kindergarten_Count
## 1 MULTIPOLYGON (((31495.56 30...              NA                 NA
## 2 MULTIPOLYGON (((29092.28 30...               4                  1
## 3 MULTIPOLYGON (((29932.33 29...              NA                 NA
## 4 MULTIPOLYGON (((27131.28 30...               3                  1
## 5 MULTIPOLYGON (((26451.03 30...               1                  1
##   Pop_per_Childcare
## 1                NA
## 2           57.5000
## 3                NA
## 4          123.3333
## 5          590.0000

This code chunk will list the planning subzone with the highest density which mean the subzone with demand for childcares but no supply of them.

top_n(subzone_popagesex2018, 1, `Pop_per_Childcare`)
## Simple feature collection with 1 feature and 20 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 25867.68 ymin: 29576.74 xmax: 26503.48 ymax: 30435.54
## projected CRS:  SVY21 / Singapore TM
##   OBJECTID SUBZONE_NO SUBZONE_N SUBZONE_C CA_IND  PLN_AREA_N PLN_AREA_C
## 1        5          3   REDHILL    BMSZ03      N BUKIT MERAH         BM
##         REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR  Y_ADDR
## 1 CENTRAL REGION       CR 85D9ABEF0A40678F 2014-12-05 26201.96 30005.7
##   SHAPE_Leng SHAPE_Area          PA 2_to_6                       geometry
## 1   2825.594   387429.4 BUKIT MERAH    590 MULTIPOLYGON (((26451.03 30...
##   Childcare_Count Kindergarten_Count Pop_per_Childcare
## 1               1                  1               590

Observation: By looking at the result, it can see that ‘REDHILL’ planning subzone has 590 children of age between 2 to 6. However, there is only one childcare center to accommodate all 590 childcare population of that particular subzone. In this case, we can conclude that there is a mismatch between the supply and demand within this subzone.

This code chunk will list the planning subzone with the lowest density which mean the subzone with no demand for childcares but have supply of them.

top_n(subzone_popagesex2018, -1, `Pop_per_Childcare`)
## Simple feature collection with 25 features and 20 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 10864.2 ymin: 28339.16 xmax: 50293.96 ymax: 48190.75
## projected CRS:  SVY21 / Singapore TM
## First 10 features:
##    OBJECTID SUBZONE_NO                     SUBZONE_N SUBZONE_C CA_IND
## 1        10          7                     QUEENSWAY    QTSZ07      N
## 2        22         10                         ANSON    DTSZ10      Y
## 3        26          7                       MAXWELL    DTSZ07      Y
## 4        27          8                         CECIL    DTSZ08      Y
## 5        37          4                       PHILLIP    DTSZ04      Y
## 6        38          5                 RAFFLES PLACE    DTSZ05      Y
## 7        43          6                 CLIFFORD PIER    DTSZ06      Y
## 8        45          3                 MARINA CENTRE    DTSZ03      Y
## 9        48          2                     CITY HALL    DTSZ02      Y
## 10       51         11 NATIONAL UNIVERSITY OF S'PORE    QTSZ11      N
##       PLN_AREA_N PLN_AREA_C       REGION_N REGION_C          INC_CRC FMEL_UPD_D
## 1     QUEENSTOWN         QT CENTRAL REGION       CR 3580D2AFFBEE914C 2014-12-05
## 2  DOWNTOWN CORE         DT CENTRAL REGION       CR 4893F02202845C1D 2014-12-05
## 3  DOWNTOWN CORE         DT CENTRAL REGION       CR CB2D9FC5CAB792B1 2014-12-05
## 4  DOWNTOWN CORE         DT CENTRAL REGION       CR 65AA82AF6F4D925D 2014-12-05
## 5  DOWNTOWN CORE         DT CENTRAL REGION       CR 615D4EDDEF809F8E 2014-12-05
## 6  DOWNTOWN CORE         DT CENTRAL REGION       CR 72107B11807074F4 2014-12-05
## 7  DOWNTOWN CORE         DT CENTRAL REGION       CR 945CC212CA80626F 2014-12-05
## 8  DOWNTOWN CORE         DT CENTRAL REGION       CR 2AB099523A1AEAD5 2014-12-05
## 9  DOWNTOWN CORE         DT CENTRAL REGION       CR C3663E9926627289 2014-12-05
## 10    QUEENSTOWN         QT CENTRAL REGION       CR 247B3009E9665A6E 2014-12-05
##      X_ADDR   Y_ADDR SHAPE_Leng SHAPE_Area            PA 2_to_6
## 1  24168.31 30104.18  3454.2393  631644.29    QUEENSTOWN      0
## 2  29145.35 28466.78  1586.1001  103238.48 DOWNTOWN CORE      0
## 3  29392.05 29096.75  1419.8019   63664.97 DOWNTOWN CORE      0
## 4  29730.20 29011.33  2116.0947  196619.86 DOWNTOWN CORE      0
## 5  29706.72 29744.91   871.5549   39437.94 DOWNTOWN CORE      0
## 6  29968.62 29572.76  1872.7522  188767.49 DOWNTOWN CORE      0
## 7  30379.50 29776.43  2405.9909  261843.90 DOWNTOWN CORE      0
## 8  30938.10 30471.83  4047.1112  886954.81 DOWNTOWN CORE      0
## 9  30209.07 30536.51  4544.1698  710568.70 DOWNTOWN CORE      0
## 10 21688.92 30930.12  5625.4169 1755950.44    QUEENSTOWN      0
##                          geometry Childcare_Count Kindergarten_Count
## 1  MULTIPOLYGON (((24472.11 29...               1                 NA
## 2  MULTIPOLYGON (((29201.07 28...               1                 NA
## 3  MULTIPOLYGON (((29341.73 29...               1                 NA
## 4  MULTIPOLYGON (((29808.18 28...               7                 NA
## 5  MULTIPOLYGON (((29814.11 29...               1                 NA
## 6  MULTIPOLYGON (((30137.77 29...               3                 NA
## 7  MULTIPOLYGON (((30436.73 29...               1                 NA
## 8  MULTIPOLYGON (((31353.26 30...               3                 NA
## 9  MULTIPOLYGON (((30671.27 30...               1                 NA
## 10 MULTIPOLYGON (((22653.1 306...               1                 NA
##    Pop_per_Childcare
## 1                  0
## 2                  0
## 3                  0
## 4                  0
## 5                  0
## 6                  0
## 7                  0
## 8                  0
## 9                  0
## 10                 0

Observation: By looking at the result, it can see that there are the planning subzones with no demand for childcare centers but childcare services are located in them. Therefore, it is found that there is a mismatch between the supply and demand of childcare centers for these subzones as well. In this case, it can conclude that these childcare centers are under-utilization for the planning subzone level assuming only the children population within the planning subzone will access them. The names of these planning subzones are QUEENSWAY, ANSON, MAXWELL, CECIL, PHILLIP, RAFFLES PLACE, CLIFFORD PIER, MARINA CENTR and CITY HALL. Especially, the ‘CECIL’ planning subzone is providing 7 childcares centers although there is no population of 2 to 6 years old childcare living in them.

5.5. Calculating the number of population to be served by each kindergarten

The code chunk will create a new field ‘Pop_per_Kindergarten’ to find out the numbers of population need to be served by each kindergarten.

subzone_popagesex2018 <- subzone_popagesex2018 %>%
  mutate(`Pop_per_Kindergarten` = `2_to_6`/`Kindergarten_Count`)
head(subzone_popagesex2018, n=5)
## Simple feature collection with 5 features and 21 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 25867.68 ymin: 28369.47 xmax: 32362.39 ymax: 30435.54
## projected CRS:  SVY21 / Singapore TM
##   OBJECTID SUBZONE_NO      SUBZONE_N SUBZONE_C CA_IND      PLN_AREA_N
## 1        1          1   MARINA SOUTH    MSSZ01      Y    MARINA SOUTH
## 2        2          1   PEARL'S HILL    OTSZ01      Y          OUTRAM
## 3        3          3      BOAT QUAY    SRSZ03      Y SINGAPORE RIVER
## 4        4          8 HENDERSON HILL    BMSZ08      N     BUKIT MERAH
## 5        5          3        REDHILL    BMSZ03      N     BUKIT MERAH
##   PLN_AREA_C       REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR
## 1         MS CENTRAL REGION       CR 5ED7EB253F99252E 2014-12-05 31595.84
## 2         OT CENTRAL REGION       CR 8C7149B9EB32EEFC 2014-12-05 28679.06
## 3         SR CENTRAL REGION       CR C35FEFF02B13E0E5 2014-12-05 29654.96
## 4         BM CENTRAL REGION       CR 3775D82C5DDBEFBD 2014-12-05 26782.83
## 5         BM CENTRAL REGION       CR 85D9ABEF0A40678F 2014-12-05 26201.96
##     Y_ADDR SHAPE_Leng SHAPE_Area              PA 2_to_6
## 1 29220.19   5267.381  1630379.3    MARINA SOUTH      0
## 2 29782.05   3506.107   559816.2          OUTRAM    230
## 3 29974.66   1740.926   160807.5 SINGAPORE RIVER      0
## 4 29933.77   3313.625   595428.9     BUKIT MERAH    370
## 5 30005.70   2825.594   387429.4     BUKIT MERAH    590
##                         geometry Childcare_Count Kindergarten_Count
## 1 MULTIPOLYGON (((31495.56 30...              NA                 NA
## 2 MULTIPOLYGON (((29092.28 30...               4                  1
## 3 MULTIPOLYGON (((29932.33 29...              NA                 NA
## 4 MULTIPOLYGON (((27131.28 30...               3                  1
## 5 MULTIPOLYGON (((26451.03 30...               1                  1
##   Pop_per_Childcare Pop_per_Kindergarten
## 1                NA                   NA
## 2           57.5000                  230
## 3                NA                   NA
## 4          123.3333                  370
## 5          590.0000                  590

This code chunk will list the planning subzone with the under-supply of kindergarten services

top_n(subzone_popagesex2018, 1, `Pop_per_Kindergarten`)
## Simple feature collection with 1 feature and 21 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 33952.59 ymin: 42084.75 xmax: 36120.62 ymax: 43285.61
## projected CRS:  SVY21 / Singapore TM
##   OBJECTID SUBZONE_NO SUBZONE_N SUBZONE_C CA_IND PLN_AREA_N PLN_AREA_C
## 1      266          3   MATILDA    PGSZ03      N    PUNGGOL         PG
##            REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR   Y_ADDR
## 1 NORTH-EAST REGION      NER 14D0DB33976B7B81 2014-12-05 35089.99 42728.27
##   SHAPE_Leng SHAPE_Area      PA 2_to_6                       geometry
## 1   5361.916    1418284 PUNGGOL   5750 MULTIPOLYGON (((35984.25 42...
##   Childcare_Count Kindergarten_Count Pop_per_Childcare Pop_per_Kindergarten
## 1              11                  1          522.7273                 5750

Observation: By looking at the result, it can see that ‘MATILDA’ planning subzone has 5750 children of age between 2 to 6. However, there is only 1 kindergarten to accommodate all 5750 childcare population of that particular subzone. In this case, we can conclude that there is a mismatch between the supply and demand within this subzone or over-utilizing the childcare center assuming all the children in this planning subzone will go to the childcare center only within its subzone.

This code chunk will list the planning subzone with the over-supply of kindergarten services

top_n(subzone_popagesex2018, -1, `Pop_per_Kindergarten`)
## Simple feature collection with 2 features and 21 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 35122.98 ymin: 38644.89 xmax: 44163.44 ymax: 44808.89
## projected CRS:  SVY21 / Singapore TM
##   OBJECTID SUBZONE_NO   SUBZONE_N SUBZONE_C CA_IND PLN_AREA_N PLN_AREA_C
## 1      229          6 LOYANG WEST    PRSZ06      N  PASIR RIS         PR
## 2      277          1  NORTHSHORE    PGSZ01      N    PUNGGOL         PG
##            REGION_N REGION_C          INC_CRC FMEL_UPD_D   X_ADDR   Y_ADDR
## 1       EAST REGION       ER 05FD555397CBEE7A 2014-12-05 43294.83 39888.77
## 2 NORTH-EAST REGION      NER 317584A40150FF3F 2014-12-05 36169.56 44222.77
##   SHAPE_Leng SHAPE_Area        PA 2_to_6                       geometry
## 1   6203.002    2114789 PASIR RIS      0 MULTIPOLYGON (((43756.39 39...
## 2   5355.637    1360001   PUNGGOL      0 MULTIPOLYGON (((36866.94 44...
##   Childcare_Count Kindergarten_Count Pop_per_Childcare Pop_per_Kindergarten
## 1              NA                  1                NA                    0
## 2               5                  1                 0                    0

Observation: By looking at the result, it can see that there are two planning subzones, "LOYANG WEST’ and ‘NORTHSHORE’ with no demand for kindergarten services but kindergarten are located in them. Therefore, it can say that there is a mismatch between the supply and demand of kindergarten services for these subzones as well. In this case, we can conclude that these kindergarten are under-utilization for the planning subzone, assuming only the children population within the planning subzone will access them.

5.6. Plotting the demand and supply ratio of childcare services

At this stage, we will plot the demand and supply ratio of childcare center on the Choropleth Map to see which subzones have a good demand and supply of childcare services and which subzones are not meeting the demand and supply for childcare services.

  • The darker green means that the higher number childrens are being served by the available number of childcare centers within the subzones.*
  • The lighter green means, the lower number childrens are being served by the available number of childcare centers within the subzones..

This code chunk will plot the Pop_per_Childcare

tm_shape(subzone_popagesex2018)+
  tm_fill("Pop_per_Childcare",
          title = "Pop_per_Childcare",
          style = "quantile",
          palette = "Reds")+ 
  tm_layout(main.title = "Childcare Demand and Supply Ratio by Planning Subzone",
            main.title.position = "center",
            main.title.size = 1,
            frame = FALSE)+
  tm_borders(alpha = 0.5)

Observation: The map can be interpreted as the darker the color of the planning subzone is, the more number population are being served by the available number of childcare centers within the subzones.

5.7. Plotting the demand and supply of kindergartens

At this stage, we will plot the Pop_per_Kindergarten on the Choropleth Map to see which subzones have a good demand and supply of kindergarten services and which subzones failed to meet the demand and supply for kindergarten services.

  • The darker green means that the supply and demand of kindergarten services are matched for that subzone.
  • The lighter green means, the supply and demand are mismatched.

This code chunk will plot the Pop_per_Kindergarten

tm_shape(subzone_popagesex2018)+
  tm_fill("Pop_per_Kindergarten", 
          title = "Pop_per_Kindergarten",
          style = "quantile",
          palette = "Reds")+
  tm_borders(alpha = 0.5) + 
  tm_layout(main.title = "Kindergarten Demand and Supply Ratio by Planning Subzone",
            main.title.position = "center",
            main.title.size = 1,
            frame = FALSE)

Observation: The map can be interpreted as the darker the color of the planning subzone is, the more population are being served by the available number of kindergarten within the subzones.

5.8. Side by side view of Childcare and Kindergarten Supply by Subzone

This code chunk show the comparison between supply of the childcare and kindergarten

childcarecountmap <- tm_shape(subzone_popagesex2018)+ 
  tm_polygons("Childcare_Count", 
              style = "pretty", 
              palette = "Greens") + 
  tm_layout(main.title = "Childcare Supply by Planning Subzone",
            main.title.position = "center",
            main.title.size = 1,
            frame = TRUE) 
  
kindergartencountmap <- tm_shape(subzone_popagesex2018)+ 
  tm_polygons("Kindergarten_Count", 
              style = "fixed",
              breaks = c(1, 11, 21, 31, 41),
              palette = "Greens")+
  tm_layout(main.title = "Kindergarten Supply by Planning Subzone",
            main.title.position = "center",
            main.title.size = 1,
            frame = TRUE)

tmap_arrange(childcarecountmap, kindergartencountmap, asp=1, ncol=2)

Observation: The comparison between this two maps showed that there are more childcare services than kindergarten services in Singapore. Moreover, the locations of childcare centers are more spread out across different planning areas compare to kindergartens. Moreover, the highest number of childcare centers operating in a subzone can range up to 41 to 50 while the highest number of kindergarten operating in a subzone is only between 11 to 20

5.8. Supply and Demand of Childcare & Kindergarten on a single Choropleth Map

tmap_mode("view")
## tmap mode set to interactive viewing
childcare_map <- tm_shape(subzone_popagesex2018) + tm_polygons("2_to_6")+
tm_shape(sf_childcare3414) + tm_dots("red") + 
   tm_layout(main.title = "Demand & Supply of Childcare",
            main.title.position = "center",
            main.title.size = 1,
            frame = FALSE) 


kindergarten_map<- tm_shape(subzone_popagesex2018) + tm_polygons("2_to_6") +
tm_shape(sf_kindergarten3414) + tm_dots("green") + 
  tm_layout(main.title = "Demand & Supply of Kindergarten",
            main.title.position = "center",
            main.title.size = 1,
            frame = FALSE) 

tmap_arrange(childcare_map, kindergarten_map, asp = 2, ncol=2, sync=TRUE)

Observation: Based on the above map, there are more red points(childcare services) than the green points (kindergaten). This shows that there are more childcare centers than kindgartens in Singapore. Moreover, whem we zoom into the map, we can see that there are more childcare and kindergarten services available in the area with more population. This means that these services are mostly available in the residential areas compare to non-residential area since there are more demand for those services in the residential areas.

tmap_mode("plot")
## tmap mode set to plotting

5.9. A single map view of childcare and kindergarten located within each planning subzone

This code chunk will show the childcare and kindergarten located within each planning subzone in a single map.

tm_shape(sf_subzone3414) + 
  tm_polygons("SUBZONE_N", border.col = NULL) + 
  tm_legend(outside = TRUE) +
  tm_layout(legend.outside = TRUE,
            legend.height = 0.45, 
            legend.width = 5.0,
            frame = FALSE) + 
 tm_shape(sf_childcare) + tm_dots(size=.1, col="red") +
 tm_shape(sf_kindergarten3414) + tm_dots(size=.1, col="green") 
## Warning in pre_process_gt(x, interactive = interactive, orig_crs =
## gm$shape.orig_crs): legend.width controls the width of the legend within a map.
## Please use legend.outside.size to control the width of the outside legend
## Warning: Number of levels of the variable "SUBZONE_N" is 323, which is
## larger than max.categories (which is 30), so levels are combined. Set
## tmap_options(max.categories = 323) in the layer function to show all levels.
## Some legend labels were too wide. These labels have been resized to 0.35. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.

Observation: By looking at this spatial objects that representing the childcare and kindergarten data, it can be see that there are more childcare centers than kindergartens in Singapore. This can also be because the childcare serve the children age of 18 months to below 7 years old which will have higher demand compare the kindergarten that only serve the age group of 4 to 6.

5.10. Histrogram

Histogram will be used to describe the density of childcare and kindergarten within each planning subzone.

This code chunk will use to create a new field ‘Area’ in the subzone_popagesex2018

subzone_popagesex2018$Area <- subzone_popagesex2018 %>% 
  st_area()
subzone_popagesex2018 <- subzone_popagesex2018 %>%  
mutate(`Childcare Density` = as.numeric(`Childcare_Count`/Area*1000000), 
       `Kindergarten Density` = as.numeric(`Kindergarten_Count`/Area*1000000))
childcare_histogram <- ggplot(data=subzone_popagesex2018, 
       aes(x= as.numeric(`Childcare Density`)))+
  geom_histogram(bins=20, color="black", fill="light blue") + 
  scale_y_continuous(limits = c(0, 50), breaks = seq(0, 50, by=10 ))
kindergarten_histogram <- ggplot(data=subzone_popagesex2018, 
       aes(x= as.numeric(`Kindergarten Density`)))+
  geom_histogram(bins=20, color="black", fill="light blue") + 
  scale_y_continuous(limits = c(0, 50), breaks = seq(0, 50, by=10 ))
grid.arrange(childcare_histogram, kindergarten_histogram, ncol=2)
## Warning: Removed 96 rows containing non-finite values (stat_bin).
## Warning: Removed 161 rows containing non-finite values (stat_bin).

Observation: Based on the histograms, we can see that both of them are left-skewed. Moreover, we can also observe that childcare’s x-asis can range up to 40 for density when the kindergarten’s density can only range up to 10. From the histograms, we can also find out that childcare’s density has a bar for every breakpoint until 20 while the kindergarten’s plot rarely have a value bar until 5. This indicates that there are more childcare services within each planning subzone than kindergarten services since childcare has a higher density than kindergarten.

5.11. Scatter Plot

A scatter plot is a type of data display that shows the relationship between two numerical variables.

This code chunk used scatter plot to see if there is a relationship

scatter <- ggplot(data=subzone_popagesex2018, 
       aes(y=`Childcare_Count`, x= `Kindergarten_Count`))+
  geom_point(color="black", fill="light blue")+
    geom_smooth(method=lm)

This code chunk will plot the scatter

ggplotly(scatter)
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 165 rows containing non-finite values (stat_smooth).

Observation: This scatter plot showed that there is a high positive correlation between kindergarten and childcare.

6. Spatial Point Patterns Analysis

6.1 Converting the spatial point data frame into generic sp format

Firstly, in order to carry out spatial point pattern analysis, spastat library requires the data in the ppp object form. Therefore, all the SpatialDataFrames we have previously need to be converted to Spatial Point Object first.

The codes below will convert the sf_subzone3414 spatial dataframes into generic spatialpoints object.

subzone_sp <- as_Spatial(sf_subzone3414)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO"): Discarded datum Unknown based on WGS84 ellipsoid in CRS definition,
##  but +towgs84= values preserved
subzone_sp
## class       : SpatialPolygonsDataFrame 
## features    : 323 
## extent      : 2667.538, 56396.44, 15748.72, 50256.33  (xmin, xmax, ymin, ymax)
## crs         : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
## variables   : 15
## names       : OBJECTID, SUBZONE_NO, SUBZONE_N, SUBZONE_C, CA_IND, PLN_AREA_N, PLN_AREA_C,       REGION_N, REGION_C,          INC_CRC, FMEL_UPD_D,     X_ADDR,     Y_ADDR,    SHAPE_Leng,    SHAPE_Area 
## min values  :        1,          1, ADMIRALTY,    AMSZ01,      N, ANG MO KIO,         AM, CENTRAL REGION,       CR, 00F5E30B5C9B7AD8,      16409,  5092.8949,  19579.069, 871.554887798, 39437.9352703 
## max values  :      323,         17,    YUNNAN,    YSSZ09,      Y,     YISHUN,         YS,    WEST REGION,       WR, FFCCF172717C2EAF,      16409, 50424.7923, 49552.7904, 68083.9364708,  69748298.792

The codes below will convert the sf_childcare3414 spatial dataframe into generic spatialpoints object.

childcare_sp <- as_Spatial(sf_childcare3414$geometry)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO"): Discarded datum Unknown based on WGS84 ellipsoid in CRS definition,
##  but +towgs84= values preserved
crs(childcare_sp)
## CRS arguments:
##  +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1
## +x_0=28001.642 +y_0=38744.572 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0
## +units=m +no_defs

The codes below will convert the sf_kindergarten3414 spatial dataframe into generic spatialpoints object.

kindergarten_sp <- as_Spatial(sf_kindergarten3414$geometry)
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO"): Discarded datum Unknown based on WGS84 ellipsoid in CRS definition,
##  but +towgs84= values preserved
kindergarten_sp
## class       : SpatialPoints 
## features    : 448 
## extent      : 11909.7, 43395.47, 25596.33, 48562.06  (xmin, xmax, ymin, ymax)
## crs         : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs

6.2. Converting the generic sp format into spatstat’s ppp format

Since spastat library requires the data in the ppp object form, we wll use as.ppp() function of spastat to convert the spatial data into spastat’s ppp object format. This will be done for both the childcare_sp and kindergarten_sp spatial objects.

This code chunk will convert the childcare_sp spatial object into spastat’s ppp object.

childcare_ppp <- as(spTransform(childcare_sp,CRS("+init=epsg:3414")), "ppp")
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO"): Discarded
## datum SVY21 in CRS definition
plot(childcare_ppp)

This code chunk will check the summary statstics of the newly created ’childcare_ppp’object.

summary(childcare_ppp)
## Planar point pattern:  1545 points
## Average intensity 1.91145e-06 points per square unit
## 
## *Pattern contains duplicated points*
## 
## Coordinates are given to 3 decimal places
## i.e. rounded to the nearest multiple of 0.001 units
## 
## Window: rectangle = [11203.01, 45404.24] x [25667.6, 49300.88] units
##                     (34200 x 23630 units)
## Window area = 808287000 square units

This code chunk will convert the kindergarten spatial object into spastat’s ppp object.

kindergarten_ppp <- as(kindergarten_sp, "ppp")
kindergarten_ppp
## Planar point pattern: 448 points
## window: rectangle = [11909.7, 43395.47] x [25596.33, 48562.06] units

This code chunk will check the summary statstics of the newly created ’kindergarten_ppp’object.

summary(kindergarten_ppp)
## Planar point pattern:  448 points
## Average intensity 6.195602e-07 points per square unit
## 
## *Pattern contains duplicated points*
## 
## Coordinates are given to 3 decimal places
## i.e. rounded to the nearest multiple of 0.001 units
## 
## Window: rectangle = [11909.7, 43395.47] x [25596.33, 48562.06] units
##                     (31490 x 22970 units)
## Window area = 723094000 square units

6.3. Checking for duplicated points

This code chunk will check for duplicated points in the childcare_ppp object

any(duplicated(childcare_ppp))
## [1] TRUE

Observation: Based on the output, we can see that there are duplicated points event in the object that we have to further look into.

This code chunk will check for duplicated points in the kindergaten_ppp object

any(duplicated(kindergarten_ppp))
## [1] TRUE

Observation: Based on the output, we can see that there are duplicated points event in the object that we have to further look into.

This code chunk will show how many locations have more than one point event in the childcare_ppp object

sum(multiplicity(childcare_ppp) > 1)
## [1] 128

Observation: Based on the output, we can see that there are 128 duplicated point events.

This code chunk will show how many locations have more than one point event in the kindergarten_ppp object

sum(multiplicity(kindergarten_ppp) > 1)
## [1] 100

Observation: Based on the output, we can see that there are 100 duplicated point events.

Since we have to overcome the problem of duplicate, my solution is to use jittering to add a small perturbation to the duplicate points so that they do not occupy the exact same space.

This code chunk will implement the jitter approach on the childcare_ppp to move the point away to another space by a little.

childcare_ppp_jit <- rjitter(childcare_ppp, retry=TRUE, nsim=1, drop=TRUE)

plot(childcare_ppp_jit)

This code chunk will implement the jitter approach on the kindergarten_ppp to move the point away to another space by a little.

kindergarten_ppp_jit <- rjitter(kindergarten_ppp, retry=TRUE, nsim=1, drop=TRUE)

plot(kindergarten_ppp_jit)

6.4. Creating owin

When analyzing spatial point patterns, it is a good practice to confine the analysis with a geographical area like Singapore boundary. In spatstat, an object called owin is specially designed to represent this polygonal region.

The code chunk below is used to covert sg SpatialPolygon object into owin object of spatstat.

subzone_owin <- as(subzone_sp, "owin")

plot(subzone_owin)

summary(subzone_owin)
## Window: polygonal boundary
## 387 separate polygons (21 holes)
##                    vertices         area relative.area
## polygon 1               156  1.63038e+06      2.09e-03
## polygon 2               305  5.59816e+05      7.16e-04
## polygon 3                47  1.60807e+05      2.06e-04
## polygon 4                47  5.95429e+05      7.61e-04
## polygon 5                48  3.87429e+05      4.95e-04
## polygon 6                59  1.03038e+06      1.32e-03
## polygon 7                83  5.51732e+05      7.06e-04
## polygon 8                70  2.90185e+05      3.71e-04
## polygon 9               217  1.08479e+06      1.39e-03
## polygon 10               42  6.31644e+05      8.08e-04
## polygon 11              226  1.82685e+06      2.34e-03
## polygon 12               53  2.93706e+05      3.76e-04
## polygon 13              256  1.84406e+06      2.36e-03
## polygon 14              165  3.92563e+05      5.02e-04
## polygon 15              240  5.06589e+05      6.48e-04
## polygon 16             1151  3.30122e+07      4.22e-02
## polygon 17 (hole)        26 -1.25665e+03     -1.61e-06
## polygon 18              478  2.06120e+06      2.64e-03
## polygon 19              266  1.50631e+06      1.93e-03
## polygon 20               65  8.42861e+04      1.08e-04
## polygon 21               47  3.82087e+04      4.89e-05
## polygon 22               22  6.74651e+03      8.63e-06
## polygon 23              234  2.08755e+06      2.67e-03
## polygon 24              227  1.10308e+06      1.41e-03
## polygon 25              145  9.61782e+05      1.23e-03
## polygon 26               19  3.09221e+04      3.95e-05
## polygon 27               37  1.29481e+04      1.66e-05
## polygon 28               10  6.60195e+03      8.44e-06
## polygon 29               30  4.28933e+03      5.49e-06
## polygon 30                4  9.47108e+01      1.21e-07
## polygon 31             1045  4.44510e+06      5.68e-03
## polygon 32 (hole)        13 -3.91907e+02     -5.01e-07
## polygon 33              234  4.72886e+05      6.05e-04
## polygon 34               15  4.03300e+04      5.16e-05
## polygon 35               14  5.86546e+03      7.50e-06
## polygon 36             1027  1.27782e+06      1.63e-03
## polygon 37 (hole)         3 -3.23310e-04     -4.13e-13
## polygon 38 (hole)         3 -1.16959e-03     -1.50e-12
## polygon 39 (hole)         3 -1.46474e-03     -1.87e-12
## polygon 40              211  4.70521e+05      6.02e-04
## polygon 41              155  2.67502e+05      3.42e-04
## polygon 42              132  9.53357e+04      1.22e-04
## polygon 43               95  5.96187e+04      7.62e-05
## polygon 44 (hole)         4 -1.86410e-02     -2.38e-11
## polygon 45               64  3.43149e+04      4.39e-05
## polygon 46 (hole)         3 -1.98390e-03     -2.54e-12
## polygon 47 (hole)         3 -5.55856e-03     -7.11e-12
## polygon 48 (hole)         6 -7.08892e-03     -9.07e-12
## polygon 49 (hole)         4 -1.13774e-02     -1.46e-11
## polygon 50               10  4.90942e+02      6.28e-07
## polygon 51                6  4.50259e+02      5.76e-07
## polygon 52                4  2.69313e+02      3.44e-07
## polygon 53             1475  4.87083e+06      6.23e-03
## polygon 54 (hole)        12 -8.36709e+01     -1.07e-07
## polygon 55               75  1.73526e+04      2.22e-05
## polygon 56               40  1.38607e+04      1.77e-05
## polygon 57               83  5.28920e+03      6.76e-06
## polygon 58              142  3.22293e+03      4.12e-06
## polygon 59              148  3.10395e+03      3.97e-06
## polygon 60              106  3.04104e+03      3.89e-06
## polygon 61               45  2.51218e+03      3.21e-06
## polygon 62              430  3.44964e+06      4.41e-03
## polygon 63               85  1.03238e+05      1.32e-04
## polygon 64              104  1.12730e+06      1.44e-03
## polygon 65                3  6.12658e-02      7.84e-11
## polygon 66              775  2.70301e+06      3.46e-03
## polygon 67 (hole)        20 -4.39069e+00     -5.62e-09
## polygon 68 (hole)        76 -1.58325e+02     -2.02e-07
## polygon 69 (hole)       351 -1.21433e+03     -1.55e-06
## polygon 70               53  2.76827e+05      3.54e-04
## polygon 71              115  6.36650e+04      8.14e-05
## polygon 72               84  1.96620e+05      2.51e-04
## polygon 73               33  3.65333e+05      4.67e-04
## polygon 74              106  1.45483e+06      1.86e-03
## polygon 75              133  8.53207e+05      1.09e-03
## polygon 76              196  1.07072e+06      1.37e-03
## polygon 77               47  5.33017e+05      6.82e-04
## polygon 78               82  4.42503e+05      5.66e-04
## polygon 79              222  9.31404e+04      1.19e-04
## polygon 80               37  4.11723e+05      5.27e-04
## polygon 81              230  5.87223e+05      7.51e-04
## polygon 82               35  3.94379e+04      5.04e-05
## polygon 83               96  1.88767e+05      2.41e-04
## polygon 84               59  1.33007e+05      1.70e-04
## polygon 85               47  4.48128e+05      5.73e-04
## polygon 86               31  5.21201e+05      6.67e-04
## polygon 87               17  3.50788e+05      4.49e-04
## polygon 88               54  2.61844e+05      3.35e-04
## polygon 89              240  1.59034e+06      2.03e-03
## polygon 90              298  8.86955e+05      1.13e-03
## polygon 91              190  2.23207e+05      2.85e-04
## polygon 92              143  2.00053e+05      2.56e-04
## polygon 93              169  7.10569e+05      9.09e-04
## polygon 94               34  7.48684e+05      9.57e-04
## polygon 95              192  5.91779e+05      7.57e-04
## polygon 96              178  1.75595e+06      2.25e-03
## polygon 97              193  3.40743e+05      4.36e-04
## polygon 98              219  3.29438e+05      4.21e-04
## polygon 99               88  1.70664e+05      2.18e-04
## polygon 100             173  3.68483e+05      4.71e-04
## polygon 101             294  7.60189e+06      9.72e-03
## polygon 102             243  2.21973e+05      2.84e-04
## polygon 103             130  2.80175e+05      3.58e-04
## polygon 104             141  2.14250e+05      2.74e-04
## polygon 105              83  1.73122e+05      2.21e-04
## polygon 106              92  5.33671e+05      6.82e-04
## polygon 107              95  1.45519e+05      1.86e-04
## polygon 108              55  6.35704e+05      8.13e-04
## polygon 109              54  5.03221e+05      6.44e-04
## polygon 110              48  5.56813e+04      7.12e-05
## polygon 111              60  1.16330e+05      1.49e-04
## polygon 112             137  2.05165e+06      2.62e-03
## polygon 113             122  2.43459e+06      3.11e-03
## polygon 114             114  1.71362e+06      2.19e-03
## polygon 115              55  3.10514e+05      3.97e-04
## polygon 116              95  1.38664e+06      1.77e-03
## polygon 117             127  1.95187e+06      2.50e-03
## polygon 118             266  4.52472e+05      5.79e-04
## polygon 119              79  6.97502e+05      8.92e-04
## polygon 120             442  2.77051e+07      3.54e-02
## polygon 121              71  5.63061e+03      7.20e-06
## polygon 122              10  1.99717e+02      2.55e-07
## polygon 123             119  1.71721e+05      2.20e-04
## polygon 124             277  1.09783e+06      1.40e-03
## polygon 125             136  1.05349e+06      1.35e-03
## polygon 126             304  2.79601e+06      3.58e-03
## polygon 127 (hole)        3 -2.18000e-06     -2.79e-15
## polygon 128             556  3.04972e+06      3.90e-03
## polygon 129 (hole)        3 -6.62377e-01     -8.47e-10
## polygon 130 (hole)        3 -2.09065e-03     -2.67e-12
## polygon 131             139  3.36221e+05      4.30e-04
## polygon 132              62  7.41438e+05      9.48e-04
## polygon 133             322  4.60550e+05      5.89e-04
## polygon 134             199  5.43484e+05      6.95e-04
## polygon 135              52  2.78304e+05      3.56e-04
## polygon 136             544  1.76950e+06      2.26e-03
## polygon 137             150  3.85093e+05      4.92e-04
## polygon 138             120  5.58761e+05      7.15e-04
## polygon 139              88  5.67581e+06      7.26e-03
## polygon 140             212  2.09609e+06      2.68e-03
## polygon 141              89  7.22589e+05      9.24e-04
## polygon 142             279  2.55046e+06      3.26e-03
## polygon 143              34  2.04263e+06      2.61e-03
## polygon 144              70  3.26040e+06      4.17e-03
## polygon 145             216  1.34615e+06      1.72e-03
## polygon 146              25  1.71334e+05      2.19e-04
## polygon 147              84  4.96260e+04      6.35e-05
## polygon 148             199  1.93992e+05      2.48e-04
## polygon 149              77  1.20171e+05      1.54e-04
## polygon 150             272  8.50854e+05      1.09e-03
## polygon 151              99  1.02647e+06      1.31e-03
## polygon 152             154  1.67537e+05      2.14e-04
## polygon 153              81  1.16002e+06      1.48e-03
## polygon 154              32  2.56100e+06      3.28e-03
## polygon 155             112  7.35502e+05      9.41e-04
## polygon 156             124  9.48159e+05      1.21e-03
## polygon 157             134  1.32109e+06      1.69e-03
## polygon 158              59  2.99731e+06      3.83e-03
## polygon 159             123  1.37683e+06      1.76e-03
## polygon 160             129  1.92662e+06      2.46e-03
## polygon 161             522  3.20331e+06      4.10e-03
## polygon 162              93  2.34938e+06      3.00e-03
## polygon 163              85  9.63199e+05      1.23e-03
## polygon 164              36  4.85022e+05      6.20e-04
## polygon 165              82  1.88131e+06      2.41e-03
## polygon 166             103  1.42508e+06      1.82e-03
## polygon 167              60  2.38728e+06      3.05e-03
## polygon 168             114  1.07899e+06      1.38e-03
## polygon 169              71  4.59546e+05      5.88e-04
## polygon 170              91  2.47888e+05      3.17e-04
## polygon 171             107  2.13582e+05      2.73e-04
## polygon 172             213  2.47266e+06      3.16e-03
## polygon 173 (hole)       36 -7.79904e+03     -9.97e-06
## polygon 174               4  1.41753e-02      1.81e-11
## polygon 175             583  1.94069e+06      2.48e-03
## polygon 176             349  2.11850e+06      2.71e-03
## polygon 177             109  4.85047e+05      6.20e-04
## polygon 178             102  7.57908e+05      9.69e-04
## polygon 179             120  3.51242e+05      4.49e-04
## polygon 180              72  1.31292e+06      1.68e-03
## polygon 181              63  9.46651e+05      1.21e-03
## polygon 182             100  7.48043e+05      9.57e-04
## polygon 183             111  1.02229e+06      1.31e-03
## polygon 184              95  4.10995e+05      5.26e-04
## polygon 185              73  8.39489e+05      1.07e-03
## polygon 186             173  1.22849e+06      1.57e-03
## polygon 187              43  5.54624e+05      7.09e-04
## polygon 188             130  3.39290e+06      4.34e-03
## polygon 189              97  1.87809e+06      2.40e-03
## polygon 190              40  8.67750e+05      1.11e-03
## polygon 191              55  6.39144e+05      8.17e-04
## polygon 192              39  3.26015e+06      4.17e-03
## polygon 193              54  4.11404e+05      5.26e-04
## polygon 194              75  4.18657e+05      5.35e-04
## polygon 195             104  2.09818e+06      2.68e-03
## polygon 196              92  1.52455e+06      1.95e-03
## polygon 197              79  8.13383e+05      1.04e-03
## polygon 198              94  1.48430e+06      1.90e-03
## polygon 199             118  3.10802e+06      3.97e-03
## polygon 200              97  1.03728e+06      1.33e-03
## polygon 201             157  2.82017e+06      3.61e-03
## polygon 202              53  9.24762e+05      1.18e-03
## polygon 203             118  1.80655e+06      2.31e-03
## polygon 204              64  1.40454e+06      1.80e-03
## polygon 205              91  2.37933e+06      3.04e-03
## polygon 206             111  2.07780e+06      2.66e-03
## polygon 207             134  3.14295e+06      4.02e-03
## polygon 208             195  2.63648e+06      3.37e-03
## polygon 209              80  1.05717e+06      1.35e-03
## polygon 210              56  1.28795e+06      1.65e-03
## polygon 211              69  4.39647e+05      5.62e-04
## polygon 212              51  7.46882e+05      9.55e-04
## polygon 213              61  4.46242e+05      5.71e-04
## polygon 214              72  5.72502e+05      7.32e-04
## polygon 215             152  2.95937e+06      3.78e-03
## polygon 216             119  2.15829e+06      2.76e-03
## polygon 217             140  1.34746e+06      1.72e-03
## polygon 218              60  2.33891e+06      2.99e-03
## polygon 219             111  4.29714e+06      5.50e-03
## polygon 220             105  9.91040e+05      1.27e-03
## polygon 221             202  2.04955e+06      2.62e-03
## polygon 222             127  2.57909e+06      3.30e-03
## polygon 223              91  3.18758e+06      4.08e-03
## polygon 224              40  9.06317e+05      1.16e-03
## polygon 225              41  3.80202e+05      4.86e-04
## polygon 226              93  5.26383e+05      6.73e-04
## polygon 227              77  8.00299e+05      1.02e-03
## polygon 228             124  8.98561e+05      1.15e-03
## polygon 229             172  1.79346e+06      2.29e-03
## polygon 230             378  3.18810e+06      4.08e-03
## polygon 231              85  4.94504e+05      6.32e-04
## polygon 232              79  1.06189e+06      1.36e-03
## polygon 233              75  1.79446e+06      2.29e-03
## polygon 234              96  3.47521e+06      4.44e-03
## polygon 235              74  1.22567e+06      1.57e-03
## polygon 236             139  1.97437e+06      2.52e-03
## polygon 237             159  1.08508e+06      1.39e-03
## polygon 238              90  1.96413e+06      2.51e-03
## polygon 239              43  1.97494e+06      2.53e-03
## polygon 240             141  4.14132e+06      5.30e-03
## polygon 241             164  4.33982e+06      5.55e-03
## polygon 242             131  1.79606e+06      2.30e-03
## polygon 243             130  2.25116e+06      2.88e-03
## polygon 244             124  7.76142e+05      9.93e-04
## polygon 245             105  2.20631e+06      2.82e-03
## polygon 246             107  1.18013e+06      1.51e-03
## polygon 247              73  1.22989e+06      1.57e-03
## polygon 248             101  9.64683e+05      1.23e-03
## polygon 249              75  1.26341e+06      1.62e-03
## polygon 250              51  3.69771e+05      4.73e-04
## polygon 251              83  3.20366e+06      4.10e-03
## polygon 252              96  1.10727e+06      1.42e-03
## polygon 253              81  1.28739e+06      1.65e-03
## polygon 254              32  8.42668e+05      1.08e-03
## polygon 255              61  1.33353e+06      1.71e-03
## polygon 256              50  1.00741e+06      1.29e-03
## polygon 257             147  8.94516e+05      1.14e-03
## polygon 258              76  9.11208e+05      1.17e-03
## polygon 259              43  1.14381e+06      1.46e-03
## polygon 260              95  1.32888e+06      1.70e-03
## polygon 261             111  6.09895e+05      7.80e-04
## polygon 262              66  7.63183e+05      9.76e-04
## polygon 263             164  2.76835e+06      3.54e-03
## polygon 264             134  3.46704e+06      4.43e-03
## polygon 265             401  7.83399e+06      1.00e-02
## polygon 266              80  2.77864e+06      3.55e-03
## polygon 267              54  8.62737e+05      1.10e-03
## polygon 268             105  1.58344e+06      2.03e-03
## polygon 269              43  8.46137e+05      1.08e-03
## polygon 270             122  1.74439e+06      2.23e-03
## polygon 271              89  1.00159e+06      1.28e-03
## polygon 272              82  1.09730e+06      1.40e-03
## polygon 273             251  4.84852e+06      6.20e-03
## polygon 274              53  6.68454e+05      8.55e-04
## polygon 275              69  6.24878e+05      7.99e-04
## polygon 276              85  6.74992e+05      8.63e-04
## polygon 277             123  2.33068e+06      2.98e-03
## polygon 278              68  1.09321e+06      1.40e-03
## polygon 279              83  1.86187e+06      2.38e-03
## polygon 280              45  9.09419e+05      1.16e-03
## polygon 281             108  2.11479e+06      2.70e-03
## polygon 282             204  3.33419e+06      4.26e-03
## polygon 283              59  1.51553e+06      1.94e-03
## polygon 284              60  9.44998e+05      1.21e-03
## polygon 285             189  1.99079e+06      2.55e-03
## polygon 286              83  1.64141e+06      2.10e-03
## polygon 287             173  1.65255e+05      2.11e-04
## polygon 288              91  1.49663e+04      1.91e-05
## polygon 289              71  8.18750e+03      1.05e-05
## polygon 290              83  2.25924e+06      2.89e-03
## polygon 291             221  3.86032e+06      4.94e-03
## polygon 292              58  8.59179e+05      1.10e-03
## polygon 293              63  5.46404e+05      6.99e-04
## polygon 294              71  1.94861e+06      2.49e-03
## polygon 295              87  1.07862e+06      1.38e-03
## polygon 296              99  6.87930e+05      8.80e-04
## polygon 297             151  3.02315e+06      3.87e-03
## polygon 298              35  4.41733e+05      5.65e-04
## polygon 299              62  9.70068e+05      1.24e-03
## polygon 300              93  1.23590e+06      1.58e-03
## polygon 301             100  1.63967e+06      2.10e-03
## polygon 302             107  2.54311e+06      3.25e-03
## polygon 303              83  9.55710e+05      1.22e-03
## polygon 304              58  3.16882e+05      4.05e-04
## polygon 305              94  1.04642e+06      1.34e-03
## polygon 306              63  9.21431e+05      1.18e-03
## polygon 307             149  7.37056e+06      9.43e-03
## polygon 308              52  6.84704e+05      8.76e-04
## polygon 309             127  1.51149e+06      1.93e-03
## polygon 310             151  2.45910e+06      3.14e-03
## polygon 311             191  7.03481e+06      9.00e-03
## polygon 312             158  3.65203e+06      4.67e-03
## polygon 313             288  1.71970e+06      2.20e-03
## polygon 314              87  1.08864e+06      1.39e-03
## polygon 315              81  1.56903e+06      2.01e-03
## polygon 316             176  1.67003e+06      2.14e-03
## polygon 317              79  2.39108e+06      3.06e-03
## polygon 318              52  1.37871e+06      1.76e-03
## polygon 319             101  9.23215e+05      1.18e-03
## polygon 320             246  5.32542e+06      6.81e-03
## polygon 321              92  1.41828e+06      1.81e-03
## polygon 322              50  1.48925e+06      1.90e-03
## polygon 323             117  5.18613e+06      6.63e-03
## polygon 324             537  3.50960e+07      4.49e-02
## polygon 325              80  1.46328e+06      1.87e-03
## polygon 326             258  9.95945e+05      1.27e-03
## polygon 327              55  1.45551e+06      1.86e-03
## polygon 328              44  1.49911e+06      1.92e-03
## polygon 329              68  9.24866e+05      1.18e-03
## polygon 330             127  1.34017e+06      1.71e-03
## polygon 331             353  8.50444e+06      1.09e-02
## polygon 332 (hole)      317 -5.11280e+04     -6.54e-05
## polygon 333             210  1.36000e+06      1.74e-03
## polygon 334              67  1.43138e+05      1.83e-04
## polygon 335              64  4.36369e+05      5.58e-04
## polygon 336             134  1.25974e+06      1.61e-03
## polygon 337               4  6.49287e-01      8.30e-10
## polygon 338             112  3.29141e+06      4.21e-03
## polygon 339             102  1.57600e+06      2.02e-03
## polygon 340             122  1.66547e+06      2.13e-03
## polygon 341              94  1.76709e+06      2.26e-03
## polygon 342            1835  6.97053e+07      8.91e-02
## polygon 343              30  2.80002e+04      3.58e-05
## polygon 344              27  1.50315e+04      1.92e-05
## polygon 345              95  2.05005e+06      2.62e-03
## polygon 346             129  1.51777e+06      1.94e-03
## polygon 347             117  5.95652e+05      7.62e-04
## polygon 348             263  3.28413e+06      4.20e-03
## polygon 349             118  2.55346e+06      3.27e-03
## polygon 350              50  9.62437e+05      1.23e-03
## polygon 351             112  1.28130e+06      1.64e-03
## polygon 352              26  7.58123e+05      9.70e-04
## polygon 353              76  9.05921e+05      1.16e-03
## polygon 354             285  1.61128e+06      2.06e-03
## polygon 355              66  1.26165e+06      1.61e-03
## polygon 356            1605  1.74949e+07      2.24e-02
## polygon 357 (hole)        3 -8.83647e-03     -1.13e-11
## polygon 358             164  3.45046e+06      4.41e-03
## polygon 359              65  1.74196e+06      2.23e-03
## polygon 360              74  1.39487e+06      1.78e-03
## polygon 361             141  1.07438e+06      1.37e-03
## polygon 362             668  5.40368e+07      6.91e-02
## polygon 363             714  1.28815e+07      1.65e-02
## polygon 364              77  3.29939e+05      4.22e-04
## polygon 365              44  2.26577e+03      2.90e-06
## polygon 366             181  7.23581e+06      9.25e-03
## polygon 367             193  2.14708e+06      2.75e-03
## polygon 368              90  1.51100e+06      1.93e-03
## polygon 369             125  9.36416e+05      1.20e-03
## polygon 370             148  1.64863e+06      2.11e-03
## polygon 371             102  1.09939e+06      1.41e-03
## polygon 372              77  2.20921e+06      2.83e-03
## polygon 373              79  1.26438e+06      1.62e-03
## polygon 374              75  2.20670e+06      2.82e-03
## polygon 375              40  1.26592e+06      1.62e-03
## polygon 376             720  3.71479e+07      4.75e-02
## polygon 377             111  3.91607e+06      5.01e-03
## polygon 378             148  2.17538e+06      2.78e-03
## polygon 379             132  3.62184e+06      4.63e-03
## polygon 380              80  1.43291e+06      1.83e-03
## polygon 381             112  4.38713e+06      5.61e-03
## polygon 382             145  1.20080e+06      1.54e-03
## polygon 383             535  2.45079e+06      3.13e-03
## polygon 384 (hole)        3 -2.21090e+00     -2.83e-09
## polygon 385             125  1.54073e+06      1.97e-03
## polygon 386             379  1.63581e+06      2.09e-03
## polygon 387             357  2.24139e+06      2.87e-03
## enclosing rectangle: [2667.54, 56396.44] x [15748.72, 50256.33] units
##                      (53730 x 34510 units)
## Window area = 781945000 square units
## Fraction of frame area: 0.422

6.5 Combining childcare points and the study area

This code chunk will allow to extract the childcare center that located within specific subzone to do the analysis.

childcareSG_ppp = childcare_ppp_jit[subzone_owin]

This code chunk plot the combined childcare point and Singapore subzone

plot(childcareSG_ppp)

This code chunk will allow to extract the kindergaten that located within specific subzone to do the analysis.

kindergartenSG_ppp = kindergarten_ppp_jit[subzone_owin]

This code chunk plot the combined kindergarten point and Singapore subzone

plot(kindergartenSG_ppp)

par(mfrow=c(1,2))
plot(childcareSG_ppp)
plot(kindergartenSG_ppp)

Observation: Based on these map, we can see that there are more points on childcare plot than kindergarten plot. This shows that there are more childcare services in Singapore compare to Kindergarten services. At the same time, we can see that childcare spatial points are more cluster to one another compared to the kindergarten’s spatial point. Based on the color of the map, we can also say that the area with no spatial points show that there is no childcare and kindergarten services available in those area.

6.6. Chi-Sqaure Quadrat Analysis

Since one of the aim of this assignment is to reveal the respective distribution of the on the childcare and kindergarten services, we will perform a test of Complete Spatial Randomness for a given point patter, based on quadrat counts with the use of quadrat.test() function of statspat.

6.6.1. Performing Monte Carlo hi-Sqaure Quadrat Analysis on childcareSG_PPP object.

The test hypotheses are:

  • Ho = The distribution of childcare services are randomly distributed.

  • H1 = The distribution of childcare services are not randomly distributed.

  • The 95% confident interval will be used.

  • The null hypothesis will be rejected if p-value is smaller than alpha value of 0.05.

The code chunk will perform Chi-squared test of CSR using quadrat counts on the childcareSG_PPP object. The method argument is indicated as “M” in this case.

quadrat.test(childcareSG_ppp, 
             nx = 20, ny = 15,
             method="M",
             nsim=199)
## 
##  Conditional Monte Carlo test of CSR using quadrat counts
##  Test statistic: Pearson X2 statistic
## 
## data:  childcareSG_ppp
## X2 = 2621.1, p-value = 0.01
## alternative hypothesis: two.sided
## 
## Quadrats: 193 tiles (irregular windows)

Observation: Based on the result of X-Square (2631.6) from the Monte Carlo Test of CSR using Quadrat, the variance mean ratio is greater than 1. Therefore, the variance is relatively large and the childcare centers are very cluster to each other. Moreover, since the p-value is 0.01 which is less than alpha value of 0.05 therefore, the null hypothesis of ‘the distribution of childcare services are randomly distributed’ is rejected. since there is a strong evidence that the distribution of childcare services are not randomly distributed.

The null hypothesis will be rejected if p-value is smaller than alpha value of 0.05.

6.6.2. Performing Monte Carlo hi-Sqaure Quadrat Analysis on childcareSG_PPP object.

The test hypotheses are:

  • Ho = The distribution of kindergarten services are randomly distributed.

  • H1 = The distribution of kindergarten services are not randomly distributed.

  • The 95% confident interval will be used.

  • The null hypothesis will be rejected if p-value is smaller than alpha value of 0.05.

The code chunk will perform Chi-squared test of CSR using quadrant counts on the kindergartenSG_ppp object. The method argument is indicated as “M” in this case.

quadrat.test(kindergartenSG_ppp, 
             nx = 20, ny = 15,
             method="M",
             nsim=199)
## 
##  Conditional Monte Carlo test of CSR using quadrat counts
##  Test statistic: Pearson X2 statistic
## 
## data:  kindergartenSG_ppp
## X2 = 837.03, p-value = 0.02
## alternative hypothesis: two.sided
## 
## Quadrats: 193 tiles (irregular windows)

Observation: Based on the result of X-Square (844.53), the variance mean ratio is greater than 1. Therefore, the variance is relatively large and the kindergarten are very cluster to each other. Moreover, since the p-value is 0.01 which is less than alpha value of 0.05 therefore, the null hypothesis of ‘the distribution of kindergarten services are randomly distributed’ is rejected since there is a strong evidence that the distribution of kindergarten services are not randomly distributed.

6.7. Nearest Neighbour Analysis

Nearest neighbor analysis is used to find out the direct distance from a point to its nearest neighbor to identify whether the spatial points are clustered.

In this section, we will perform the Clark-Evans test of aggregation for a spatial point pattern on both the childcareSG_ppp and kindergartenSG_ppp by using clarkevans.test() of statspat.

6.7.1. Testing spatial point patterns using Clark and Evans Test on childcareSG_ppp

The test hypotheses are:

  • Ho = The distribution of childcare services are randomly distributed.

  • H1= The distribution of childcare services are not randomly distributed.

  • 95% confident interval will be used.

  • The null hypothesis will be rejected if p-value is smaller than alpha value of 0.05.

clarkevans.test(childcareSG_ppp,
                correction="none",
                clipregion="subzone_owin",
                alternative=c("two.sided"),
                nsim=199)
## 
##  Clark-Evans test
##  No edge correction
##  Monte Carlo test based on 199 simulations of CSR with fixed n
## 
## data:  childcareSG_ppp
## R = 0.53955, p-value = 0.01
## alternative hypothesis: two-sided

Observation: Based on the output, the R value of Nearest neighbor analysis is 0.54346. This indicates that the point patterns are very cluster. Moreover, the p-value is smaller than significance level of 0.05. Therefore, we reject the null hypothesis that the childcare point patterns are randomly distributed since there is a strong evidence that the distribution of childcare services are not randomly distributed.

6.7.2. Testing spatial point patterns using Clark and Evans Test on kindergartenSG_ppp

The test hypotheses are:

  • Ho = The distribution of kindergarten services are randomly distributed.

  • H1= The distribution of kindergarten services are not randomly distributed.

  • 95% confident interval will be used.

  • The null hypothesis will be rejected if p-value is smaller than alpha value of 0.05.

clarkevans.test(kindergartenSG_ppp,
                correction="none",
                clipregion="subzone_owin",
                alternative=c("two.sided"),
                nsim=199)
## 
##  Clark-Evans test
##  No edge correction
##  Monte Carlo test based on 199 simulations of CSR with fixed n
## 
## data:  kindergartenSG_ppp
## R = 0.49925, p-value = 0.01
## alternative hypothesis: two-sided

Observation: Based on the output, the R value of Nearest neighbor analysis is 0.50431 for the kindergarten point patterns. This indicates that the kindergarten point patterns are very cluster. Moreover, the p-value is smaller than significance level of 0.05. Therefore, we reject the null hypothesis that the kindergarten point patterns are randomly distributed since there is a strong evidence that the distribution of kindergarten services are not randomly distributed.

6.8. Performing 2nd order spatial point patterns analysis test by using G-function

G-function measures the distribution of distances from an arbitrary event to its nearest neighbors. In this section, I will compute G-function estimation and perform Monte Carlo simulationt est on both childcareSG_ppp and kindergartenSG_ppp object using the following functions.

  • Gest() of spastat package - to compute G-function estimation.
  • Use evelope() of spastat package to perform monta carlo simulation test

6.8.1. Compute G-function on Childcare Services

This code chunk will compute G-function using Gest() of spastat package.

G_Childcare = Gest(childcareSG_ppp, correction = "border")
plot(G_Childcare)

After which I will perform Monte Carlo’s Complete Spatial Randomness Hypothesis Test to confirm the observed spatial patterns.

  • Ho = The distribution of childcare services are randomly distributed.

  • H1= The distribution of childcare services are not randomly distributed.

  • The null hypothesis will be rejected if p-value is smaller than alpha value of 0.05.

  • 95% confident interval will be used.

G_Childcare.csr <- envelope(childcareSG_ppp, Gest, nsim = 199)
## Generating 199 simulations of CSR  ...
## 1, 2,  [etd 6:18] 3, 4 [etd 6:05] .6 [etd 6:41] .8
##  [etd 6:36] .10 [etd 6:22] .12 [etd 6:12] .14 [etd 6:04] .16
##  [etd 5:58] .18 [etd 5:51] .20 [etd 5:45] .22 [etd 5:40] .24
##  [etd 5:37] .26 [etd 5:31] .28 [etd 5:26] .30 [etd 5:22] .32
##  [etd 5:17] .34 [etd 5:13] .36 [etd 5:08] .38 [etd 5:03] .40
##  [etd 4:59] .42 [etd 4:56] .44 [etd 4:51] .46 [etd 4:47] .48
##  [etd 4:46] .50 [etd 4:44] .52 [etd 4:41] .54 [etd 4:38] .56
##  [etd 4:34] .58 [etd 4:32] .60 [etd 4:30] .62 [etd 4:28] .64
##  [etd 4:24] .66 [etd 4:21] .68 [etd 4:17] .70 [etd 4:14] .72
##  [etd 4:11] .74 [etd 4:07] .76 [etd 4:03] .78 [etd 3:59] .80
##  [etd 3:55] .82 [etd 3:52] .84 [etd 3:48] .86 [etd 3:45] .88
##  [etd 3:41] .90 [etd 3:37] .92 [etd 3:33] .94 [etd 3:29] .96
##  [etd 3:25] .98 [etd 3:22] .100 [etd 3:18] .102 [etd 3:15] .104
##  [etd 3:12] .106 [etd 3:08] .108 [etd 3:05] .110 [etd 3:02] .112
##  [etd 2:58] .114 [etd 2:54] .116 [etd 2:49] .118 [etd 2:45] .120
##  [etd 2:41] .122 [etd 2:38] .124 [etd 2:34] .126 [etd 2:30] .128
##  [etd 2:27] .130 [etd 2:23] .132 [etd 2:19] .134 [etd 2:15] .136
##  [etd 2:12] .138 [etd 2:08] .140 [etd 2:04] .142 [etd 2:00] .144
##  [etd 1:56] .146 [etd 1:52] .148 [etd 1:48] .150 [etd 1:44] .152
##  [etd 1:40] .154 [etd 1:36] .156 [etd 1:32] .158 [etd 1:28] .160
##  [etd 1:23] .162 [etd 1:19] .164 [etd 1:15] .166 [etd 1:11] .168
##  [etd 1:07] .170 [etd 1:03] .172 [etd 59 sec] .174 [etd 55 sec] .176
##  [etd 51 sec] .178 [etd 46 sec] .180 [etd 42 sec] .182 [etd 37 sec] .184
##  [etd 33 sec] .186 [etd 29 sec] .188 [etd 24 sec] .190 [etd 20 sec] .192
##  [etd 15 sec] .194 [etd 11 sec] .196 [etd 7 sec] .198 [etd 2 sec]  199.
## 
## Done.

This code chunk will plot the G_Childcare.csr

plot(G_Childcare.csr)

Observation: Based on the shape of G-function for G_Childcare.csr, it can conclude that event of the childcare spatial points patterns are clustered since the estimated G(r) lies above the upper envelope and it is statistically significant. Therefore, this result is aligned with the previous spatial point pattern analysis test results. Moreover, since both the 1st order and 2nd order spatial point pattern analysis tests indicate that the point pattern of the childcare services are cluster, we can safely say that the childcare services are relatively clustered to one another.

6.8.2. Compute G-function on Kindergarten Services

This code chunk will compute G-function using Gest() of spastat package.

G_Kindergarten = Gest(kindergartenSG_ppp, correction = "border")
plot(G_Childcare)

After which I will perform Monte Carlo’s Complete Spatial Randomness Hypothesis Test to confirm the observed spatial patterns.

  • Ho = The distribution of kindergarten services are randomly distributed.

  • H1= The distribution of kindergarten services are not randomly distributed.

  • The null hypothesis will be rejected if p-value is smaller than alpha value of 0.05.

G_Kindergarten.csr <- envelope(kindergartenSG_ppp, Gest, nsim = 199) 
## Generating 199 simulations of CSR  ...
## 1, 2, 3, 4 [etd 3:08] .6 [etd 3:05] .8
##  [etd 3:09] .10 [etd 3:05] .12 [etd 3:02] .14 [etd 3:05] .16
##  [etd 3:04] .18 [etd 3:00] .20 [etd 2:57] .22 [etd 2:57] .24
##  [etd 2:56] .26 [etd 2:54] .28 [etd 2:52] .30 [etd 2:51] .32
##  [etd 2:50] .34 [etd 2:51] .36 [etd 2:50] .38 [etd 2:47] .40
##  [etd 2:46] .42 [etd 2:42] .44 [etd 2:39] .46 [etd 2:36] .48
##  [etd 2:33] .50 [etd 2:31] .52 [etd 2:28] .54 [etd 2:26] .56
##  [etd 2:23] .58 [etd 2:20] .60 [etd 2:18] .62 [etd 2:16] .64
##  [etd 2:13] .66 [etd 2:10] .68 [etd 2:08] .70 [etd 2:06] .72
##  [etd 2:04] .74 [etd 2:01] .76 [etd 1:59] .78 [etd 1:56] .80
##  [etd 1:55] .82 [etd 1:52] .84 [etd 1:50] .86 [etd 1:48] .88
##  [etd 1:46] .90 [etd 1:44] .92 [etd 1:42] .94 [etd 1:40] .96
##  [etd 1:38] .98 [etd 1:36] .100 [etd 1:34] .102 [etd 1:32] .104
##  [etd 1:30] .106 [etd 1:28] .108 [etd 1:26] .110 [etd 1:24] .112
##  [etd 1:22] .114 [etd 1:20] .116 [etd 1:18] .118 [etd 1:16] .120
##  [etd 1:14] .122 [etd 1:12] .124 [etd 1:10] .126 [etd 1:09] .128
##  [etd 1:07] .130 [etd 1:05] .132 [etd 1:03] .134 [etd 1:01] .136
##  [etd 59 sec] .138 [etd 57 sec] .140 [etd 55 sec] .142 [etd 53 sec] .144
##  [etd 51 sec] .146 [etd 50 sec] .148 [etd 48 sec] .150 [etd 46 sec] .152
##  [etd 44 sec] .154 [etd 42 sec] .156 [etd 40 sec] .158 [etd 38 sec] .160
##  [etd 36 sec] .162 [etd 34 sec] .164 [etd 32 sec] .166 [etd 31 sec] .168
##  [etd 29 sec] .170 [etd 27 sec] .172 [etd 25 sec] .174 [etd 23 sec] .176
##  [etd 21 sec] .178 [etd 19 sec] .180 [etd 18 sec] .182 [etd 16 sec] .184
##  [etd 14 sec] .186 [etd 12 sec] .188 [etd 10 sec] .190 [etd 8 sec] .192
##  [etd 6 sec] .194 [etd 5 sec] .196 [etd 3 sec] .198 [etd 1 sec]  199.
## 
## Done.

This code chunk will plot the G_Kindergarten.csr

plot(G_Kindergarten.csr)

Observation: Based on the shape of G-function for G_Kindergarten.csr, it can conclude that event of the kindergarten spatial points patterns are clustered since the estimated G(r) lies above the upper envelope and it is statistically significant. Therefore, this result is in align with the previous spatial point pattern analysis test results. Since both the 1st order and 2nd order spatial point pattern analysis tests indicate that the point pattern of the kindergarten services are clustered, we can safely say that the kindergarten services are relatively clustered to one another.

6.9 Conclusion

Conclusion on 1st order and 2nd order analysis:

Based on the results of 1st order and 2nd order spatial analysis, we can conclude that both the childcare and kindergarten services spatial point patterns events are clustered and the hypothesis results showed that p-value is smaller than the significance level of 0.05. Therefore, the null hypothesis of the childcare and kindergarten’s point patterns are randomly distributed can be rejected since there are strong evidences that the distribution of childcare and kindergarten services are not randomly distributed.*

7. Kernel Density Estimation Map

In this step, we will compute the kernel density estimation of childcare and kindergarten services in Singapore. The main goal of Kernel density estimation is to analyze the intensity of the point distribution to determine whether the area has high intensity or concentration in comparison to other areas. The following will be used to compute the kernel density of the map.

  • density() of spastat to compute a kernel density
  • bw.diggle() to select bandwidth
  • gaussian is used as smoothing kernel

7.1. Rescale from M to KM.

This code chunk will rescale from meter to km using rescale() function so that the unit of measurement is converted to kilometer from meter which is the default unit measurement of SVY21.

childcareSG_ppp.km <- rescale(childcareSG_ppp, 1000, "km")

kindergartenSG_ppp.km <- rescale(kindergarten_ppp, 1000, "km")

7.2. Compute kernel density

This code chunk will compute the density using the density() function and rescaled dataset to plot the output of childcare kde map.

kde_childcareSG.bw <- density(childcareSG_ppp.km, sigma=bw.ppl, edge=TRUE, kernel="gaussian")

plot(kde_childcareSG.bw, main = "bw.ppl")

This code chunk will compute the density using the density() function and rescaled dataset to plot the output of kindergarten kde map.

kde_kindergartenSG.bw <- density(kindergartenSG_ppp.km, sigma=bw.ppl, edge=TRUE, kernel="gaussian")

plot(kde_kindergartenSG.bw, main = "bw.ppl")

7.3. Converting KDE output into grid object.

This code chunk will convert KDE output of kde_childcareSG.bw into grid object.

gridded_kde_childcareSG_bw <- as.SpatialGridDataFrame.im(kde_childcareSG.bw)
spplot(gridded_kde_childcareSG_bw)

This code chunk will convert KDE output of kde_kindergartenSG.bw into grid object.

gridded_kde_kindergartenSG_bw <- as.SpatialGridDataFrame.im(kde_kindergartenSG.bw)
spplot(gridded_kde_kindergartenSG_bw)

7.4. Converting gridded output into raster

This code chunk will convert the gridded kernel density object, gridded_kde_childcareSG_bw into RasterLayer object by using raster() of raster package.

kde_childcareSG_bw_raster <- raster(gridded_kde_childcareSG_bw)

This code chunk will check the properties of kde_childcareSG_bw_raster.

kde_childcareSG_bw_raster
## class      : RasterLayer 
## dimensions : 128, 128, 16384  (nrow, ncol, ncell)
## resolution : 0.419757, 0.2695907  (x, y)
## extent     : 2.667538, 56.39644, 15.74872, 50.25633  (xmin, xmax, ymin, ymax)
## crs        : NA 
## source     : memory
## names      : v 
## values     : -9.493063e-15, 33.55138  (min, max)

Observation: based on the output, it can see that CRS is property is shown as NA. Therefore, the projection need to be change to complete the CRS property.

This code chunk will convert the gridded kernel density object, gridded_kde_kindergartenSG_bw into RasterLayer object by using raster() of raster package.

kde_kindergartenSG_bw_raster <- raster(gridded_kde_kindergartenSG_bw)

This code chunk will check the properties of kde_kindergartenSG_bw_raster

kde_kindergartenSG_bw_raster
## class      : RasterLayer 
## dimensions : 128, 128, 16384  (nrow, ncol, ncell)
## resolution : 0.2459826, 0.1794197  (x, y)
## extent     : 11.9097, 43.39547, 25.59633, 48.56206  (xmin, xmax, ymin, ymax)
## crs        : NA 
## source     : memory
## names      : v 
## values     : -7.431237e-16, 9.402008  (min, max)

Observation: based on the output, it can see that CRS is property is shown as NA. Therefore, the projection need to be change to complete the CRS property.

7.5. Assigning projection systems

Based on the above result, we are required to include the CRS information kde_childcareSG_bw_raster on and kde_kindergartenSG_bw_raster.

This code chunk will include the CRS information on kde_childcareSG_bw_raster RasterLayer.

projection(kde_childcareSG_bw_raster) <- CRS("+init=EPSG:3414 +datum=WGS84 +units=km")

kde_childcareSG_bw_raster
## class      : RasterLayer 
## dimensions : 128, 128, 16384  (nrow, ncol, ncell)
## resolution : 0.419757, 0.2695907  (x, y)
## extent     : 2.667538, 56.39644, 15.74872, 50.25633  (xmin, xmax, ymin, ymax)
## crs        : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +datum=WGS84 +units=km +no_defs 
## source     : memory
## names      : v 
## values     : -9.493063e-15, 33.55138  (min, max)

This code chunk will include the CRS information on kde_kindergartenSG_bw_raster RasterLayer.

projection(kde_kindergartenSG_bw_raster) <- CRS("+init=EPSG:3414 +datum=WGS84 +units=km")

kde_kindergartenSG_bw_raster
## class      : RasterLayer 
## dimensions : 128, 128, 16384  (nrow, ncol, ncell)
## resolution : 0.2459826, 0.1794197  (x, y)
## extent     : 11.9097, 43.39547, 25.59633, 48.56206  (xmin, xmax, ymin, ymax)
## crs        : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +datum=WGS84 +units=km +no_defs 
## source     : memory
## names      : v 
## values     : -7.431237e-16, 9.402008  (min, max)

7.6. Visualizing the output in OpenStreet Map

This code chunk will display the raster in cartographic quality map using tmap package.

tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(kde_childcareSG_bw_raster) + 
  tm_raster("v", palette = "Reds", title = "Childcare Kernel Density", alpha = 0.5) +
  tmap_options(basemaps = c('OpenStreetMap'))
tm_shape(kde_childcareSG_bw_raster) + 
  tm_raster("v", palette = "Reds", title = "Kindergarten Kernel Density", 
            alpha = 0.5) +
  tmap_options(basemaps = c('OpenStreetMap'))

Observation: Based on the plot, we can see that kindergarten and childcare services are clustered together. The result is consistent to what we have found in the 1st order and 2nd order point pattern analysis tests that the area of kindergarten and childcare services are clustered on their own. By plotting on the opernstreetmap, it is more obvious to see that clusters are forming in residential area and where there are no cluster in certain area of the subzone where the residents do not live.

tmap_mode("plot")
## tmap mode set to plotting

7.7. Advantage of Kernel Density Map over Point Map

Firstly, we can see that the kernel density maps show the intensity of the occurrence of the point events and the color are more intense compare to the point map whereby the color are more simple. Moreover, KDE allows us to plot the map on the openstreetmap where we can see and visualize the exact location of the subzone and buildings which are more visually appealing to us compare to points and polygons.