FROM: PPIC Blog, October 2022, FROM: PPIC Blog, October 2022

Introduction The data set “US Estimated Crimes” was provided by Bojan Tunguz on Kaggle offers a comprehensive look into crime trends within the United States between 1979 to 2019. Their data was sourced from the Summary Reporting System, which is the same system the FBI utilizes for their annual publications.

My exploration will primarily focus on analyzing data from 2013 onward, which coincides with a significant alteration in the FBI’s reporting methodology. In 2013, the FBI revised their definition of rape as acts committed “forcibly” and “without consent,” which reflects societies improved understanding of sexual violence. However, the data set lacks specific details regarding the data collection process from individual law enforcement agencies.

My interest in this topic is motivated by a desire to gain deeper insights into potential patterns in crime within the DMV area. I’m aiming to identify anything that could improve crime prevention and overall societal safety.

Explaining the Variables Before beginning, I will provide an display the variables being explored.

year = Year state_abbr = State Abbreviation state_name = State Name population = Population violent_crime = Violent Crime homicide = Homicide rape_revised = Rape, specifically under the new changes of FBI’s reporting methodology robbery = Robbery aggravated_assault = Aggravated Assault property_crime = Property Crime burglary = Burglary larceny = Larceny motor_vehicle_theft = Motor Vehicle Theft

I’m choosing to remove the rape_legacy variable to keep the exploration consistent and focused on the data provided after the methodology update.

Preparation

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(RColorBrewer)
library(treemap)
Orig_Crime <- readr::read_csv("estimated_crimes_1979_2019.csv")
## Rows: 2116 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (3): state_abbr, state_name, caveats
## dbl (12): year, population, violent_crime, homicide, rape_legacy, rape_revis...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Filtering the Data

Crime1 <- Orig_Crime |>
  filter(year>= 2013 & year<= 2019) |>
  filter(state_abbr %in% c("MD", "VA", "DC")) |>
  select(-rape_legacy, -caveats)

In this chunk, I used the filter commands to only include data between 2013-2019 and to only include the states within the DMV area. The select command was used to remove the rape_legacy column, which contained data prior to the FBI’s update. It was also used to remove the caveat column that was completely blank for the data I selected.

Modifying the Data

CrimeRate <- Crime1 |>
  mutate("Violent Crime Rate" = violent_crime / population,
         "Homicide Rate" = homicide / population,
         "Rape Revised Rate" = rape_revised / population,
         "Robbery Rate" = robbery / population,
         "Aggravated Assault Rate" = aggravated_assault / population,
         "Property Crime Rate" = property_crime / population,
         "Burglary Rate" = burglary / population,
         "Larceny Rate" = larceny / population,
         "Motor Vehicle Theft Rate" = motor_vehicle_theft / population)

Now we have the crime rates within the DMV area. This will be used later on in the exploration.

Initial Plots To begin, lets see if the population has changed dramatically between 2013 and 2019.

PopG <- Crime1 |>
  group_by(year) |>
  summarise(Total_Population = sum(population))
Pop1 <- ggplot(PopG, aes(x = year, y = Total_Population)) +
  labs(title="United States Population in 2013-2019") +
  xlab("Year") + 
  ylab("Population")
Pop1 + geom_line()

The population in the DMV area has increased significantly since 2013. This knowledge will assist us in analyzing the data further, allowing for a more nuanced understanding of crime dynamics. For example, if we discover that the incidence and rate of crime has decreased while the population grew, that would imply that the DMV’s crime prevention methods have been effective. Unfortunately, this also means the opposite could also be true.

Crime Incidents

CIncLong <- Crime1 |>
  pivot_longer(names_to = "Categories",
               values_to = "Total",
               cols = c("violent_crime",
                        "homicide",
                        "rape_revised",
                        "robbery",
                        "aggravated_assault",
                        "burglary",
                        "larceny",
                        "motor_vehicle_theft"))

In this chunk, I have used the pivot_longer command to convert the data into a long format. This will make it easier to plot the data over time and assist us in identifing any trends or patterns.

CRL1 <- ggplot(CIncLong, aes(x=year, y=Total)) +
  geom_line(aes(group = Categories, color = Categories), stat = 'summary', size = 2) +
  labs(title = "DMV Crime Between 2013 and 2019") +
  labs(subtitle = "Source: Summary Reporting System") +
  ylab("Total Incidents") +
  scale_color_brewer(palette = "Dark2", name = "Categories")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
CRL1
## No summary function supplied, defaulting to `mean_se()`

Final1 <- ggplotly(CRL1)
## No summary function supplied, defaulting to `mean_se()`
Final1

While we can immediately see the significant decrease in larceny and burglary, it would be difficult to discern whether the other crimes have increased or decreased. However, the “plotly” command allows us to see the total number of crime incidences for each year. While a majority of crimes have decreased between 2013 and 2019, I was surprised to learn that homicide has actually increased. This currently implies an overall positive effect on total incidences for all crimes except for homicide.

Crime Rate In the following chunks, I am repeating the same steps, but now for the rate of crimes instead of the total number of incidents.

CRateLong <- CrimeRate |>
  pivot_longer(names_to = "Categories",
               values_to = "Rate",
               cols = c("Violent Crime Rate",
                        "Homicide Rate",
                        "Rape Revised Rate",
                        "Robbery Rate",
                        "Aggravated Assault Rate",
                        "Burglary Rate",
                        "Larceny Rate",
                        "Motor Vehicle Theft Rate"))
CRL2 <- ggplot(CRateLong, aes(x=year, y=Rate)) +
  geom_line(aes(group = Categories, color = Categories), stat = 'summary', size = 2) +
  labs(title = "DMV Crime Between 2013 and 2019") +
  labs(subtitle = "Source: Summary Reporting System") +
  ylab("Rate (Per Capita)") +
  scale_color_brewer(palette = "Dark2", name = "Categories")
CRL2
## No summary function supplied, defaulting to `mean_se()`

Final2 <- ggplotly(CRL2)
## No summary function supplied, defaulting to `mean_se()`
Final2

This visualization displays the rate at which each crime within the DMV area has occurred based on the change in population. Despite the total number of homicide incidences increasing, the rate has actually decreased over the 6 years. The only crime that displayed any increase was aggravated assault, but that increase was marginal. This impliees that the DMV’s crime prevention methods have an overall positive effect.

Comparison of the DMV While we are now aware of rates and total incidences, I want to compare the data from each area of the DMV.

CFin <- Crime1 |>
  mutate("Violent Crime" = violent_crime,
         "Homicide" = homicide,
         "Rape Revised" = rape_revised,
         "Robbery" = robbery,
         "Aggravated Assault" = aggravated_assault,
         "Property Crime" = property_crime,
         "Burglary" = burglary,
         "Larceny" = larceny,
         "M.V.T" = motor_vehicle_theft) |>
  pivot_longer(names_to = "Categories",
               values_to = "Total",
               cols = c("Violent Crime",
                        "Homicide",
                        "Rape Revised",
                        "Robbery",
                        "Aggravated Assault",
                        "Burglary",
                        "Larceny",
                        "M.V.T"))
Final3 <- treemap(CFin, 
                  index = c("state_name", "Categories"), 
                  vSize = "population", 
                  vColor = "Total",
                  type = "manual",
                  palette = "RdYlBu")

Final3
## $tm
##              state_name         Categories     vSize  vColor    stdErr
## 1  District of Columbia Aggravated Assault   4766647   28103   4766647
## 2  District of Columbia           Burglary   4766647   17554   4766647
## 3  District of Columbia           Homicide   4766647     948   4766647
## 4  District of Columbia            Larceny   4766647  182072   4766647
## 5  District of Columbia              M.V.T   4766647   20722   4766647
## 6  District of Columbia               <NA>  38133176  329872  38133176
## 7  District of Columbia       Rape Revised   4766647    3133   4766647
## 8  District of Columbia            Robbery   4766647   22578   4766647
## 9  District of Columbia      Violent Crime   4766647   54762   4766647
## 10             Maryland Aggravated Assault  42040191  111784  42040191
## 11             Maryland           Burglary  42040191  170646  42040191
## 12             Maryland           Homicide  42040191    3411  42040191
## 13             Maryland            Larceny  42040191  704711  42040191
## 14             Maryland              M.V.T  42040191   90765  42040191
## 15             Maryland               <NA> 336321528 1362748 336321528
## 16             Maryland       Rape Revised  42040191   12471  42040191
## 17             Maryland            Robbery  42040191   70647  42040191
## 18             Maryland      Violent Crime  42040191  198313  42040191
## 19             Virginia Aggravated Assault  58882422   69516  58882422
## 20             Virginia           Burglary  58882422  139711  58882422
## 21             Virginia           Homicide  58882422    2855  58882422
## 22             Virginia            Larceny  58882422  878917  58882422
## 23             Virginia              M.V.T  58882422   65618  58882422
## 24             Virginia               <NA> 471059376 1326242 471059376
## 25             Virginia       Rape Revised  58882422   19009  58882422
## 26             Virginia            Robbery  58882422   29618  58882422
## 27             Virginia      Violent Crime  58882422  120998  58882422
##    vColorValue level        x0        y0          w         h   color
## 1        28103     2 0.5571278 0.0000000 0.05535903 0.1018366 #B40E26
## 2        17554     2 0.6124868 0.0000000 0.05535903 0.1018366 #AA0426
## 3          948     2 0.6678458 0.0000000 0.05535903 0.1018366 #A50026
## 4       182072     2 0.7232049 0.0000000 0.05535903 0.1018366 #F46D43
## 5        20722     2 0.7785639 0.0000000 0.05535903 0.1018366 #AF0926
## 6       329872     1 0.5571278 0.0000000 0.44287223 0.1018366 #FDD181
## 7         3133     2 0.8339229 0.0000000 0.05535903 0.1018366 #A50026
## 8        22578     2 0.8892819 0.0000000 0.05535903 0.1018366 #AF0926
## 9        54762     2 0.9446410 0.0000000 0.05535903 0.1018366 #C31C26
## 10      111784     2 0.5571278 0.6631887 0.14762408 0.3368113 #DC3C2C
## 11      170646     2 0.7047518 0.6631887 0.14762408 0.3368113 #F16640
## 12        3411     2 0.8523759 0.6631887 0.14762408 0.3368113 #A50026
## 13      704711     2 0.5571278 0.3825126 0.17714889 0.2806761 #74ADD1
## 14       90765     2 0.5571278 0.1018366 0.17714889 0.2806761 #D73027
## 15     1362748     1 0.5571278 0.1018366 0.44287223 0.8981634 #313695
## 16       12471     2 0.7342767 0.2889539 0.13286167 0.3742348 #AA0426
## 17       70647     2 0.8671383 0.2889539 0.13286167 0.3742348 #C82126
## 18      198313     2 0.7342767 0.1018366 0.26572334 0.1871174 #F57949
## 19       69516     2 0.0000000 0.6250000 0.18570926 0.3750000 #C82126
## 20      139711     2 0.1857093 0.6250000 0.18570926 0.3750000 #E54E34
## 21        2855     2 0.3714185 0.6250000 0.18570926 0.3750000 #A50026
## 22      878917     2 0.0000000 0.3125000 0.22285111 0.3125000 #313695
## 23       65618     2 0.0000000 0.0000000 0.22285111 0.3125000 #C82126
## 24     1326242     1 0.0000000 0.0000000 0.55712777 1.0000000 #313695
## 25       19009     2 0.2228511 0.2083333 0.16713833 0.4166667 #AF0926
## 26       29618     2 0.3899894 0.2083333 0.16713833 0.4166667 #B40E26
## 27      120998     2 0.2228511 0.0000000 0.33427666 0.2083333 #DF422F
## 
## $type
## [1] "manual"
## 
## $vSize
## [1] "population"
## 
## $vColor
## [1] "Total"
## 
## $stdErr
## [1] "population"
## 
## $algorithm
## [1] "pivotSize"
## 
## $vpCoorX
## [1] 0.02812148 0.97187852
## 
## $vpCoorY
## [1] 0.171685 0.910315
## 
## $aspRatio
## [1] 1.788798
## 
## $range
## [1] 0e+00 9e+05
## 
## $mapping
## [1] NA NA NA
## 
## $draw
## [1] TRUE

/{r} FinalF <-ggplotly(Final3) FinalF/

Closing Thoughts My exploration into the “US Estimated Crimes” data set has provided a thorough glimpse into the crime trends across the DMV area. It’s filled with a variety of information and variables, such as: year, population, state names, and various crime categories. Tge data itself was provided Bojan Tunguz provided this data on Kaggle, which was sourced from the Summary Reporting System, the same system the FBI relies on for their annual reports.

Cleaning up the data involved a few steps: filtering the data for specific years, standardizing column names, and dealing with outliers. While the specifics of how the data was collected aren’t crystal clear, the Summary Reporting System likely involves law enforcement agencies across the country submitting crime data to the FBI. This dataset is valuable for uncovering crime trends, which could provide guidance on how to maintain and improve crime prevention systems.