Friday, February 23, 2018

Mapping and Comparing the Murder Rates of Italy and the USA Using R

Overview | Code | Output

Map of the world depicting countries in green which have a homicide rate less than Italy.Map of Europe depicting countries in green which have a homicide rate less than Italy.Map of the word depicting countries in green which have a homicide rate less than the USA.
Three plots visually showing countries with a smaller and greater homicide rate than Italy and USA. Left: Map of the world depicting countries in green which have a homicide rate less than Italy. Center: Map of Europe depicting countries in green which have a homicide rate less than Italy. Right: Map of the word depicting countries in green which have a homicide rate less than the USA.

Overview


Traveling between the USA and Italy, you might be interested in crime statistics between the two countries as we were. In particular, we wanted to see if we could understand which country we were "safer". Safe is complex, multi-faceted concept, depending on where you are and what kind of things you do. To look at one facet of it, here we look at the murder rate per million people per country. These stats are published on the NationMaster site and are intentional homicides, number and rate per number and rate per million people.

The NationMaster site has a map where countries are colored light to dark based on their crime statistic. We wanted to look at the data in a slightly different way, specifically breaking the data into two: countries with a crime statistic greater than a reference country and countries with a crime statistic lower. Therefore, in a glance we could see for Italy or the USA (as the reference country) all the countries with the higher and lower values.

Code


You should be able to paste the code below directly onto the command line of your R environment. Here is the code on Github. See the notes below for more information.

require("dplyr")
require("rworldmap")
data(countryExData)

# www.nationmaster.com/country-info/stats/Crime/Violent-crime/Murder-rate-per-million-people
data.murder <- read.csv("Murder rate per million people.csv")
colnames(data.murder)[2] <- "Rate"

# get values for Italy and USA
rate.Italy <- data.murder[data.murder$Country=="Italy","Rate"]
rate.USA <- data.murder[data.murder$Country=="United States", "Rate"]

data.murder.Italy <- data.murder
data.murder.USA <- data.murder
data.murder.Italy$RateF <- mutate(data.murder, RateF=ifelse(Rate/rate.Italy >= 1, ifelse(Rate/rate.Italy == 1.0, 1.0, 2.0),0.0))$RateF
data.murder.USA$RateF <- mutate(data.murder, RateF=ifelse(Rate/rate.USA >= 1, ifelse(Rate/rate.USA == 1.0, 1.0, 2.0),0.0))$RateF

# Plotting variables
title <- "Country homicide crimes relative to"
pal <- c("lightgreen", "lightskyblue", "mistyrose2")

# World map referenced to Italy
data.joined.Italy <- joinCountryData2Map(data.murder.Italy, joinCode="NAME", nameJoinColumn="Country")
par(mai=c(0,0,0,0),xaxs="i",yaxs="i")
mapCountryData(data.joined.Italy, nameColumnToPlot="RateF")
mapParams <- mapCountryData(data.joined.Italy, nameColumnToPlot="RateF", addLegend=FALSE, catMethod="fixedWidth", numCats=3, colourPalette=pal, mapTitle="") 
do.call( addMapLegend, c(mapParams, legendWidth=0.5, legendMar = 2, legendLabels = "none" ))
text(x=0,y=120,labels=paste(title,"Italy"), cex=1.5)
text(c(-100,0,100),-140, labels=c("Rates less than Italy","Italy","Rates greater than Italy"))

# Europe map referenced to Italy
data.joined.Italy2 <- joinCountryData2Map(data.murder.Italy, joinCode="NAME", nameJoinColumn="Country")
par(mai=c(0,0,0,0),xaxs="i",yaxs="i")
mapCountryData(data.joined.Italy2, nameColumnToPlot="RateF")
mapParams <- mapCountryData(data.joined.Italy2, nameColumnToPlot="RateF", addLegend=FALSE, catMethod="fixedWidth", numCats=3, colourPalette=pal, mapTitle="", mapRegion="europe") 
do.call( addMapLegend, c(mapParams, legendWidth=0.5, legendMar = 2, legendLabels = "none" ))
text(x=17,y=75,labels=paste(title,"Italy"), cex=1.5)
text(c(2,17,32),30, labels=c("Rates less than Italy","Italy","Rates greater than Italy"))

# World map referenced to USA
data.joined.USA <- joinCountryData2Map(data.murder.USA, joinCode="NAME", nameJoinColumn="Country")
par(mai=c(0,0,0,0),xaxs="i",yaxs="i")
mapCountryData(data.joined.USA, nameColumnToPlot="RateF" )
mapParams <- mapCountryData(data.joined.USA, nameColumnToPlot="RateF", addLegend=FALSE, catMethod="fixedWidth", numCats=3, colourPalette=pal, mapTitle="" ) 
do.call( addMapLegend, c(mapParams, legendWidth=0.5, legendMar = 2, legendLabels = "none" ))
text(x=0,y=120,labels=paste(title,"USA"), cex=1.5)
text(c(-100,0,100),-140, labels=c("Rates less than USA","USA","Rates greater than USA"))




Notes:

  • On the NationMaster site, we selected all years to export. This gives the largest possible list of countries for comparison with the caveat that not all countries are compared for the same year. For this exercise of R code this wasn't a big concern. 
  • If you export the NationMaster stats into a CSV file into a specific directory, then make sure you use setwd() to change to that directory or modify the read.csv() statement in the code to point to the correct location. 
  • Using the rworldmap package is described here in the post Maps in R: Introduction - Drawing the map of Europe. See rworldmap package page on cran.r-project.org to get to the latest reference manual. 
  • The rworldmap::mapcountryData() method will warn about quantiles as discussed in this Stack Overflow post. If you look at the help (?mapcountryData) it says "will generate unhelpful errors in data categorisation if inappropriate options are chosen, e.g. with catMethod:Quantiles if numCats too high so that unique breaks cannot be defined."

Output


The code generates three plots. Two plots are referenced for Italy and one for the USA. Each plot has three colors, green, blue and orange. Green represents countries with less homicides than the reference country and orange represents countries with more homicides than the reference. Blue represents the reference country, either Italy or the USA.


  • Map 1: The world map referenced for Italy shows that there are many countries colored as orange, i.e., having more homicides. In the NationMaster data, there are only 19 countries with less homicide. Many are European and Scandinavian countries. A few countries with less homicide are in the Saudi Arabian Peninsula and others in Asia. The world map doesn't make it easy to see the smaller countries that are green.
  • Map 2: Zooming into Europe makes it easier to see the countries in Europe that have less homicide than Italy, including Denmark, Spain, Germany, Slovenia, Switzerland, Austrian, Norway, and Iceland.
  • Map 3: Back to the world map referenced on the USA, i.e., countries with less homicide than the USA are colored green and countries with more homicide are colored orange.


In 2010, 8.75 people per million were killed due to intentional homicide in Italy. For 2010, the number was 42.01 people per million in the USA. The UNODOC report Global Study on Homicide 2013 reports that for Italy, there were 0.9 homicides per 100,000 people with a total count for that year of 530. For the USA, the report gives 4.7 homicides per 100,000 people with a total count for that year of 14,827.

There will be discrepancy in the numbers because we are mixing years and different reporting sources, but it's still useful to do a sanity check.


  • In 2012, Italy's total population was about 60 million. 8.75 people per million x 60 million = 525 people, close to the UNODOC report.
  • In 2012, USA's total population was about 314 million. 42.01 people per million x 316 million = 13,275, about 10% off from UNDOC number.


The takeaway is that one is more likely to be killed by intentional homicide in the USA than in Italy. Crime in the United States Wikipedia article is a good introduction. It states that "Overall the total crime rate of the United States is higher than developed countries, specifically Europe, with South American countries and Russia being the exceptions", which is pretty much what is shown above.

An interesting side note from the UNDOC report is that "[i]n Italy, there has been a 50 per cent decline in this type of homicide since 2007, with organized crime-related rates of homicide decreasing from 0.2 to less than 0.1 per 100,000 population."

Update


2023-08-10:  This NYT article Why Is America Such a Deadly Place? references this report On gun violence, the United States is an outlier where there is this quote:  

Age-adjusted firearm homicide rates in the US are 13 times greater than they are in France, and 22 times greater than in the European Union as a whole. The US has 23 times the rate of firearm homicide seen in Australia. 
Our estimates above for Italy were about 5 times greater for Italy for the years mentioned above. Just an estimate.


No comments:

Post a Comment

All comments go through a moderation process. Even though it may not look like the comment was accepted, it probably was. Check back in a day if you asked a question. Thanks!