My post yesterday discussed the mean centres of population of South Africa and its provinces. The mean centre is (relatively) easy to calculate, but it may not be the most useful type of population centre. It is essentially an arithmetic mean, which means that outliers can have a massive effect on the centre. It minimizes the average square of distance from the centre, not the average distance from the centre. The centre that does minimize the average distance is called the geometric median, and it is not quite so simple to calculate, since there is no closed form solution. But it can be done!
Finding the geometric median uses an iterative method known as Weiszfeld's algorithm, which is described in section 2.2 here (amongst many other places). As before, the calculations were performed using a PostGIS spatial database with the small area layer from Census 2011. The code implementing Weiszfeld's algorithm is in this GitHub repository; it is a naive implementation but sufficient for this purpose.
The national geometric median centre of population is at 26.84307°S 28.23545°E, on Bezuidenhoutsberg just north of Vaal Marina on the Vaal Dam. This point is 75km south of the Johannesburg CBD and very close to the tripoint of Gauteng, Mpumalanga and the Free State. It is 165km north (and a bit east) of the mean centre of population.
The provincial geometric medians are:
Follow-up: a subsequent post describes the geometric median centre of population, which is some respects a more sensible definition than the mean centre of population described here.
The centre of population is a point that represents an "average" location of the people in a country or other area; exactly what that "average" is depends on the way the centre is calculated. As far as I can tell, nobody has calculated a centre of population of South Africa; at least nobody has published it anywhere that Google can find. So I've calculated one myself, both out of interest and also in case anyone else finds it useful. I also calculated the centre of population of each province.
The method of calculation is that described in the US Census Bureau publication Centers of Population Computation for the United States. This method produces a mean centre of population, and adjusts for the fact that the distance between meridians (lines of longitude) decreases with latitude. The calculations were performed in a PostGIS spatial database using the Census 2011 small area layer, the most detailed level of population data available fron the census.
The national centre of population is located at 28.28430°S 27.70690°E, at the foot of Ghwarriekop just outside the town of Senekal in the Free State. (If we ever decide to move all the branches of national government to one place, perhaps Senekal should be the site.) The population centre is substantially further east than the geographic centre of South Africa because South Africa is much more densely populated in the east than the west, as can be seen from the map above.
The provincial centres of population are:
At some point in school, we South Africans are told that the official decimal separator is the comma.1 Most of us then proceed to ignore this—at least in English use2—because it differs from the decimal point used in the rest of the English-speaking world, and thereby creates confusion. Thankfully, the maintainers of the glibc locale data—and thus the number formats used in Linux systems—agree with me on this question, and the South African English locale uses the decimal point.
Unfortunately, the developers of Ubuntu Linux have come across a government communications style guide—a style guide widely ignored even within the government—which specifies the use of the decimal comma. They have therefore included in Ubuntu a patch which changes the decimal separator for South African English to a comma.3 Reversing this change is one of the first things I do after setting up a new Ubuntu (or Linux Mint) install. Fortunately it is quite easy, and I give the instructions here to help those who suffer from the same annoyance.
Run the command
sudo update-locale LC_NUMERIC="en_GB.UTF-8"
The change won't take effect until you log out and back in again. This tells your system to use the British English settings for number formatting, and therefore to use the decimal point.
(If, for some reason, update-locale doesn't work for you, you can produce the same results by adding the line LC_NUMERIC="en_GB.UTF-8" to the file /etc/default/locale.)
This method changes LC_NUMERIC which defines the format for ordinary numbers, but not LC_MONETARY, which defines the format for currency values. We could change LC_MONETARY to "en_GB.UTF-8", but then it would also change the currency symbol from "R" to "£".
If we want to change the decimal separator for monetary values, without changing the currency symbol, we will have to edit the en_ZA locale definitions. You can download my patch file en_ZA-decimal-point.patch, and then apply it to the locale definitions by running the commands
sudo patch /usr/share/i18n/locales/en_ZA en_ZA-decimal-point.patch
The changes will take effect immediately. You may have to repeat this process if the locales package is upgraded, because the upgrade will overwrite the locale definitions.
I've drawn some maps showing the percentage-point change between the 2009 and 2014 elections in the vote share of the major parties (or, in the case of COPE, formerly major parties). Because municipal boundaries have changed a bit, I had to recalculate the 2009 results for the 2014 boundaries, by assigning the voting districts from 2009 to wards from 2014. In the cases where a 2009 VD was spread across multiple 2014 municipalities, I assigned it according to the location of the voting station.
As always, click on the map to see the full-size version.
The ANC has increased its share substantially in some parts of the Western and Northern Cape; but it appears to have been at the cost of COPE or other smaller opposition parties, as the DA has also seen an increase in most of these areas (see the next map).
Some of the substantial increases seen by the DA are thanks to its absorption of the Independent Democrats.
Since the EFF is a new party the map just shows its share of the vote in 2014. The municipality where it won more than 20% is, unsurprisingly, Rustenburg, where it won 20.22% of the vote.
Essentially, this map just shows COPE's share of the vote in 2009. In the places where it won more votes in 2009, it had more votes to lose in 2014.
The IFP lost badly in northern KZN, shedding votes to the breakaway NFP and, to a lesser extent, the ANC.
The NFP, which broke away from the IFP before the 2011 municipal elections, managed to win a substantial share of the vote in northern KZN.
The detailed 2014 election results map promised in my last post is live! It has all the features of the 2009 map, plus you can see the results from both the national and the provincial ballots. As before, you can zoom right down to street level and see the results for individual voting districts.
By way of example, here you can see it with the provincial ballot results from my voting station.
As a long-weekend project I've put together this interactive map of the 2009 South African election results. It's a "slippy" (i.e. scrollable and zoomable) map and you can zoom right down to street level and see the results for individual voting districts. (Something you can't do with the News24 election map!)
Use the buttons in the top left to choose the level of detail—province, district municipality, local municipality, ward or voting district—though wards and voting districts aren't available until you zoom in a few levels. Click on an area on the map to see the results for that area. For example, here are the results from my voting district in Rosebank.
It's my plan to have a version with the 2014 election results up as soon as possible after the IEC releases the detailed results spreadsheets once the election is declared.
I have a new site up which graphically displays information about the results of the 2009 South African elections. This project was an exercise in learning to use the D3.js framework. All the code and data is available in a github repository.