Posts that use New Zealand data


Sankey charts for swinging voters

21 May 2017

Sankey charts based on individual level survey data are a good way of showing change from election to election. I demonstrate this, via some complications with survey-reweighting and missing data, with the New Zealand Election Study for the 2014 and 2011 elections.


Web app for individual party vote from the 2014 New Zealand election study

14 May 2017

Introducing a Shiny web tool for exploring individual characteristics and party vote in the 2014 New Zealand general election.


Modelling individual party vote from the 2014 New Zealand election study

06 May 2017

I work through a fairly complete modelling case study utilising methods for complex surveys, multiple imputation, multilevel models, non-linear relationships and the bootstrap. People who voted for New Zealand First in the 2014 election were more likely to be older, born in New Zealand, identify as working class and male.


Luke-warm about micromaps

30 April 2017

Linked micromaps are an ok way of presenting data and are probably the right tool in some circumstances; but they're not as cool as I thought they might be.


More cartograms of New Zealand census data (district and city level)!

25 April 2017

Shapefiles for cartogram by New Zealand Territorial Authority (ie District or City), with area proportional to population in 2013, have been added to the nzcensus package on GitHub.


Cartograms of New Zealand census data

23 April 2017

Choropleth maps are useful ways of using fill colour to show densities, proportions and growth rates by political or economic boundaries, but can be visually problematic when large geographic areas represent few people, or small areas (ie cities) represent many. One solution is a cartogram, and I have a go at using them to present New Zealand census data in this post and accompanying shiny app.


House effects in New Zealand voting intention polls

21 March 2017

I use generalized additive models to explore "house effects" (ie statistical bias) in polling firms' estimates of vote in previous New Zealand elections.


New data and functions in nzelect 0.3.0 R package

11 March 2017

Version 0.3.0 of the nzelect R package now on CRAN includes historical polling data and a few convenience functions


Earthquake energy over time

19 November 2016

I look more into this business of energy from earthquakes.


Extreme pie chart polishing

15 November 2016

I polish up a dramatic pie chart from stuff.co.nz on earthquake energy released in New Zealand over the last few years.


Statistics New Zealand experimental API initiative

15 October 2016

Statistics New Zealand recently launched experimental access to some of their data over the web via an application programming interface; it can be accessed easily via the equally experimental statsNZ R package by Jonathan Marshall.



New Zealand Election Study individual level data

18 September 2016

Individual level data on voting behaviour are freely available from the New Zealand Election Study and everyone should have a go at analysing them!


Analysing the Modelled Territorial Authority GDP estimates for New Zealand

13 September 2016

My presentation and paper on the development and use of "Modelled Territorial Authority Gross Domestic Product" for New Zealand, as presented to the New Zealand Association of Economists conference in June 2016


nzcensus on GitHub

04 August 2016

Demonstration analysis of area unit demographic data from the nzcensus R package on GitHub, which is approaching more maturity and readiness for general use.


nzelect 0.2.0 on CRAN

14 July 2016

The nzelect R package is now available on CRAN; so far it has aggregate results by voting place for the New Zealand 2014 general election.


Monthly Regional Tourism Estimates

16 June 2016

My day-job released new data on estimated tourism spend by region in New Zealand, by month.


Visual contrast of two robust regression methods

22 May 2016

I use animations to show some of the properties of least trimmed squares compared to a Huber M estimator as alternative robust regression estimation methods for a simple linear models.


Election analysis contest entry part 4 - drivers of preference for Green over Labour party

16 April 2016

Locations with more self employed, people with Bachelor degrees, no religion, and people living overseas five years ago were more likely to vote Green over Labour in the 2014 New Zealand General Election, and locations with more ethnically Asian and Pacific people, people born in New Zealand, and people with no qualification returned higher votes for Labour over the Greens.


Election analysis contest entry part 3 - interactive exploration of voting locations with leaflet and Shiny

09 April 2016

I talk through some exploratory analysis of voting location with a Shiny application using the {nzelect} New Zealand General Election 2014 data.


Election analysis contest entry part 2 - building the nzelect R package

04 April 2016

I explain the structure and techniques behind building the nzelect R package, which has New Zealand election results, in case anyone is interested or wants to adapt the process for other packages that rely on preparatory data munging.


Election analysis contest entry part 1 - introducing the nzelect R package

03 April 2016

I introduce a new R package, with tidy versions of New Zealand election data (so far only for the 2014 general election). We confirm and discuss some well-known results such as the tendency for the Labour Party to apparently under-perform on party vote; and identify patterns at the Territorial Authority and Regional Council level that are not usually available due to how voting behaviour is normally classified and reported on.


Filling in the gaps - highly granular estimates of income and population for New Zealand from survey data

23 January 2016

I use Random Forests to create estimated income distributions for small (sometimes non-existent) subsets of the New Zealand population, using the 2011 New Zealand Income Survey. The estimated distributions are showcased in an interactive web app.


Network charts of commuting in New Zealand with R and D3

26 December 2015

Commuting patterns between districts and cities in New Zealand are used to illustrate static (for printing) and interactive (for the web) network charts with R and D3.


Modelled Territorial Authority GDP for New Zealand

30 October 2015

The Ministry of Business, Innovation and Employment (MBIE) published Modelled Territorial Authority Gross Domestic Product estimates for New Zealand 2000 to 2012 in October 2015, and plan to update annually from now on. The data, method and an interactive web app are on the MBIE website and the source code is available on GitHub.


Seasonal adjusment on the fly with X-13ARIMA-SEATS, seasonal and ggplot2

10 October 2015

I show how to seasonally adjust published electronic card transactions spend in New Zealand using the US Census Bureau's excellent X-13ARIMA-SEATS software, the Spanish SEATS algorithm and Christoph Sax's seasonal R package; and how to build a new "stat" for ggplot2 to make it easy to do seasonal adjustment on the fly for a graphic of a time series split by various grouping dimensions.


Sampling distribution of Gini coefficient

12 September 2015

I explore the sampling distributions of estimates of Gini coefficients from a sample, using the New Zealand Income Survey 2011. At the actual sample size of nearly 30,000, sampling error is negligible, and as low as a sample size of 1,000 a 95% confidence interval is (0.48, 0.55), precise enough for most purposes and certainly good enough given the non-sampling vagaries of the underlying data. I discuss why individual and weekly income data - which is all I have to hand - returns a higher measure of inequality than does annual household income, the more usual and internationally-comparable (and completely valid) measure.


Transforming the breaks to match a scale

07 September 2015

I follow up my ggplot2 version of John and Draper's modulus transformation from my last post. The default for creating new transformations using the {scales} package places the breaks for gridlines and labels in the scale at regular intervals on the original untransformed scale; I explore how to adjust for this.


Creating a scale transformation

05 September 2015

It's easy to define a new transformation with Hadley Wickham's {scales} package, and I do this for John and Draper's modulus transform proposed in 1980 as a way of dealing with data with zero and negative values where logarithmic or Box-Cox transformations fail. This makes it easy to integrate this useful transformation, which works for negative numbers and is continuous through zero, into graphical data analysis.


A better way of visualising income distributions with zeroes and negatives

21 August 2015

I demonstrate a better way of visualising income distributions when they include zero and negative values rather than just putting them on a logarithmic scale and dropping the inconvenient values. I use a modified power transformation, which applies a transformation like square root to the absolute value of the original variable and then restores the sign. I apply the method to the New Zealand Income Survey 2011 data.


Importing the New Zealand Income Survey SURF

15 August 2015

I tidy up the publicly available simulated unit record file (SURF) of the New Zealand Income Survey 2011, import into a database, and explore income distributions, visualising the lower distribution of weekly incomes New Zealanders of Maori and Pacific Islander ethnicity. Along the way I create a function to identify modes in a multi-modal distribution.


New Zealand Data & APIs on GitHub

01 August 2015

I discuss a new listing of datasets in New Zealand, and demonstrate tidying up a publicly available dataset on number of welfare beneficiaries for use in an interactive web application.