police-violence

A look at the data from Mapping Police Violence.
git clone https://git.eamoncaddigan.net/police-violence.git
Log | Files | Refs | README | LICENSE

useOfForce.R (3495B)


      1 # Look at the relationship between departments' use of force policies and
      2 # violence.
      3 
      4 library(readxl)
      5 library(dplyr)
      6 library(tidyr)
      7 library(ggplot2)
      8 library(grid)
      9 library(gridExtra)
     10 
     11 forcePolicy <- read_excel("UseofForcePolicyReview-bbdj.xlsx")
     12 # The column names are pretty long
     13 colnames(forcePolicy) <- sub(":.*", "", colnames(forcePolicy))
     14 
     15 # Strip answers down to TRUE (yes) / FALSE (no) values
     16 yesOrNo <- function(x) {
     17   ifelse(grepl("^Yes", x), 
     18          "Yes",
     19          ifelse(grepl("^No", x),
     20                 "No",
     21                 NA))
     22 }
     23 forcePolicy <- mutate_each(forcePolicy, funs(yesOrNo), -`Police Department`)
     24 
     25 # Now look at the mapping police violence project's report to find these
     26 # departments.
     27 mpvReport <- read_excel("MPVDatasetDownload-83zj.xlsx", sheet = 2) 
     28 
     29 mpvReport <- mpvReport %>%
     30   mutate(`Police Department` = sub("^[^[:alpha:]]*", "", `Police Department`),
     31          row_number = 1:nrow(.)) %>% 
     32   filter(row_number <= 60) %>%
     33   rename(`Police Department 2` = `Police Department`)
     34 
     35 # We'll do a fuzzy left join of these tables. This code is inelegant and
     36 # inefficient, but works OK for this few rows.
     37 forcePolicy[["Police Department"]][7] <- "Las Vegas"
     38 matches <- rep(NA, nrow(forcePolicy))
     39 for (r in seq_len(nrow(forcePolicy))) {
     40   matches[r] <- agrep(forcePolicy[["Police Department"]][r],
     41                       mpvReport[["Police Department 2"]])
     42 }
     43 forcePolicy <- cbind(forcePolicy, mpvReport[matches, ])
     44 
     45 # Now let's see how these policies may effect police killings
     46 policyEffectiveness <- forcePolicy %>%
     47   select(department = `Police Department`, 
     48          2:9, 
     49          rate_of_killings = `Rate of Police Killings per Million Population`,
     50          population = `2014 population (US Census)`) %>%
     51   gather("policy", "in_place", 2:9)
     52 
     53 # Plot it
     54 p <- ggplot(policyEffectiveness, aes(x = in_place, y = rate_of_killings)) + 
     55   geom_point(aes(color = in_place, size = population), 
     56              alpha = 0.5,
     57              position = position_jitter(width = 0.4, height = 0.0)) + 
     58   facet_wrap(~ policy) + 
     59   labs(title = "The effect of department policies on killings by police", 
     60        x = "Policy in place", 
     61        y = "Citizens killed by police (per million population)") + 
     62   scale_color_discrete(guide = FALSE) +
     63   scale_size_area(name = "City population",
     64                   breaks = seq(2e06, 8e06, length.out = 4),
     65                   labels = paste(seq(2, 8, length.out = 4), " million")) +
     66   theme(legend.position = c(0.85, 0.15))
     67 print(p)
     68 pCaption <- textGrob(paste(" ",
     69                            "Police killing data: http://mappingpoliceviolence.org/",
     70                            "Police departmental policy data: http://useofforceproject.org/",
     71                            sep = "\n"), 
     72                      x = 0, 
     73                      just = c("left", "bottom"), 
     74                      gp = gpar(fontface = "italic", fontsize = 12))
     75 pWithCaption <- arrangeGrob(p, bottom = pCaption)
     76 ggsave("all police force policies.png", pWithCaption, dpi=120)
     77 
     78 # Wow. Zero in on de-escalation though.
     79 policyEffectiveness %>% 
     80   filter(policy == "Requires De-Escalation") %>%
     81   ggplot(aes(x = in_place, y = rate_of_killings)) + 
     82   geom_boxplot(aes(fill = in_place)) + 
     83   labs(title="Policies requiring officers to de-escalate vs. police violence",
     84        x = "Are officers required to de-escalate situations?",
     85        y = "Rate of police killings (per million population)") + 
     86   theme(legend.position = "none")
     87 ggsave("de-escalation reduces police killings.png")