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 [54 × 5]> 
## 2 emnid      <tibble [275 × 5]>
## 3 forsa      <tibble [288 × 5]>
## 4 fgw        <tibble [27 × 5]> 
## 5 gms        <tibble [107 × 5]>
## 6 infratest  <tibble [133 × 5]>
## 7 insa       <tibble [357 × 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: 54 x 6
##    pollster   date       start      end        respondents survey          
##    <chr>      <date>     <date>     <date>           <dbl> <list>          
##  1 allensbach 2019-02-19 2019-02-01 2019-02-13        1222 <tibble [7 × 3]>
##  2 allensbach 2019-01-23 2019-01-05 2019-01-17        1249 <tibble [7 × 3]>
##  3 allensbach 2018-12-20 2018-12-01 2018-12-12        1295 <tibble [7 × 3]>
##  4 allensbach 2018-11-30 2018-11-02 2018-11-15        1242 <tibble [7 × 3]>
##  5 allensbach 2018-10-18 2018-09-28 2018-10-11        1259 <tibble [7 × 3]>
##  6 allensbach 2018-09-18 2018-09-01 2018-09-13        1258 <tibble [7 × 3]>
##  7 allensbach 2018-08-15 2018-07-27 2018-08-09        1295 <tibble [7 × 3]>
##  8 allensbach 2018-07-17 2018-07-01 2018-07-12        1295 <tibble [7 × 3]>
##  9 allensbach 2018-06-20 2018-06-01 2018-06-13        1279 <tibble [7 × 3]>
## 10 allensbach 2018-05-17 2018-04-24 2018-05-08        1253 <tibble [7 × 3]>
## # … with 44 more rows
## # A tibble: 7 x 8
##   pollster date       start      end        respondents party percent votes
##   <chr>    <date>     <date>     <date>           <dbl> <chr>   <dbl> <dbl>
## 1 allensb… 2019-02-19 2019-02-01 2019-02-13        1222 cdu      30   367. 
## 2 allensb… 2019-02-19 2019-02-01 2019-02-13        1222 spd      18   220. 
## 3 allensb… 2019-02-19 2019-02-01 2019-02-13        1222 gree…    18.5 226. 
## 4 allensb… 2019-02-19 2019-02-01 2019-02-13        1222 fdp       8    97.8
## 5 allensb… 2019-02-19 2019-02-01 2019-02-13        1222 left      8    97.8
## 6 allensb… 2019-02-19 2019-02-01 2019-02-13        1222 afd      13.5 165. 
## 7 allensb… 2019-02-19 2019-02-01 2019-02-13        1222 othe…     4    48.9

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 2019-02-19 cdu                   0    
## 2 allensbach 2019-02-19 cdu_fdp               0    
## 3 allensbach 2019-02-19 cdu_fdp_greens      100    
## 4 allensbach 2019-02-19 spd                   0    
## 5 allensbach 2019-02-19 left_spd              0    
## 6 allensbach 2019-02-19 greens_left_spd       0.560