Archive for the ‘Election analysis’ Category

Following on from the previous post about Electorate geodata, if we know the votes cast at the polling place-level we can look for geographic differences in vote distributions.  Because political prefernces are correlated with socio-economic status we can then use any differences to quantify the degree of segregation in each electorate.

As in the previous post we calculate the average of the positions of the polling places in each electorate weighted by the total number of party votes cast at each polling place, and also separately weighted by the number of left-wing party votes (Labour and Green) and right-wing party votes (National and ACT).  The distance between these left-wing vote and right-wing vote centres of gravity gives us a measure of segregation in each electorate.  (We normalise this distance relative to the two-dimensional normal distribution defined by the standard deviations of the positions of the centres of gravity for all party votes for each electorate.  It’s not the best way to measure this, but it’s a case of close enough is good enough.)

Based on the results of the 2011 election the most segregated electorate in New Zealand is Botany, shown below (click captions for interactive versions).

The centre of gravity for the left-wing vote in East Tamaki lies over 1km south of that for the right-wing vote in Dannemora.  This agrees reasonably well with prior expectations based on the differences in socio-economic status between Auckland suburbs such as Howick and Otara.

The second most segregated electorate is Mangare:

Again we see a difference as the more northern suburbs such as Mangare Bridge lean (relatively) more in favour of National than more southern suburbs such as Mangare and Mangare East.  The right wing vote lies approximately 1km NW of the left wing vote.

The least segregated electorate in New Zealand is Rotorua.

In spite of the rather large provincial/rural electorate the centres of gravity for the left-wing and right-wing votes lie only a few hundred metres apart, just 4km from central Rotorua.

In each of these three electorates, however, either Labour or National won a fairly high proportion of the party votes, which means that the segregation measures aren’t particularly robust.  A single enclave voting out of sync with the rest of the electorate could be enough to move the centres of gravity around and mess with the results.  If we confine the analysis to electorates closer to the national median, where the left wing vote was in the range of 60%-100% of the right wing vote, then the most segregated electorate was Whanganui:

We can see a clear difference caused by Hawera and rural South Taranaki voting (relatively) more in favour of National, and Whanganui city voting (relatively) more in favour of Labour.

The least segregated electorate was Ohariu:

These calculations have implications for get-out-the-vote efforts in the different electorates.  Given limited resources, Labour supporters in Whanganui would be best to focus their efforts on Whanganui city.  Likewise, National supporters in Botany should be mainly focussing their efforts on the northern two-thirds of the Botany electorate.

Any segregation occurring in electorates also gives us some idea about how the Representation Commission goes about their task of drawing up the electoral boundaries.  From the Electoral Commission website:

All electoral districts must contain electoral populations within 5% of the quota for the North Island or South Island General
electoral districts or the Māori electoral districts as applicable.

The Representation Commission, in forming General electoral districts, is required by the [Electoral Act 1993] to give due consideration to:

  • the existing boundaries of General electoral districts;
  • community of interest;
  • facilities of communications;
  • topographical features; and
  • any projected variation in the General electoral population of those districts during their life.

Studying the segregation implied by the differences in vote distributions amongst polling places gives us some idea of how the Commission go about their task.  We are lucky in New Zealand that because we have MMP the drawing up of electorate boundaries is largely apolitical, and we don’t really have to worry about gerrymandering.  Nevertheless, there are tradeoffs between the different features given consideration, and the existence of any form of segregation as seen above is evidence that the Commission is, at least to some extent, prioritising existing boundaries over communities of interest and topographical features.  This is particularly true in the case of Botany, which was added during the 2007 boundary review to reflect population growth in the Auckland region.  In addition to being the most segregated electorate the Botany electorate boundary looks ugly too, which is no doubt the result of trying to carve an area out of the Auckland region for a new electorate whilst maintaing as much as possible of the existing boundaries.


Again had a few hassles dealing with the geodata.  The first step was to download the 2007 electorate district boundary files from Statistics New Zealand.  Unfortunately I couldn’t get ArcExplorer running, so instead I installed the GDAL package and ran the ogr2ogr wrapper from the terminal to convert them to KML format.  Thirdly, we want to extract the boundaries for single electorates, which was done by selecting layers in Google Earth and exporting.  Fourthly, upload the individual boundary files in KML to Google Maps Engine using the classic Google Maps interface.  And finally we can use the new Google Maps Engine to import and convert old KML from classic maps, and then add the other data points as necessary as a separate layer on top.  There has to be an easier way to do this without dropping $USD400 for the full version of Google Earth!  Hit me up if you have any recommendations.

Read Full Post »

As explained yesterday, one of the first things we need to do is decide on the granularity for the analysis.  The New Zealand Electoral Commission makes election results available at the polling place-level, which makes them a good place to start, but difficulties occur when polling places are discontinued or new polling places are added between elections, and also when there is significant migration, such as that which occurred in and around Christchurch after the 2011 Christchurch Earthquake.  As such we need to look at where the polling places are physically located, and try to understand what happens to voter turnout between elections at the polling place-level.  This will give us an idea of where New Zealanders actually cast their votes.

But first, an aside on geographic datums.

The surface of the earth is flat, at least to first approximation.  This means that instead of dealing with spherical coordinates, such as longitude and latitude, it is often preferable to project the surface onto a plane, and treat it as a two-dimensional cartesian space where points are described by an x-coordinate and a y-coordinate (and a “height”, if necessary).  One example of such a projection is the New Zealand Transverse Mercator (NZTM) produced by LINZ specifically to represent the New Zealand mainland accurately.  Points are given as an “easting” (the x-coordinate) and a “northing” (the y-coordinate), and are expressed in meters east and north of an arbitrary reference point to the southwest of the country.  Because the NZTM is a conformal map shapes and direction are preserved, and it is therefore easy to calculate distances and bearings between nearby points.

As it happens, Elections New Zealand have handily produced a list of all the polling places used in the 2008 and 2011 elections along with their NZTM coordinates.  When we combine this information with the 2011 election party vote results by polling place we get a good idea of where people are voting.  The NZ Herald have an excellent interactive map that shows where the polling places fall under the previous 2008 electoral boundaries and the new 2014 electoral boundaries.  But we can go further and aggregate the information to look at, for example, the centre of gravity of each electorate as defined by the average of the polling place locations weighted by votes.  Results are as follows.

Clicking on the points shows the electorate name and number, total party votes (excluding special votes), and location in latitude and longitude.

One thing that immediately stands out is how sparsely populated much of the country is.  At a fundamental level the map is really only showing population density, but even then it is surprising that if you were to draw a line from Nelson to Invercargill and carve off everything to the west then that quarter-or-so of New Zealand’s land area would contain only a single electorate seat (West Coast-Tasman).  Similarly the middle of the North Island is pretty empty; if you were to cut out an area from Whakatane to New Plymouth to Whanganui to Napier you would have over one-third of the North Island and it would contain only a single electorate seat: East Coast.  (The Taupō electorate has been dragged north by polling places in Tokoroa and Cambridge.)

Of course you may think that this is a bit gimmicky, and you’d be right.  With the exception of a bit of data-vis showing election results this kind of thing isn’t of much use.  The real reasons why we want the polling place geodata are four-fold:

  1. Boundary changes.  The New Zealand Electoral Commission has just finished the latest review of electorate boundaries.  In order to simulate election results for the 2014 or 2017 elections we must figure out where each of the polling places used in the 2011 and 2008 elections are and which new electorate they now fall in.
  2. Discontinued polling places.  At every election some former polling places are discontinued, and other new polling places are added.  If we make the reasonable assumption that most people will vote at their nearest polling place then we can somewhat predict votes and turnout at polling places for the 2014 election even if they were not used for previous elections.
  3. Regression.  If we know the physical locations of each polling place, and again make reasonable assumptions about where people vote then we can at least theoretically make comparisons with the Census meshblock-level data from Statistics NZ and try and predict people’s votes based on their age, education, income, family size and so on.  A little outside the scope of my work here, but it would be a fascinating project.
  4. Get-out-the-vote.  Certain polling places will have a higher proportion than others of swing voters.  Depending on your political leanings polling place geodata will tell you where you need to concentrate your get-out-the-vote efforts.

The next post will look at political segregation in different electorates.


I don’t have a lot of experience handling geodata, and it took a bit of effort to get the coordinate transforms into longitude and latitude working properly so that the results would show up correctly in Google Maps.  By far the best solution I found was to use the PROJ.4 – Cartographic Projections Library.  As I’m using python I needed the pyproj wrapper for PROJ.  On Mac the easiest way to get it is to use pip as follows:

curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
pip install pyproj

There is an excellent tutorial on using geospatial data with python from the SciPy 2013 conference (see the first video).  The secret is to instantiate PROJ classes using the European Petroleum Survey Group (EPSG) Geodetic Parameter Dataset code numbers:

import pyproj
nztm_proj = pyproj.Proj("+init=EPSG:2193")
latlong_proj = pyproj.Proj("+init=EPSG:3857")
long, lat = pyproj.transform(nztm_proj, latlong_proj, easting, northing)

keywords: python, PROJ, pyproj, NZTM, Google Maps, EPSG.


Read Full Post »