Chapter 13 Australian election data

Elections tend to create fascinating data sets. They are spatial in nature, comparable over time (i.e. the number of electorates roughly stays the same) - and more importantly they are consequential for all Australians.

Australia’s compulsory voting system is a remarkable feature of our Federation. Every three-ish years we all turn out at over 7,000 polling booths our local schools, churches, and community centres to cast a ballot and pick up an obligatory election day sausage. The byproduct is a fascinating longitudinal and spatial data set.

The following code explores different R packages, election data sets, and statistical processes aimed at exploring and modelling federal elections in Australia.

One word of warning: I use the term electorates, divisions, and seats interchangeably throughout this chapter.

Let’s start by loading up some packages

library(ggparliament)  # If working with parliamentary data
library(tidyverse)      # Includes dplyr, ggplot2, tidyr, purrr, and more
library(ggthemes)
library(readxl)         # Reading Excel files
library(sf)             # Spatial data handling
library(DT)
library(eechidna)
library(absmapsdata)

Some phenomenal Australian economists and statisticians have put together a handy election package called eechidna. It includes three main data sets for the most recent Australia federal election (2022).

  • fp22: first preference votes for candidates at each electorate

  • tpp22: two party preferred votes for candidates at each electorate

  • tcp22: two candidate preferred votes for candidates at each electorate

They’ve also gone to the trouble of aggregating some census data to the electorate level. This can be found with the abs2022 function.

data(fp22)
data(tpp22)
data(tcp22)
data(abs2022)

# Show the first few rows
head(tpp22)
## # A tibble: 6 × 9
##   DivisionNm DivisionID StateAb LNP_Votes LNP_Percent ALP_Votes ALP_Percent
##   <chr>           <dbl> <chr>       <dbl>       <dbl>     <dbl>       <dbl>
## 1 CANBERRA          101 ACT         25424        27.5     66898        72.5
## 2 FENNER            102 ACT         31315        34.3     59966        65.7
## 3 BANKS             103 NSW         48969        53.2     43076        46.8
## 4 BARTON            104 NSW         31569        34.5     60054        65.5
## 5 BENNELONG         105 NSW         48847        49.0     50801        51.0
## 6 BEROWRA           106 NSW         55771        59.8     37535        40.2
## # ℹ 2 more variables: TotalVotes <dbl>, Swing <dbl>
head(tcp22)
## # A tibble: 6 × 13
##   StateAb DivisionID DivisionNm BallotPosition CandidateID Surname GivenNm
##   <chr>        <dbl> <chr>               <dbl>       <dbl> <chr>   <chr>  
## 1 ACT            318 BEAN                    3       36231 SMITH   DAVID  
## 2 ACT            318 BEAN                    6       37198 HIATT   JANE   
## 3 ACT            101 CANBERRA                5       36241 HOLLO   TIM    
## 4 ACT            101 CANBERRA                6       36228 PAYNE   ALICIA 
## 5 ACT            102 FENNER                  1       36234 LEIGH   ANDREW 
## 6 ACT            102 FENNER                  2       37203 KUSTER  NATHAN 
## # ℹ 6 more variables: PartyAb <chr>, PartyNm <chr>, Elected <chr>,
## #   HistoricElected <chr>, OrdinaryVotes <dbl>, Percent <dbl>

13.1 Election maps

As noted in the introduction, elections are spatial in nature.

Not only does geography largely determine policy decisions, we see that many electorates vote for the same party (or even the same candidate) for decades. How electorate boundaries are drawn is a long story (see here, here, and here).

The summary version is the AEC carves up the population by state and territory, uses a wacky formula to decide how many seats each state and territory should be allocated, then draws maps to try and get a roughly equal number of people in each electorate.

Oh… and did I mention for reasons that aren’t worth explaining that Tasmania has to have at least 5 seats? Our Federation is a funny thing. Anyhow, at time of writing this is how the breakdown of seats looks.

State/Territory Number of members of the House of Representatives (2022)
New South Wales 47
Victoria 39
Queensland 30
Western Australia 15
South Australia 10
Tasmania 5
Australian Capital Territory 3
Northern Territory 2
TOTAL 151

Note: The NT doesn’t have the population to justify it’s second seat . The AEC scheduled to dissolve it after the 2019 election but Parliament intervened in late 2020 and a bill was passed to make sure both seats were kept (creating 151 nationally).

How variant are these 151 electorates in size? Massive.

Durack in Western Australia (1.63 million square kilometres) is by far the largest and the smallest is Grayndler in New South Wales (32 square kilometres).

Let’s make a map to make things easier.

CED_map <- absmapsdata::ced2021 %>%
           ggplot()+
           geom_sf()+
           labs(title="Electoral divisions in Australia",
               subtitle = "It turns out we divide the country in very non-standard blocks",
               caption = "Data: Australian Bureau of Statistics 2016",
               x="",
               y="") + 
           theme_minimal() +
            theme(axis.ticks.x = element_blank(),axis.text.x = element_blank())+
            theme(axis.ticks.y = element_blank(),axis.text.y = element_blank())+
            theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
            theme(legend.position = "right")+
            theme(plot.title=element_text(face="bold",size=12))+
            theme(plot.subtitle=element_text(size=11))+
            theme(plot.caption=element_text(size=8))


CED_map_remove_6 <- ced2021 %>%
                    dplyr::filter(!ced_code_2021 %in% c(506,701,404,511,321,317)) %>%   
                    ggplot()+
           geom_sf()+
           labs(title="194 electoral divisions in Australia",
               subtitle = "Turns out removing the largest 6 electorates makes a difference",
               caption = "Data: Australian Bureau of Statistics 2016",
               x="",
               y="") + 
           theme_minimal() +
            theme(axis.ticks.x = element_blank(),axis.text.x = element_blank())+
            theme(axis.ticks.y = element_blank(),axis.text.y = element_blank())+
            theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
            theme(legend.position = "right")+
            theme(plot.title=element_text(face="bold",size=12))+
            theme(plot.subtitle=element_text(size=11))+
            theme(plot.caption=element_text(size=8))

CED_map
CED_map_remove_6

Next let’s look at what party/candidate is currently the sitting member for each electorate. To do this on a map we’re going to need to join our tcp22 data and the ced2021 spatial data.

In the first data set, the electorate column in called ‘DivisionNm’ and in the second ‘ced_name_2021’.

We see the data in our DivisionNm variable is in UPPERCASE while our ced_name_2021 variable is in Titlecase. Let’s change the first variable to Titlecase to match.

We can then then join the two dataframes using the left_join function.

#Pull in the electorate shapefiles from the absmapsdata package
electorates <- ced2021

#Make the DivisionNm Titlecase
tcp22$DivisionNm=str_to_title(tcp22$DivisionNm)

tcp22_edit <- tcp22 %>% distinct() %>% filter(Elected == "Y")

#Make the column names the same
electorates <- dplyr::rename(electorates, DivisionNm = ced_name_2021)

ced_map_data <- left_join(tcp22_edit, electorates, by = "DivisionNm")

ced_map_data <- as.data.frame(ced_map_data)

head(ced_map_data, n=151)

13.2 Analysis

Let’s start by answering a simple question: who won the election? For this we’ll need to use the two-candidate preferred data set (to make sure we capture all the minor parties that won seats).

Note in the table above, the PartyNm variable is a mess. Some candidates noted their party by it’s abbreviation rather than full name, others put in a state specific prefix For this analysis, the PartyAb variable is cleaner to use.

who_won <- tcp22 %>% 
  filter(Elected == "Y") %>% 
  group_by(PartyAb) %>% 
  tally() %>% 
  arrange(desc(n)) 

head(who_won, n=10)
## # A tibble: 7 × 2
##   PartyAb     n
##   <chr>   <int>
## 1 ALP        77
## 2 LP         48
## 3 IND        10
## 4 NP         10
## 5 GRN         4
## 6 KAP         1
## 7 XEN         1

Next up let’s see which candidates won with the smallest percentage of first preference votes. Australia’s preferential voting system normally makes these numbers quite interesting.

who_won_least_votes_prop <- fp22 %>% 
  filter(Elected == "Y") %>% 
  arrange(Percent) %>% 
  mutate(candidate_full_name = paste0(GivenNm, " ", Surname, " (", CandidateID, ")")) %>% 
  dplyr::select(candidate_full_name, PartyNm, DivisionNm, Percent)

head(who_won_least_votes_prop,n=10)
## # A tibble: 10 × 4
##    candidate_full_name            PartyNm                DivisionNm   Percent
##    <chr>                          <chr>                  <chr>          <dbl>
##  1 KYLEA JANE TINK (37452)        INDEPENDENT            NORTH SYDNEY    25.2
##  2 SAM BIRRELL (36061)            NATIONAL PARTY         NICHOLLS        26.1
##  3 STEPHEN BATES (37338)          QUEENSLAND GREENS      BRISBANE        27.2
##  4 MICHELLE ANANDA-RAJAH (36433)  AUSTRALIAN LABOR PARTY HIGGINS         28.5
##  5 JUSTINE ELLIOT (36802)         AUSTRALIAN LABOR PARTY RICHMOND        28.8
##  6 BRIAN MITCHELL (37276)         AUSTRALIAN LABOR PARTY LYONS           29.0
##  7 KATE CHANEY (36589)            INDEPENDENT            CURTIN          29.5
##  8 DAI LE (36240)                 INDEPENDENT            FOWLER          29.5
##  9 ELIZABETH WATSON-BROWN (37370) QUEENSLAND GREENS      RYAN            30.2
## 10 REBEKHA SHARKIE (37710)        CENTRE ALLIANCE        MAYO            31.4

This is really something.

The relationship we’re seeing here seems to be these are many the seats that are won with barely 30% of the first preference vote.

The electorate I grew up in is listed here (Richmond) - let’s look at how the votes were allocated.

Richmond_fp <- fp22 %>% 
  filter(DivisionNm == "RICHMOND") %>% 
  arrange(-Percent) %>% 
  mutate(candidate_full_name = paste0(GivenNm, " ", Surname, " (", CandidateID, ")")) %>% 
  dplyr::select(candidate_full_name, PartyNm, DivisionNm, Percent, OrdinaryVotes)

head(Richmond_fp,n=10)
## # A tibble: 10 × 5
##    candidate_full_name            PartyNm       DivisionNm Percent OrdinaryVotes
##    <chr>                          <chr>         <chr>        <dbl>         <dbl>
##  1 JUSTINE ELLIOT (36802)         AUSTRALIAN L… RICHMOND     28.8          28733
##  2 MANDY NOLAN (36361)            THE GREENS    RICHMOND     25.3          25216
##  3 KIMBERLY HONE (36351)          NATIONAL PAR… RICHMOND     23.4          23299
##  4 GARY BIGGS (36648)             LIBERAL DEMO… RICHMOND      7.7           7681
##  5 TRACEY BELL-HENSELIN (37831)   ONE NATION    RICHMOND      4.08          4073
##  6 ROBERT JAMES MARKS (37084)     UNITED AUSTR… RICHMOND      2.93          2922
##  7 DAVID WARTH (37813)            INDEPENDENT   RICHMOND      2.35          2341
##  8 MONICA SHEPHERD (36408)        INFORMED MED… RICHMOND      2.28          2271
##  9 NATHAN JONES (37721)           INDEPENDENT   RICHMOND      1.98          1974
## 10 TERRY PATRICK SHARPLES (37823) INDEPENDENT   RICHMOND      1.28          1274

Sure enough - the Greens certainly helped get the ALP across the line.

The interpretation that these seats are the ‘most marginal’ is incorrect under a preferential voting system (e.g. imagine if ALP win 30% and the Greens win 30% - that is a pretty safe 10% margin assuming traditional preference flows).

But - let’s investigate which seats are the most marginal.

who_won_smallest_margin <- tcp22 %>% 
  filter(Elected == "Y") %>% 
  mutate(percent_margin = 2*(Percent - 50), vote_margin = round(percent_margin * OrdinaryVotes / Percent)) %>% 
  arrange(Percent) %>% 
  mutate(candidate_full_name = paste0(GivenNm, " ", Surname, " (", CandidateID, ")")) %>% 
  dplyr::select(candidate_full_name, PartyNm, DivisionNm, Percent, OrdinaryVotes, percent_margin, vote_margin)

head(who_won_smallest_margin, n=20)
## # A tibble: 20 × 7
##    candidate_full_name   PartyNm DivisionNm Percent OrdinaryVotes percent_margin
##    <chr>                 <chr>   <chr>        <dbl>         <dbl>          <dbl>
##  1 FIONA PHILLIPS (3677… AUSTRA… Gilmore       50.2         56039          0.340
##  2 MICHAEL SUKKAR (3671… LIBERA… Deakin        50.2         50322          0.380
##  3 JAMES STEVENS (37067) LIBERA… Sturt         50.4         56813          0.900
##  4 IAN GOODENOUGH (3659… LIBERA… Moore         50.7         52958          1.32 
##  5 KEITH WOLAHAN (36733) LIBERA… Menzies       50.7         51198          1.36 
##  6 BRIAN MITCHELL (3727… AUSTRA… Lyons         50.9         37341          1.84 
##  7 MARION SCRYMGOUR (37… A.L.P.  Lingiari      51.0         23339          1.90 
##  8 JEROME LAXALE (36827) AUSTRA… Bennelong     51.0         50801          1.96 
##  9 KATE CHANEY (36589)   INDEPE… Curtin        51.3         53847          2.52 
## 10 BRIDGET KATHLEEN ARC… LIBERA… Bass          51.4         35288          2.86 
## 11 AARON VIOLI (36711)   LIBERA… Casey         51.5         51283          2.96 
## 12 DAI LE (36240)        INDEPE… Fowler        51.6         44348          3.26 
## 13 PETER DUTTON (37493)  LIBERA… Dickson       51.7         51196          3.40 
## 14 MICHELLE ANANDA-RAJA… AUSTRA… Higgins       52.1         49726          4.12 
## 15 GORDON REID (36801)   AUSTRA… Robertson     52.3         50277          4.52 
## 16 PAT CONAGHAN (36342)  NATION… Cowper        52.3         58204          4.64 
## 17 SAM LIM (37337)       AUSTRA… Tangney       52.4         56331          4.76 
## 18 SOPHIE SCAMPS (37450) INDEPE… Mackellar     52.5         51973          5    
## 19 ELIZABETH WATSON-BRO… QUEENS… Ryan          52.6         52286          5.3  
## 20 ALAN TUDGE (36704)    LIBERA… Aston         52.8         51840          5.62 
## # ℹ 1 more variable: vote_margin <dbl>

Crikey. We see Fiona Phillips in Gilmore got in with a 0.17% margin (just 380 votes!)

While we’re at it, we better do the opposite and see who romped it in by the largest margin.

who_won_largest_margin <- tcp22 %>% 
  filter(Elected == "Y") %>% 
  mutate(percent_margin = 2*(Percent - 50), vote_margin = round(percent_margin * OrdinaryVotes / Percent)) %>% 
  arrange(desc(Percent)) %>% 
  mutate(candidate_full_name = paste0(GivenNm, " ", Surname, " (", CandidateID, ")")) %>% 
  dplyr::select(candidate_full_name, PartyNm, DivisionNm, Percent, OrdinaryVotes, percent_margin, vote_margin)

 head(who_won_largest_margin, n=20)
## # A tibble: 20 × 7
##    candidate_full_name   PartyNm DivisionNm Percent OrdinaryVotes percent_margin
##    <chr>                 <chr>   <chr>        <dbl>         <dbl>          <dbl>
##  1 DAVID LITTLEPROUD (3… LIBERA… Maranoa       72.1         67153           44.2
##  2 ANDREW WILKIE (33553) INDEPE… Clark         70.8         46668           41.6
##  3 DARREN CHESTER (3604… NATION… Gippsland     70.6         71205           41.1
##  4 ANNE WEBSTER (36060)  NATION… Mallee        69.0         70523           38.0
##  5 SHARON CLAYDON (3680… AUSTRA… Newcastle     68.0         71807           36.0
##  6 MARK COULTON (36363)  NATION… Parkes        67.8         60433           35.7
##  7 ANTHONY ALBANESE (36… AUSTRA… Grayndler     67.0         63413           34.1
##  8 JOSH WILSON (37314)   AUSTRA… Fremantle     66.9         65585           33.8
##  9 MADELEINE KING (3718… AUSTRA… Brand         66.7         63829           33.4
## 10 TANYA PLIBERSEK (368… AUSTRA… Sydney        66.7         68770           33.4
## 11 TONY PASIN (37083)    LIBERA… Barker        66.6         70483           33.2
## 12 DANIEL MULINO (36385) AUSTRA… Fraser        66.5         61251           33  
## 13 BARNABY JOYCE (36335) NATION… New Engla…    66.4         64622           32.9
## 14 SUSSAN LEY (37032)    LIBERA… Farrer        66.4         66739           32.7
## 15 AMANDA RISHWORTH (36… AUSTRA… Kingston      66.4         72564           32.7
## 16 ANDREW LEIGH (36234)  AUSTRA… Fenner        65.7         59966           31.4
## 17 ANDREW GILES (36447)  AUSTRA… Scullin       65.6         59761           31.2
## 18 LINDA BURNEY (36820)  AUSTRA… Barton        65.5         60054           31.1
## 19 MATT KEOGH (37195)    AUSTRA… Burt          65.2         59704           30.4
## 20 TONY BURKE (36809)    AUSTRA… Watson        65.1         55810           30.2
## # ℹ 1 more variable: vote_margin <dbl>

Wowza. That’s really something. Some candidates won seats with a 40-45 percent margin - scooping up 70% of the two candidate preferred vote in the process!

We can also cut the seats by state for a look at where the ‘strongholds’ are across the country.

who_won <- tcp22 %>% 
  filter(Elected == "Y") %>% 
  group_by(PartyAb, StateAb) %>% 
  tally() %>% 
  arrange(desc(n)) 

who_won_by_state <- spread(who_won,StateAb, n) %>% arrange(desc(NSW))

head(who_won_by_state, n=10)

13.4 Booth data

The AEC maintains a handy spreadsheet of booth locations for recent federal elections. You can search for your local booth location (probably a school, church, or community center) in the table below.

## # A tibble: 10 × 15
##    State DivisionID DivisionNm PollingPlaceID PollingPlaceTypeID PollingPlaceNm 
##    <chr>      <dbl> <chr>               <dbl>              <dbl> <chr>          
##  1 ACT          101 Canberra             8829                  1 Barton         
##  2 ACT          101 Canberra            64583                  5 Belconnen CANB…
##  3 ACT          101 Canberra            65504                  5 BLV Canberra P…
##  4 ACT          101 Canberra            11877                  1 Bonython       
##  5 ACT          101 Canberra             8802                  1 Braddon (Canbe…
##  6 ACT          101 Canberra            11452                  1 Calwell        
##  7 ACT          101 Canberra             8806                  1 Campbell       
##  8 ACT          101 Canberra             8761                  1 Chapman        
##  9 ACT          101 Canberra             8763                  1 Chisholm       
## 10 ACT          101 Canberra             8808                  1 City (Canberra)
## # ℹ 9 more variables: PremisesNm <chr>, PremisesAddress1 <chr>,
## #   PremisesAddress2 <chr>, PremisesAddress3 <chr>, PremisesSuburb <chr>,
## #   PremisesStateAb <chr>, PremisesPostCode <chr>, Latitude <dbl>,
## #   Longitude <dbl>

What do these booths look like on a map? Let’s reuse the CED map above and plot a point for each booth location.

ggplot() +
  geom_sf(data = ced2021) +
  geom_point(data = booths, aes(x = Longitude, y = Latitude), 
             colour = "purple", size = 1, alpha = 0.3, inherit.aes = FALSE) +
  labs(
    title = "Polling booths in Australia",
    subtitle = " ",
    caption = "Data: Australian Electoral Commission 2016",
    x = "",
    y = ""
  ) + 
  theme_minimal() +
  theme(
    axis.ticks.x = element_blank(),
    axis.text.x = element_blank(),
    axis.ticks.y = element_blank(),
    axis.text.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    legend.position = "right",
    plot.title = element_text(size = 12),
    plot.subtitle = element_text(size = 11),
    plot.caption = element_text(size = 8)
  ) +
  xlim(c(112, 157)) + 
  ylim(c(-44, -11))

Figuring out where a candidates votes come from within an electorate is fundamental to developing a campaign strategy. Even in small electorates (e.g. Wentworth), there are pockets of right leaning and left leaning districts. Once you factor in preference flows, this multi-variate calculus becomes important to winning or maintaining a seat.

In the eechidnapackage, election results are provided at the resolution of polling place. Unfortunately, these are yet to be updated for elections after 2016.

The data sets must be downloaded using the functions firstpref_pollingbooth_download, twoparty_pollingbooth_download or twocand_pollingbooth_download (depending on the vote type).

The two files need to be merged to be useful for analysis. Both have a unique ID for the polling place that can be used to match the records. The two party preferred vote, a measure of preference between only the Australian Labor Party (ALP) and the Liberal/National Coalition (LNP), is downloaded using twoparty_pollingbooth_download. The preferred party is the one with the higher percentage, and we use this to colour the points indicating polling places.

We see that within some big rural electorates (e.g. in Western NSW), there are pockets of ALP preference despite the seat going to the LNP. Note that this data set is on a tpp basis - so we can’t see the booths that were won by minor parties (although it would be fascinating).We see that within some big rural electorates (e.g. in Western NSW), there are pockets of ALP preference despite the seat going to the LNP. Note that this data set is on a tpp basis - so we can’t see the booths that were won by minor parties (although it would be fascinating).

The two candidate preferred vote (downloaded with twocand_pollingbooth_download) is a measure of preference between the two candidates who received the most votes through the division of preferences, where the winner has the higher percentage.

13.5 Informal votes

Over 700,000 people (around 5% of all votes cast) vote informally each election. Of these, over have ‘no clear first preference’, meaning their vote did not contribute to the campaign of any candidate.

I’ll be honest, informal votes absolutely fascinate me. Not only are there 8 types of informal votes (you can read all about the Australian Electoral Commission’s analysis here), but the rate of informal voting varies a tremendous amount by electorate.

Broadly, we can think of informal votes in two main buckets.

  1. Protest votes

  2. Stuff-ups

If we want to get particular about it, I like to subcategorise these buckets into:

  1. Protest votes (i.e. a person that thinks they are voting against):

    • the democratic system,

    • their local selection of candidates on the ballot, or

    • the two most likely candidates for PM.

  2. Stuff ups (people who):

    • filled in the form wrong but a clear preference was still made

    • stuffed up the form entirely and it didn’t contribute towards the tally for any candidtate

The AEC works tirelessly to reduce stuff-ups on ballot papers (clear instructions and UI etc), but there isn’t much of a solution for protest votes.