Overview

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

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 [49 × 5]> 
## 2 emnid      <tibble [255 × 5]>
## 3 forsa      <tibble [266 × 5]>
## 4 fgw        <tibble [94 × 5]> 
## 5 gms        <tibble [103 × 5]>
## 6 infratest  <tibble [123 × 5]>
## 7 insa       <tibble [335 × 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: 49 x 6
##    pollster   date       start      end        respondents survey          
##    <chr>      <date>     <date>     <date>           <dbl> <list>          
##  1 allensbach 2018-09-18 2018-09-01 2018-09-13        1258 <tibble [7 × 3]>
##  2 allensbach 2018-08-15 2018-07-27 2018-08-09        1295 <tibble [7 × 3]>
##  3 allensbach 2018-07-17 2018-07-01 2018-07-12        1295 <tibble [7 × 3]>
##  4 allensbach 2018-06-20 2018-06-01 2018-06-13        1279 <tibble [7 × 3]>
##  5 allensbach 2018-05-17 2018-04-24 2018-05-08        1253 <tibble [7 × 3]>
##  6 allensbach 2018-04-25 2018-04-03 2018-04-17        1279 <tibble [7 × 3]>
##  7 allensbach 2018-03-21 2018-03-02 2018-03-15        1256 <tibble [7 × 3]>
##  8 allensbach 2018-02-23 2018-02-02 2018-02-15        1271 <tibble [7 × 3]>
##  9 allensbach 2018-01-25 2018-01-05 2018-01-18        1221 <tibble [7 × 3]>
## 10 allensbach 2017-12-21 2017-12-01 2017-12-14        1443 <tibble [7 × 3]>
## # ... with 39 more rows
## # A tibble: 7 x 8
##   pollster date       start      end        respondents par… percent votes
##   <chr>    <date>     <date>     <date>           <dbl> <ch>   <dbl> <dbl>
## 1 allensb… 2018-09-18 2018-09-01 2018-09-13        1258 cdu     31.5 396. 
## 2 allensb… 2018-09-18 2018-09-01 2018-09-13        1258 spd     19.5 245. 
## 3 allensb… 2018-09-18 2018-09-01 2018-09-13        1258 gre…    12.5 157. 
## 4 allensb… 2018-09-18 2018-09-01 2018-09-13        1258 fdp      8.5 107. 
## 5 allensb… 2018-09-18 2018-09-01 2018-09-13        1258 left     9   113. 
## 6 allensb… 2018-09-18 2018-09-01 2018-09-13        1258 afd     15   189. 
## 7 allensb… 2018-09-18 2018-09-01 2018-09-13        1258 oth…     4    50.3

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-09-18 cdu                     0  
## 2 allensbach 2018-09-18 cdu_fdp                 0  
## 3 allensbach 2018-09-18 cdu_fdp_greens         99.9
## 4 allensbach 2018-09-18 spd                     0  
## 5 allensbach 2018-09-18 left_spd                0  
## 6 allensbach 2018-09-18 greens_left_spd         0