Feb 102019
 
AfD results in 2017 federal election in Germany (map of districts)

As (West) European election years go, 2017 was quite something. The French party system changed beyond recognition. The radical right entered Germany’s national parliament for the first time. UKIP was wiped out, but May still managed to lose a comfortable majority. And very high fragmentation resulted in a coalition that looks improbable even by Dutch standards.

SCoRE is our multinational project that explores the link between local and regional living conditions on the one hand and radical right attitudes and behaviours in these four countries on the other. Sometimes, serendipity is really a thing. Because we had our individual-level data collection scheduled for this year anyway, we gained some unique insights into all four big Western European elections of 2017.

Accordingly, my colleagues have written up reports for France, Germany, the Netherlands, and the UK, complete with beautiful maps. Who does not like maps?

Four 2017 elections that changed West European Politics: France, Germany, the Netherlands & the UK

But perhaps you’re pressed for time or not sure if you really want to read four (fairly short) reports? With the European Parliamentary elections on the horizon, I made a short explainer/teaser video about them to bring you up to speed in just over two minutes. I have a hunch that afterwards, you will want to read all four pieces.

May 202012
 
Apr 212012
 

I’m more and more intrigued by the potential spatial data hold for political science. Once you begin to think about it, concepts like proximity and clustering are basic building blocks  for explaining social phenomena. Even better, since the idea of open data has gone mainstream, more and more spatially referenced information becomes available, and when it comes to free, open source software, we are spoilt for choice or, at least in my case, up and beyond the point of utter confusion.

For our paper on the effect of spatial distance between candidates and their prospective voters,  we needed  a choropleth map of English Westminster constituencies that shows how many of the mainstream candidates live within the constituency’s boundaries. Basically, we had three options (not counting the rather few user-contributed packages for Stata): GRASS, a motley collection of Python packages, and a host of libraries for R.

GRASS is a full-blown open source GIS, whose user interface is perfect for keyboard aficionados and brings back happy memories of the 1980s. While GRASS can do amazing things with raster and vector maps, it is suboptimal for dealing with rectangular data. In the end, we used only its underrated cartographic ps.map module, which reliably creates high-resolution postscript maps.

Python has huge potential for social scientists, both in its own right and as a kind of glue that binds various programs together. In principle, a lot of GIS-related tasks could be done with Python alone. We used the very useful geopy toolboxfor converting UK postcodes to LatLong co-ordinates, with a few lines of code and a little help from Google.

Candidate locations by constituency

The real treasure trove, however, is R. The quality of packages for spatial analysis is amazing, and their scope is a little overwhelming. Applied Spatial Data Analysis with R by Roger Bivand, who wrote much of the relevant code, provides much-needed guidance.

Counting the number of mainstream candidates living in a constituency is a point-in-polygon problem: each candidate is a co-ordinate enclosed by a constituency boundary. Function overlay from package sp carries out the relevant operation. Once I had it located, I was seriously tempted to loop over constituencies and candidates. Just in time, I remembered the R mantra of vectorisation. Provided that points (candidates) and polygons (constituencies) have been transformed to the same projection, all that is needed is this:

mymap@data$homeconst1 <-overlay(candpos1,mymap)
mymap@data$homeconst2 <-overlay(candpos2,mymap)
mymap@data$homeconst3 <-overlay(candpos3,mymap)

This works because candpos1 is a vector of points that represent the spatial positions of all Labour candidates. These are tested against all constituency boundaries. The result is another vector of indices, i.e. sequence numbers of the constituencies the candidates are living in. Put differently, overlay takes a list of points and a bunch of polygons and returns a list that maps the former to the latter. With a bit of boolean logic, a vector of zeros (candidate outside constituency) and ones (candidate living in their constituency) ensues. Summing up the respective vectors for Labour, Tories, and LibDems then gives the required count that can be mapped. Result!