Visualizing Correlates of War Data With Leaflet.js14 Feb 2014
The Correlates of War project maintains several data sets that document conflicts throughout history. This includes data on armed conflicts such as inter-state disputes as well as ancillary data that might be correlated with disputes, such as trade, alliances and measures of countries’ resources. This data makes for interesting geographic visualizations. This post highlights how Leaftlet.js can be used to create geographic data visualizations using this data.
Using Crosslet.js to compare battle related fatalities with national capability
Can we see any relationship between the fatalities a country suffers during disputes and it’s national capabilitiy?
This first visual uses two datasets from Correlates of War:
- National Material Capabilities Index
The National Material Capabilites data set contains annual values for total population, urban population, iron and steel production, energy consumption, military personnel, and military expenditure of all state members, currently from 1816-2007. The widely-used Composite Index of National Capability (CINC) index is based on these six variables and included in the data set.
- the New COW War Data, 1816-2007 v4.0
This data set records all instances of when one state threatened, displayed, or used force against another.
Specifically, three values are computed for each country listed in the dataset:
- CINC time average - the mean Composite Index of National Capability value over time
- Average fatality - the mean number of battle-related fatalities per militarized interstate dispute
- Average fatality per military personnel - average fatality relative to the size of that country’s military, measured by the number of military personnel for the observation year.
Using Crosslet is very straight forward. First build the
config object that specifys our Leaflet API key and the geoJSON file we wish to use to define the borders of the countries we wish to highlight:
Next, we specify which data we want to load.
Finally, instantiate a new Crosslet map object using the
config object we just created, passing the DOM element where it should be rendered on the page:
In the Crosslet widget above, you can see that we have three dimensions of data displayed in a choropleth map. We can also see the distribution of each variable as displayed in a histogram/color map for each variable. One of the powerful features of Crosslet is that we can select a range over which to slice the observations. This piece is powered by Crossfilter.js. This slicing of the data allows for some interesting visual analysis. By selecting the upper range of the CINC index data do we see a change in the distribution of average fatalities?
This map based visualization makes for interesting exploratory data analysis, but we can use more conventional data visualization techniques to test our hypothesis as well. For example, this scatter plot shows a time-average of the CINC score vs. average battle related fatalities relative to the size of a country’s military on a log-log scale. A regression shows that there is a weak negative relationship between average fatalities per battle and a country’s CINC score.
Visualizing battle related fatalities geographically
Next, visualizing inter-state dispute fatalities throughout history using a heatmap. Can we identify “hot” areas where more fatalities occured?
This visual makes use of Militarized Interstate Disputes v4.0 and the Militarized Interstate Dispute Location datasets. This data is initially in three csv files. I used a Python script to read in the data and do some initial descriptive data analysis, exporting the data into JSON format:
Fatality Heatmap With Heatcanvas
This visual uses the heatcanvas library to generate a heatmap overlay to highlight battle related fatality levels throughout the world. The value of each pixel displayed on the map is defined by its distance to points that holds data (in this case fatality level for a dispute).
Marker annotation functionality is provided by Leaflet, however the easy to use Leaftlet.markerCluster plug-in handles overlapping annotations by grouping them and tracing the area of the map covered by a given cluster of annotations.
This will make things a bit easier for us as we: 1) Join the data sets 2) Create the Leaflet.js Tile Layer and init the Marker Layer and HeatCanvas Tile Layer objects 3) Build the marker text, and finally 4) Add the Layers to the map.
Here’s how it looks (images link to the actual interactive widget - will take a few seconds to load):
Militarized inter-state disputes marker cluster
####Problems with this visual
- The maximum fatality level is 999+, swamping disputes that resulted in thousands, hundreds of thousands, and even millions of fatalities.
- Location is set where the dispute began, not where individual battles occured
- Only 1 datapoint per dispute
- Loading performance is poor, mostly due to the data munging being done in the client. The data should be prepared in the format intended to be used ahead of time.
Thanks to the maintainers of the Correlates of War project. Building these visuals was a sobering experience for me. The full code for this project is available on github.