Calculate seat distribution from draws from posterior

get_seats(
  dirichlet.draws,
  survey,
  distrib.fun = sls,
  samplesize = NULL,
  hurdle = 0.05,
  others = "others",
  ...
)

Arguments

dirichlet.draws

Matrix containing random draws from posterior.

survey

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

distrib.fun

Function to calculate seat distribution. Defaults to sls (Sainte-Lague/Schepers).

samplesize

Number of individuals participating in the survey.

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.

...

Further arguments passed to distrib.fun.

Value

A data frame containing seat distributions for each simulation in dirichlet.draws

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)
# simulate 100 seat distributions
surveys <- surveys %>% mutate(draws = purrr::map(survey, draw_from_posterior, nsim = 100),
                              seats = purrr::map2(draws, survey, get_seats))
surveys$seats
#> [[1]]
#> # A tibble: 600 × 3
#>      sim party  seats
#>    <int> <chr>  <int>
#>  1     1 cdu       51
#>  2     1 spd      245
#>  3     1 greens    50
#>  4     1 fdp       51
#>  5     1 left      60
#>  6     1 afd      141
#>  7     2 cdu       44
#>  8     2 spd      237
#>  9     2 greens    55
#> 10     2 fdp       52
#> # ℹ 590 more rows
#>