votes < hurdle
R/seat-distribution.R
redistribute.Rd
Calculate percentage of votes/seats after excluding parties with
votes < hurdle
redistribute(survey, hurdle = 0.05, others = "others", epsilon = 1e-05)
survey | The actual survey results on which |
---|---|
hurdle | The percentage threshold which has to be reached by a party to enter the parliament. |
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 |
library(coalitions) library(dplyr) # get the latest survey for a sample of German federal election polls surveys <- get_latest(surveys_sample) # 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 x 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 x 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. #>