Overview

The package offers functions that calculate coalition probabilities in multi-party elections, based on a survey results:

Installation

Install from GitHub using:

devtools::install_github("adibender/coalitions")

Usage

Detailed workflow is outlined in the workflow vignette.

A short overview is presented below.

Scrape surveys

The wrapper get_surveys() which takes no arguments, downloads all surveys currently available at wahlrecht.de and stores them in a nested tibble:

## # A tibble: 7 x 2
##   pollster   surveys           
##   <chr>      <list>            
## 1 allensbach <tibble [43 × 5]> 
## 2 emnid      <tibble [231 × 5]>
## 3 forsa      <tibble [241 × 5]>
## 4 fgw        <tibble [85 × 5]> 
## 5 gms        <tibble [97 × 5]> 
## 6 infratest  <tibble [113 × 5]>
## 7 insa       <tibble [310 × 5]>

Each row represents a polling agency and each row in the surveys column again contains a nested tibble with survey results from different time-points:

surveys %>%
    filter(pollster == "allensbach") %>%
    unnest()
## # A tibble: 43 x 6
##    pollster   date       start      end        respondents survey         
##    <chr>      <date>     <date>     <date>           <dbl> <list>         
##  1 allensbach 2018-03-21 2018-03-02 2018-03-15       1256. <tibble [7 × 3…
##  2 allensbach 2018-02-23 2018-02-02 2018-02-15       1271. <tibble [7 × 3…
##  3 allensbach 2018-01-25 2018-01-05 2018-01-18       1221. <tibble [7 × 3…
##  4 allensbach 2017-12-21 2017-12-01 2017-12-14       1443. <tibble [7 × 3…
##  5 allensbach 2017-11-30 2017-11-22 2017-11-27       1299. <tibble [7 × 3…
##  6 allensbach 2017-10-25 2017-10-07 2017-10-19       1454. <tibble [7 × 3…
##  7 allensbach 2017-09-22 2017-09-13 2017-09-20       1074. <tibble [7 × 3…
##  8 allensbach 2017-09-19 2017-09-06 2017-09-14       1083. <tibble [7 × 3…
##  9 allensbach 2017-09-06 2017-08-22 2017-08-31       1043. <tibble [7 × 3…
## 10 allensbach 2017-08-22 2017-08-04 2017-08-17       1421. <tibble [7 × 3…
## # ... with 33 more rows
## # A tibble: 7 x 8
##   pollster   date       start      end        respondents party  percent
##   <chr>      <date>     <date>     <date>           <dbl> <chr>    <dbl>
## 1 allensbach 2018-03-21 2018-03-02 2018-03-15       1256. cdu      34.0 
## 2 allensbach 2018-03-21 2018-03-02 2018-03-15       1256. spd      19.0 
## 3 allensbach 2018-03-21 2018-03-02 2018-03-15       1256. greens   11.0 
## 4 allensbach 2018-03-21 2018-03-02 2018-03-15       1256. fdp      10.0 
## 5 allensbach 2018-03-21 2018-03-02 2018-03-15       1256. left     10.0 
## 6 allensbach 2018-03-21 2018-03-02 2018-03-15       1256. afd      12.5 
## 7 allensbach 2018-03-21 2018-03-02 2018-03-15       1256. others    3.50
## # ... with 1 more variable: votes <dbl>

Calculate coalition probabilities

For each survey (row) we can calculate the coalition probabilities

## # A tibble: 6 x 4
##   pollster   date       coalition       probability
##   <chr>      <date>     <chr>                 <dbl>
## 1 allensbach 2018-03-21 cdu                   0.   
## 2 allensbach 2018-03-21 cdu_fdp               0.100
## 3 allensbach 2018-03-21 cdu_fdp_greens       99.9  
## 4 allensbach 2018-03-21 spd                   0.   
## 5 allensbach 2018-03-21 left_spd              0.   
## 6 allensbach 2018-03-21 greens_left_spd       0.