Collecting results of the New Zealand General Elections

New Zealand Electoral Commission results website. It held really well in election night.

I was reading an article about the results of our latest elections where I was having a look at the spatial pattern for votes in my city. I was wondering how would I go over obtaining the data for something like that and went to the Electoral Commission, which has this neat page with links… Continue reading Collecting results of the New Zealand General Elections

Where are New Zealand’s bellwether electorates?

Newton meditating how far down the list os the Wigram electorate: not quite bellwether (Photo: Luis. Click to enlarge).

I was reading a piece by Graeme Edgeler who, near the end, asked "Where are New Zealand's bellwether electorates?". I didn't know where the data came from or how was the "index of disproportionality for each electorate" calculated, but I saw it mostly as an opportunity to whip up some quick code to practice the… Continue reading Where are New Zealand’s bellwether electorates?

Functions with multiple results in tidyverse

Mobile phone antenna in church (Photo: Luis, click to enlarge).

I have continued playing with the tidyverse for different parts of a couple of projects. Often I need to apply a function by groups of observations; sometimes, that function returns more than a single number. It could be something like for each group fit a distribution and return the distribution parameters. Or, simpler for the… Continue reading Functions with multiple results in tidyverse

Turtles all the way down

Door in Valparaíso.

One of the main uses for R is for exploration and learning. Let's say that I wanted to learn simple linear regression (the bread and butter of statistics) and see how the formulas work. I could simulate a simple example and fit the regression with R:

The formulas for the intercept ($latex b_0$) and… Continue reading Turtles all the way down

Old dog and the tidyverse

Trees in a carpark (Photo: Luis, click to enlarge).

I started using R ages ago and have happily lived in mostly-base-R for data manipulation. Once in a while I move to something that makes a big difference, like ggplot2 in 2010 or Rmarkdown in 2015, but the set of packages I use for data + plotting hasn't seen many changes. I have to confess… Continue reading Old dog and the tidyverse