There was a flurry of activity in the last couple of days on Twitter and the blogosphere, most notably Thomas Lumley’s excellent Stats Chat, relating to whether there is a pro-government bias in surveys of New Zealand voting intention in the summer. As the analysis I’ve seen used my
nzelect R package, this motivated me to update it for recent polls.
nzelect hasn’t been updated on CRAN for some time, because about a year ago I made some major changes to the data model for the historical election results by voting place and I haven’t been able to complete testing and stabilisation of the result. I do hope to do this some time in the next few months. In the meantime, the version on GitHub has the current polling data, and I intend to keep it current. Political polls are very thin on the ground these days for New Zealand, so that’s not too big an ask! I’ve now spent a bit of time tidying it up and adding the three most recent polls, which I’d previously neglected.
Let’s start with the basics. One of the reasons I first put the package together several years ago was to help facilitate analysis of the relatively long run in political opinion. I wanted to lift up analysis from over-interpretation of the last few noisy data points. Here’s the expressed voting intention of New Zealanders for the four currently largest parties in Parliament over time:
It’s striking, but unsurprising, how the Greens and New Zealand First support has collapsed since coming into government with Labour (or just before, in the case of the Greens and their disappointing 2017 election campaign). The junior party in a coalition often suffers, as attention and kudos goes to the leaders of the large party (in this case, Prime Minister Jacinda Ardern) and the smaller parties’ own base deals with the realities and compromises of being in government.
The other interesting (and disappointing, for statisticians and political scientists) observation from this chart is how obviously the number of polls has decreased. Topic for another day (or more likely, someone else to write about).
Here’s the R code for that chart:
There’s obvious interest for supporters of the left-of-centre parties in the combined vote for Labour and the Greens. That suggests the importance of this chart:
(Apologies for red-green colour blind people in the use of these party colours; the Greens are the lowest of the three lines and Labour the middle.)
It’s clear that to a significant degree electoral support for the two is substitutable, with the green and red lines moving in scissors-like counter directions at several key times since 2010, with the last 24 months just the most dramatic example.
It’s also clear that the combined support for the centre-left in New Zealand is pretty strong, recovered to a point it hasn’t been since several years before the end of the government led by Helen Clarke in the 2000s.
Here’s the code for that chart. Note how I use the dates of elections to make a simple data frame of who is in power when, for the background rectangles; and leverage the
parties_v vector of colours in
nzelect to allocate the official party colours to both the parties’ lines and to the background fill.
Now, on to the question of seasonality. I don’t have much to add to the analysis of David Hood on Twitter and Thomas Lumley on StatsChat; I basically agree with their conclusions. I have the advantage of a few more polls because of the update to
nzelect this morning.
Here is the expressed intended vote for the party of the Prime Minister over time:
The blue line for the National Party is higher than the equivalent for Labour Prime Ministers because National has tended to form a larger proportion of its governing coalitions than Labour in this time period. I could (and probably should) have added the intended vote for all parties currently in coalition government, but this is actually a pretty complicated thing to do so I’ve gone for the simpler approach for now. So long as we don’t make simplistic comparisons forgetting that New Zealand has a proportional representation system, that is ok for our purposes.
We obviously can’t tell anything from this chart about the seasonality; there are two many data points and too much noise. Actually, one thing we can say for sure is that seasonality isn’t strong. For very seasonal data such as tourist numbers, the seasonality would be obvious even in a chart like this.
To see if there is a subtle seasonality effect, I tried modelling voting intention for the Prime Minister’s party on the month of the year, controlling for the party in power, a smooth trend over time, and whether or not it is an election month (otherwise September and November, with five of the six elections in this period, would certainly cloud the data). I used (as I nearly always do in this situation) Simon Woods excellent
mgcv R package.
Having done that, we can approximate confidence intervals for the impact on voting preference of the month of the year. The next chart shows those estimates:
As the title says, it’s weak evidence of a weak effect, which might be around half a percentage point more positive for the Prime Minister’s party in the summer months than it is in June. Or it might be more than that, or even negative.
Here’s the code for that model and the last two charts:
It’s very motivating to see others using the
nzelect package. Please tag me in Twitter, or let me know some other way, if you use this and it will encourage me for further enhancements, and to get the new version with better historical data onto CRAN!
I’m going to try to get into the habit of this at the end of each blog post. Without the hard work, innovation and sheer smarts of the open source community my blog (and many much more important things!) wouldn’t be possible. Here are just those in the R world whose code I used in this session (not all of it made it into the excerpt above, but that’s all the more reason to give thanks below).
|Hadley Wickham firstname.lastname@example.org||17||assertthat, dplyr, forcats, ggplot2, gtable, haven, httr, lazyeval, modelr, plyr, rvest, scales, stringr, testthat, tidyr, tidyverse, usethis|
|R Core Team Remail@example.com||10||base, compiler, datasets, graphics, grDevices, grid, methods, stats, tools, utils|
|Gábor Csárdi firstname.lastname@example.org||9||callr, cli, crayon, desc, pkgconfig, processx, ps, remotes, sessioninfo|
|Kirill Müller <email@example.com>||6||bindr, bindrcpp, hms, pillar, rprojroot, tibble|
|Jim Hester firstname.lastname@example.org||4||devtools, pkgbuild, pkgload, readr|
|Winston Chang email@example.com||4||extrafont, extrafontdb, R6, Rttf2pt1|
|Jim Hester firstname.lastname@example.org||3||fs, glue, withr|
|Lionel Henry email@example.com||3||purrr, rlang, tidyselect|
|Dirk Eddelbuettel firstname.lastname@example.org||3||digest, Rcpp, x13binary|
|Yixuan Qiu email@example.com||3||showtext, showtextdb, sysfonts|
|Jeroen Ooms firstname.lastname@example.org||2||curl, jsonlite|
|Yihui Xie email@example.com||2||knitr, xfun|
|Vitalie Spinu firstname.lastname@example.org||1||lubridate|
|Michel Lang email@example.com||1||backports|
|Patrick O. Perry firstname.lastname@example.org||1||utf8|
|Simon Wood email@example.com||1||mgcv|
|Achim Zeileis Achim.Zeileis@R-project.org||1||colorspace|
|Baptiste Auguie firstname.lastname@example.org||1||gridExtra|
|Gabor Csardi email@example.com||1||prettyunits|
|Peter Ellis firstname.lastname@example.org||1||nzelect|
|Simon Urbanek Simon.Urbanek@r-project.org||1||Cairo|
|James Hester email@example.com||1||xml2|
|Justin Talbot firstname.lastname@example.org||1||labeling|
|Torsten Hothorn Torsten.Hothorn@R-project.org||1||mvtnorm|
|Christoph Sax email@example.com||1||seasonal|
|Jennifer Bryan firstname.lastname@example.org||1||readxl|
|Kevin Ushey email@example.com||1||rstudioapi|
|Max Kuhn firstname.lastname@example.org||1||generics|
|Stefan Milton Bache email@example.com||1||magrittr|
|Martin Maechler <mmaechler+Matrix@gmail.com>||1||Matrix|
|Charlotte Wickham firstname.lastname@example.org||1||munsell|
|Brodie Gaslam email@example.com||1||fansi|
|Matthew Lincoln firstname.lastname@example.org||1||clipr|
|Gavin L. Simpson email@example.com||1||gratia|
|Marek Gagolewski firstname.lastname@example.org||1||stringi|
|Jeremy Stephens email@example.com||1||yaml|
|Brian Ripley firstname.lastname@example.org||1||MASS|
|Deepayan Sarkar email@example.com||1||lattice|
|Claus O. Wilke firstname.lastname@example.org||1||cowplot|
|Rasmus Bååth email@example.com||1||beepr|
|Jennifer Bryan firstname.lastname@example.org||1||cellranger|
|Alex Hayes email@example.com||1||broom|
|Simon Urbanek firstname.lastname@example.org||1||audio|
|Jim Hester email@example.com||1||memoise|