Calculate percentage of votes/seats after excluding parties with votes < hurdle

redistribute(survey, hurdle = 0.05, others = "others", epsilon = 1e-05)

Arguments

survey

The actual survey results on which dirichlet.draws were based on.

hurdle

The percentage threshold which has to be reached by a party to enter the parliament. Any party called "ssw" will be exempt from the hurdle.

others

A string indicating the name under which parties not listed explicitly are subsumed.

epsilon

Percentages should add up to 1. If they do not, within accuracy of epsilon, an error is thrown.

Value

A data frame with the same structure as survey but with parties below the hurdle removed and vote percentages renormalized.

See also

Examples

library(coalitions)
library(dplyr)
# get the latest survey for a sample of German federal election polls
surveys <- get_latest(surveys_sample) %>% ungroup() %>% slice(1)
# redistribute the shares of 'others' parties and parties with a share of under 5\%
surveys <- surveys %>% mutate(survey_redist = purrr::map(survey, redistribute))
surveys$survey # results before redistribution
#> [[1]]
#> # A tibble: 7 × 3
#>   party  percent votes
#>   <chr>    <dbl> <dbl>
#> 1 cdu         38 718. 
#> 2 spd         24 453. 
#> 3 greens       8 151. 
#> 4 fdp          8 151. 
#> 5 left         9 170. 
#> 6 afd          8 151. 
#> 7 others       5  94.4
#> 
surveys$survey_redist # results after redistribution
#> [[1]]
#> # A tibble: 6 × 3
#>   party  percent votes
#>   <chr>    <dbl> <dbl>
#> 1 cdu     0.4     718.
#> 2 spd     0.253   453.
#> 3 greens  0.0842  151.
#> 4 fdp     0.0842  151.
#> 5 left    0.0947  170.
#> 6 afd     0.0842  151.
#>