1. Introduction

This project analyses the spatial distribution of crime incidents in New York City using spatial point pattern analysis. Each crime incident is represented as a point in space using its geographical coordinates.

The aim is to compare crime patterns between 2012 and 2025 and investigate whether crime incidents are randomly distributed or clustered in specific areas.

2. Literature review

Spatial point pattern analysis is widely used in geography, criminology and urban studies to analyse the spatial distribution of events. In crime studies, these methods help identify whether criminal incidents are randomly distributed or concentrated in specific areas of a city.

Previous research has shown that crime often forms spatial clusters, commonly known as hotspots. These concentrations are usually related to urban and socio-economic factors such as population density, commercial activity and transportation networks.

Methods such as kernel density estimation and Ripley’s K function are commonly applied to study spatial clustering and compare observed patterns with Complete Spatial Randomness (CSR).

3. Packages

requiredPackages = c("sf", "spatstat", "ggplot2", "dplyr")

for(i in requiredPackages){
  if(!require(i, character.only = TRUE)) install.packages(i)
}

for(i in requiredPackages){
  library(i, character.only = TRUE)
}

Sys.setenv(LANG="en")

4. Filtering and preparing data for New York City

The crime data come from the NYPD Complaint Data Historic dataset. For this analysis, only observations with latitude and longitude are used. The data are filtered into two separate years: 2012 and 2025.

# NYC borough map
nyc_map <- st_read(
  "https://raw.githubusercontent.com/dwillis/nyc-maps/master/boroughs.geojson",
  quiet = TRUE
)

nyc_map <- st_make_valid(nyc_map)

# Function to download crime data by year
download_crime_year <- function(year, limit = 700) {
  
  start_date <- paste0(year, "-01-01T00:00:00")
  end_date <- paste0(year, "-12-31T23:59:59")
  
  where_query <- paste0(
    "latitude IS NOT NULL AND longitude IS NOT NULL ",
    "AND cmplnt_fr_dt between '", start_date, "' and '", end_date, "'"
  )
  
  url <- paste0(
    "https://data.cityofnewyork.us/resource/qgea-i56i.csv?",
    "$limit=", limit,
    "&$select=cmplnt_fr_dt,ofns_desc,boro_nm,latitude,longitude",
    "&$where=", URLencode(where_query, reserved = TRUE)
  )
  
  read.csv(url)
}

crime_2012 <- download_crime_year(2012)
crime_2025 <- download_crime_year(2025)

nrow(crime_2012)
## [1] 700
nrow(crime_2025)
## [1] 700

The dataset is downloaded directly from NYC Open Data. The variables used are the date of the complaint, type of offence, borough, latitude and longitude. The coordinates allow each crime incident to be treated as a spatial point.

5. Creating spatial objects

Following the structure used in class, the data frame is converted into an sf object using st_as_sf(). Then, both the points and the New York City boundary are transformed into a projected coordinate system.

crime_2012_sf <- st_as_sf(
  crime_2012,
  coords = c("longitude", "latitude"),
  crs = 4326
)

crime_2025_sf <- st_as_sf(
  crime_2025,
  coords = c("longitude", "latitude"),
  crs = 4326
)

# Transform to planar projection
nyc_map_proj <- st_transform(nyc_map, crs = 3857)
crime_2012_proj <- st_transform(crime_2012_sf, crs = 3857)
crime_2025_proj <- st_transform(crime_2025_sf, crs = 3857)

# Keep only points inside New York City
crime_2012_proj <- st_intersection(crime_2012_proj, nyc_map_proj)
crime_2025_proj <- st_intersection(crime_2025_proj, nyc_map_proj)

This step follows the same logic used in class: the original coordinate system is geographic, so the data are transformed into a projected coordinate system before distance-based analysis.

6. Study area

plot(st_geometry(nyc_map_proj),
     main = "Study area: New York City",
     col = "gray90",
     border = "black")

The study area is New York City, formed by five boroughs: Manhattan, Brooklyn, Queens, The Bronx and Staten Island.

7. Visualisation of crime incidents

plot(st_geometry(nyc_map_proj),
     main = "Crime incidents in New York City, 2012",
     col = "white",
     border = "black")

plot(st_geometry(crime_2012_proj),
     add = TRUE,
     col = "blue",
     pch = 16,
     cex = 0.4)

plot(st_geometry(nyc_map_proj),
     main = "Crime incidents in New York City, 2025",
     col = "white",
     border = "black")

plot(st_geometry(crime_2025_proj),
     add = TRUE,
     col = "red",
     pch = 16,
     cex = 0.4)

Each point represents one reported crime incident. The maps provide a first visual comparison between the spatial distribution of crimes in 2012 and 2025.

8. Crime distribution by borough

boro_2012 <- crime_2012 %>%
  count(boro_nm)

boro_2025 <- crime_2025 %>%
  count(boro_nm)

ggplot(boro_2012,
       aes(x = reorder(boro_nm, n), y = n, fill = boro_nm)) +
  geom_bar(stat = "identity") +
  coord_flip() +
  labs(title = "Crime incidents by borough, 2012",
       x = "Borough",
       y = "Number of crimes") +
  theme_minimal() +
  theme(legend.position = "none")

ggplot(boro_2025,
       aes(x = reorder(boro_nm, n), y = n, fill = boro_nm)) +
  geom_bar(stat = "identity") +
  coord_flip() +
  labs(title = "Crime incidents by borough, 2025",
       x = "Borough",
       y = "Number of crimes") +
  theme_minimal() +
  theme(legend.position = "none")

This section adds a simple quantitative and socio-economic interpretation. Differences between boroughs may reflect population density, commercial activity, tourism and other urban characteristics.

9. Creating point pattern objects

The sf points are converted into ppp objects, following the approach used in class. The observation window is created from the New York City boundary using as.owin().

# Create observation window
W <- as.owin(nyc_map_proj)

# Extract coordinates
xy_2012 <- st_coordinates(crime_2012_proj)
xy_2025 <- st_coordinates(crime_2025_proj)

# Create ppp objects
ppp_2012 <- ppp(
  x = xy_2012[,1],
  y = xy_2012[,2],
  window = W
)

ppp_2025 <- ppp(
  x = xy_2025[,1],
  y = xy_2025[,2],
  window = W
)

# Remove duplicated points if necessary
ppp_2012 <- unique(ppp_2012)
ppp_2025 <- unique(ppp_2025)

summary(ppp_2012)
## Planar point pattern:  350 points
## Average intensity 2.558407e-07 points per square unit
## 
## Coordinates are given to 9 decimal places
## 
## Window: polygonal boundary
## 64 separate polygons (1 hole)
##                   vertices         area relative.area
## polygon 1               21  1.71662e+04      1.25e-05
## polygon 2             5101  9.58781e+07      7.01e-02
## polygon 3                4  8.05116e+02      5.89e-07
## polygon 4                5  1.47236e+03      1.08e-06
## polygon 5               15  4.95573e+03      3.62e-06
## polygon 6                5  7.95246e+02      5.81e-07
## polygon 7                7  1.74311e+03      1.27e-06
## polygon 8                5  3.34093e+04      2.44e-05
## polygon 9                4  8.46849e+03      6.19e-06
## polygon 10               4  2.67616e+03      1.96e-06
## polygon 11             136  8.12964e+03      5.94e-06
## polygon 12             106  3.12758e+03      2.29e-06
## polygon 13             128  3.62314e+03      2.65e-06
## polygon 14               4  4.37037e+03      3.19e-06
## polygon 15             190  4.91014e+04      3.59e-05
## polygon 16              96  7.81569e+05      5.71e-04
## polygon 17            1400  1.94910e+06      1.42e-03
## polygon 18               5  1.46725e+04      1.07e-05
## polygon 19               5  1.26636e+04      9.26e-06
## polygon 20               7  8.81355e+04      6.44e-05
## polygon 21               4  1.30235e+04      9.52e-06
## polygon 22              11  1.11055e+05      8.12e-05
## polygon 23             243  3.80942e+06      2.78e-03
## polygon 24              11  3.86041e+04      2.82e-05
## polygon 25             508  2.94551e+06      2.15e-03
## polygon 26              29  1.88748e+04      1.38e-05
## polygon 27             144  1.02374e+06      7.48e-04
## polygon 28              17  1.33687e+03      9.77e-07
## polygon 29              29  1.94843e+05      1.42e-04
## polygon 30             279  1.25032e+06      9.14e-04
## polygon 31              47  1.03542e+05      7.57e-05
## polygon 32              15  1.61910e+03      1.18e-06
## polygon 33           30898  7.50536e+08      5.49e-01
## polygon 34            8909  2.61582e+08      1.91e-01
## polygon 35              57  1.24307e+05      9.09e-05
## polygon 36            1438  7.93930e+06      5.80e-03
## polygon 37               7  1.28578e+06      9.40e-04
## polygon 38               5  5.64214e+05      4.12e-04
## polygon 39              30  6.70779e+05      4.90e-04
## polygon 40              30  1.97498e+06      1.44e-03
## polygon 41               7  1.48721e+06      1.09e-03
## polygon 42              31  1.43027e+06      1.05e-03
## polygon 43 (hole)        9 -1.94339e+03     -1.42e-06
## polygon 44               6  4.09039e+05      2.99e-04
## polygon 45              15  1.56820e+06      1.15e-03
## polygon 46              15  9.70082e+05      7.09e-04
## polygon 47            9432  3.66054e+07      2.68e-02
## polygon 48               9  1.30499e+05      9.54e-05
## polygon 49              12  3.03573e+05      2.22e-04
## polygon 50              17  8.87032e+05      6.48e-04
## polygon 51               5  3.32429e+04      2.43e-05
## polygon 52               4  2.17558e+04      1.59e-05
## polygon 53              12  6.41352e+04      4.69e-05
## polygon 54             105  3.29170e+05      2.41e-04
## polygon 55               5  1.37126e+04      1.00e-05
## polygon 56              38  9.10120e+05      6.65e-04
## polygon 57               4  3.08903e+04      2.26e-05
## polygon 58            1659  5.69806e+05      4.17e-04
## polygon 59               3  9.20719e+03      6.73e-06
## polygon 60             405  6.50783e+05      4.76e-04
## polygon 61              46  1.11728e+06      8.17e-04
## polygon 62               8  8.18035e+04      5.98e-05
## polygon 63              46  2.06765e+04      1.51e-05
## polygon 64            6155  1.87344e+08      1.37e-01
## enclosing rectangle: [-8266095, -8204247] x [4938301, 4999891] units
##                      (61850 x 61590 units)
## Window area = 1368040000 square units
## Fraction of frame area: 0.359
summary(ppp_2025)
## Planar point pattern:  623 points
## Average intensity 4.553964e-07 points per square unit
## 
## Coordinates are given to 9 decimal places
## 
## Window: polygonal boundary
## 64 separate polygons (1 hole)
##                   vertices         area relative.area
## polygon 1               21  1.71662e+04      1.25e-05
## polygon 2             5101  9.58781e+07      7.01e-02
## polygon 3                4  8.05116e+02      5.89e-07
## polygon 4                5  1.47236e+03      1.08e-06
## polygon 5               15  4.95573e+03      3.62e-06
## polygon 6                5  7.95246e+02      5.81e-07
## polygon 7                7  1.74311e+03      1.27e-06
## polygon 8                5  3.34093e+04      2.44e-05
## polygon 9                4  8.46849e+03      6.19e-06
## polygon 10               4  2.67616e+03      1.96e-06
## polygon 11             136  8.12964e+03      5.94e-06
## polygon 12             106  3.12758e+03      2.29e-06
## polygon 13             128  3.62314e+03      2.65e-06
## polygon 14               4  4.37037e+03      3.19e-06
## polygon 15             190  4.91014e+04      3.59e-05
## polygon 16              96  7.81569e+05      5.71e-04
## polygon 17            1400  1.94910e+06      1.42e-03
## polygon 18               5  1.46725e+04      1.07e-05
## polygon 19               5  1.26636e+04      9.26e-06
## polygon 20               7  8.81355e+04      6.44e-05
## polygon 21               4  1.30235e+04      9.52e-06
## polygon 22              11  1.11055e+05      8.12e-05
## polygon 23             243  3.80942e+06      2.78e-03
## polygon 24              11  3.86041e+04      2.82e-05
## polygon 25             508  2.94551e+06      2.15e-03
## polygon 26              29  1.88748e+04      1.38e-05
## polygon 27             144  1.02374e+06      7.48e-04
## polygon 28              17  1.33687e+03      9.77e-07
## polygon 29              29  1.94843e+05      1.42e-04
## polygon 30             279  1.25032e+06      9.14e-04
## polygon 31              47  1.03542e+05      7.57e-05
## polygon 32              15  1.61910e+03      1.18e-06
## polygon 33           30898  7.50536e+08      5.49e-01
## polygon 34            8909  2.61582e+08      1.91e-01
## polygon 35              57  1.24307e+05      9.09e-05
## polygon 36            1438  7.93930e+06      5.80e-03
## polygon 37               7  1.28578e+06      9.40e-04
## polygon 38               5  5.64214e+05      4.12e-04
## polygon 39              30  6.70779e+05      4.90e-04
## polygon 40              30  1.97498e+06      1.44e-03
## polygon 41               7  1.48721e+06      1.09e-03
## polygon 42              31  1.43027e+06      1.05e-03
## polygon 43 (hole)        9 -1.94339e+03     -1.42e-06
## polygon 44               6  4.09039e+05      2.99e-04
## polygon 45              15  1.56820e+06      1.15e-03
## polygon 46              15  9.70082e+05      7.09e-04
## polygon 47            9432  3.66054e+07      2.68e-02
## polygon 48               9  1.30499e+05      9.54e-05
## polygon 49              12  3.03573e+05      2.22e-04
## polygon 50              17  8.87032e+05      6.48e-04
## polygon 51               5  3.32429e+04      2.43e-05
## polygon 52               4  2.17558e+04      1.59e-05
## polygon 53              12  6.41352e+04      4.69e-05
## polygon 54             105  3.29170e+05      2.41e-04
## polygon 55               5  1.37126e+04      1.00e-05
## polygon 56              38  9.10120e+05      6.65e-04
## polygon 57               4  3.08903e+04      2.26e-05
## polygon 58            1659  5.69806e+05      4.17e-04
## polygon 59               3  9.20719e+03      6.73e-06
## polygon 60             405  6.50783e+05      4.76e-04
## polygon 61              46  1.11728e+06      8.17e-04
## polygon 62               8  8.18035e+04      5.98e-05
## polygon 63              46  2.06765e+04      1.51e-05
## polygon 64            6155  1.87344e+08      1.37e-01
## enclosing rectangle: [-8266095, -8204247] x [4938301, 4999891] units
##                      (61850 x 61590 units)
## Window area = 1368040000 square units
## Fraction of frame area: 0.359

The ppp object is the main structure used in spatstat for point pattern analysis. It contains the coordinates of the events and the observation window.

10. Rescaling

As in the class scripts, the point patterns are rescaled to make distances easier to interpret.

area.owin(W)
## [1] 1368038987
# Rescale from metres to kilometres
ppp_2012_km <- rescale(ppp_2012, 1000, "km")
ppp_2025_km <- rescale(ppp_2025, 1000, "km")

summary(ppp_2012_km)
## Planar point pattern:  350 points
## Average intensity 0.2558407 points per square km
## 
## Coordinates are given to 12 decimal places
## 
## Window: polygonal boundary
## 64 separate polygons (1 hole)
##                   vertices         area relative.area
## polygon 1               21  1.71662e-02      1.25e-05
## polygon 2             5101  9.58781e+01      7.01e-02
## polygon 3                4  8.05116e-04      5.89e-07
## polygon 4                5  1.47236e-03      1.08e-06
## polygon 5               15  4.95573e-03      3.62e-06
## polygon 6                5  7.95246e-04      5.81e-07
## polygon 7                7  1.74311e-03      1.27e-06
## polygon 8                5  3.34093e-02      2.44e-05
## polygon 9                4  8.46849e-03      6.19e-06
## polygon 10               4  2.67616e-03      1.96e-06
## polygon 11             136  8.12964e-03      5.94e-06
## polygon 12             106  3.12758e-03      2.29e-06
## polygon 13             128  3.62314e-03      2.65e-06
## polygon 14               4  4.37037e-03      3.19e-06
## polygon 15             190  4.91014e-02      3.59e-05
## polygon 16              96  7.81569e-01      5.71e-04
## polygon 17            1400  1.94910e+00      1.42e-03
## polygon 18               5  1.46725e-02      1.07e-05
## polygon 19               5  1.26636e-02      9.26e-06
## polygon 20               7  8.81355e-02      6.44e-05
## polygon 21               4  1.30235e-02      9.52e-06
## polygon 22              11  1.11055e-01      8.12e-05
## polygon 23             243  3.80942e+00      2.78e-03
## polygon 24              11  3.86041e-02      2.82e-05
## polygon 25             508  2.94551e+00      2.15e-03
## polygon 26              29  1.88748e-02      1.38e-05
## polygon 27             144  1.02374e+00      7.48e-04
## polygon 28              17  1.33687e-03      9.77e-07
## polygon 29              29  1.94843e-01      1.42e-04
## polygon 30             279  1.25032e+00      9.14e-04
## polygon 31              47  1.03542e-01      7.57e-05
## polygon 32              15  1.61910e-03      1.18e-06
## polygon 33           30898  7.50536e+02      5.49e-01
## polygon 34            8909  2.61582e+02      1.91e-01
## polygon 35              57  1.24307e-01      9.09e-05
## polygon 36            1438  7.93930e+00      5.80e-03
## polygon 37               7  1.28578e+00      9.40e-04
## polygon 38               5  5.64214e-01      4.12e-04
## polygon 39              30  6.70779e-01      4.90e-04
## polygon 40              30  1.97498e+00      1.44e-03
## polygon 41               7  1.48721e+00      1.09e-03
## polygon 42              31  1.43027e+00      1.05e-03
## polygon 43 (hole)        9 -1.94339e-03     -1.42e-06
## polygon 44               6  4.09039e-01      2.99e-04
## polygon 45              15  1.56820e+00      1.15e-03
## polygon 46              15  9.70082e-01      7.09e-04
## polygon 47            9432  3.66054e+01      2.68e-02
## polygon 48               9  1.30499e-01      9.54e-05
## polygon 49              12  3.03573e-01      2.22e-04
## polygon 50              17  8.87032e-01      6.48e-04
## polygon 51               5  3.32429e-02      2.43e-05
## polygon 52               4  2.17558e-02      1.59e-05
## polygon 53              12  6.41352e-02      4.69e-05
## polygon 54             105  3.29170e-01      2.41e-04
## polygon 55               5  1.37126e-02      1.00e-05
## polygon 56              38  9.10120e-01      6.65e-04
## polygon 57               4  3.08903e-02      2.26e-05
## polygon 58            1659  5.69806e-01      4.17e-04
## polygon 59               3  9.20719e-03      6.73e-06
## polygon 60             405  6.50783e-01      4.76e-04
## polygon 61              46  1.11728e+00      8.17e-04
## polygon 62               8  8.18035e-02      5.98e-05
## polygon 63              46  2.06765e-02      1.51e-05
## polygon 64            6155  1.87344e+02      1.37e-01
## enclosing rectangle: [-8266.095, -8204.247] x [4938.301, 4999.891] km
##                      (61.85 x 61.59 km)
## Window area = 1368.04 square km
## Unit of length: 1 km
## Fraction of frame area: 0.359
summary(ppp_2025_km)
## Planar point pattern:  623 points
## Average intensity 0.4553964 points per square km
## 
## Coordinates are given to 12 decimal places
## 
## Window: polygonal boundary
## 64 separate polygons (1 hole)
##                   vertices         area relative.area
## polygon 1               21  1.71662e-02      1.25e-05
## polygon 2             5101  9.58781e+01      7.01e-02
## polygon 3                4  8.05116e-04      5.89e-07
## polygon 4                5  1.47236e-03      1.08e-06
## polygon 5               15  4.95573e-03      3.62e-06
## polygon 6                5  7.95246e-04      5.81e-07
## polygon 7                7  1.74311e-03      1.27e-06
## polygon 8                5  3.34093e-02      2.44e-05
## polygon 9                4  8.46849e-03      6.19e-06
## polygon 10               4  2.67616e-03      1.96e-06
## polygon 11             136  8.12964e-03      5.94e-06
## polygon 12             106  3.12758e-03      2.29e-06
## polygon 13             128  3.62314e-03      2.65e-06
## polygon 14               4  4.37037e-03      3.19e-06
## polygon 15             190  4.91014e-02      3.59e-05
## polygon 16              96  7.81569e-01      5.71e-04
## polygon 17            1400  1.94910e+00      1.42e-03
## polygon 18               5  1.46725e-02      1.07e-05
## polygon 19               5  1.26636e-02      9.26e-06
## polygon 20               7  8.81355e-02      6.44e-05
## polygon 21               4  1.30235e-02      9.52e-06
## polygon 22              11  1.11055e-01      8.12e-05
## polygon 23             243  3.80942e+00      2.78e-03
## polygon 24              11  3.86041e-02      2.82e-05
## polygon 25             508  2.94551e+00      2.15e-03
## polygon 26              29  1.88748e-02      1.38e-05
## polygon 27             144  1.02374e+00      7.48e-04
## polygon 28              17  1.33687e-03      9.77e-07
## polygon 29              29  1.94843e-01      1.42e-04
## polygon 30             279  1.25032e+00      9.14e-04
## polygon 31              47  1.03542e-01      7.57e-05
## polygon 32              15  1.61910e-03      1.18e-06
## polygon 33           30898  7.50536e+02      5.49e-01
## polygon 34            8909  2.61582e+02      1.91e-01
## polygon 35              57  1.24307e-01      9.09e-05
## polygon 36            1438  7.93930e+00      5.80e-03
## polygon 37               7  1.28578e+00      9.40e-04
## polygon 38               5  5.64214e-01      4.12e-04
## polygon 39              30  6.70779e-01      4.90e-04
## polygon 40              30  1.97498e+00      1.44e-03
## polygon 41               7  1.48721e+00      1.09e-03
## polygon 42              31  1.43027e+00      1.05e-03
## polygon 43 (hole)        9 -1.94339e-03     -1.42e-06
## polygon 44               6  4.09039e-01      2.99e-04
## polygon 45              15  1.56820e+00      1.15e-03
## polygon 46              15  9.70082e-01      7.09e-04
## polygon 47            9432  3.66054e+01      2.68e-02
## polygon 48               9  1.30499e-01      9.54e-05
## polygon 49              12  3.03573e-01      2.22e-04
## polygon 50              17  8.87032e-01      6.48e-04
## polygon 51               5  3.32429e-02      2.43e-05
## polygon 52               4  2.17558e-02      1.59e-05
## polygon 53              12  6.41352e-02      4.69e-05
## polygon 54             105  3.29170e-01      2.41e-04
## polygon 55               5  1.37126e-02      1.00e-05
## polygon 56              38  9.10120e-01      6.65e-04
## polygon 57               4  3.08903e-02      2.26e-05
## polygon 58            1659  5.69806e-01      4.17e-04
## polygon 59               3  9.20719e-03      6.73e-06
## polygon 60             405  6.50783e-01      4.76e-04
## polygon 61              46  1.11728e+00      8.17e-04
## polygon 62               8  8.18035e-02      5.98e-05
## polygon 63              46  2.06765e-02      1.51e-05
## polygon 64            6155  1.87344e+02      1.37e-01
## enclosing rectangle: [-8266.095, -8204.247] x [4938.301, 4999.891] km
##                      (61.85 x 61.59 km)
## Window area = 1368.04 square km
## Unit of length: 1 km
## Fraction of frame area: 0.359

Rescaling allows the analysis to be interpreted in kilometres instead of metres.

11. Kernel density estimation

density_2012 <- density(ppp_2012_km, sigma = 1)

plot(density_2012,
     main = "Kernel density of crime incidents, 2012")

points(ppp_2012_km,
       pch = 16,
       cex = 0.2)

density_2025 <- density(ppp_2025_km, sigma = 1)

plot(density_2025,
     main = "Kernel density of crime incidents, 2025")

points(ppp_2025_km,
       pch = 16,
       cex = 0.2)

Kernel density estimation identifies areas with higher concentrations of crime incidents. These areas can be interpreted as crime hotspots.

12. Nearest neighbour distances

nn_2012 <- nndist(ppp_2012_km)
nn_2025 <- nndist(ppp_2025_km)

summary(nn_2012)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.02169 0.42615 0.66350 0.86054 1.12995 5.04776
summary(nn_2025)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## 0.004503 0.244618 0.400617 0.581354 0.651926 6.559123
hist(nn_2012,
     main = "Nearest neighbour distances, 2012",
     xlab = "Distance in km",
     col = "lightblue")

hist(nn_2025,
     main = "Nearest neighbour distances, 2025",
     xlab = "Distance in km",
     col = "lightcoral")

Nearest neighbour distances measure how close each crime incident is to its closest neighbouring event. Shorter distances suggest stronger clustering.

13. Ripley’s K function

K_2012 <- Kest(ppp_2012_km)

plot(K_2012,
     main = "Ripley's K function, 2012")

K_2025 <- Kest(ppp_2025_km)

plot(K_2025,
     main = "Ripley's K function, 2025")

Ripley’s K function analyses clustering at different distance scales. If the observed curve is above the theoretical CSR curve, this suggests clustering.

16. Conclusions

This project analysed the spatial distribution of crime incidents in New York City using point pattern analysis. The comparison between 2012 and 2025 showed how crime incidents are distributed across the city and whether they tend to cluster in specific areas.

The visual maps and kernel density estimations suggest that crime is not evenly distributed across New York City. Instead, crime incidents tend to concentrate in certain areas, forming spatial hotspots.

Nearest neighbour distances and Ripley’s K function provide additional quantitative evidence about the spatial structure of the pattern. The simulation envelopes allow comparison with Complete Spatial Randomness.

From a socio-economic perspective, the spatial concentration of crime may reflect urban factors such as population density, commercial activity, tourism, transportation hubs and social inequality. Therefore, spatial crime analysis can provide useful information for urban planning, public safety policies and resource allocation.