Do coalitions have a majority

have_majority(
  seats_tab,
  coalitions = list(c("cdu"), c("cdu", "fdp"), c("cdu", "fdp", "greens"), c("spd"),
    c("spd", "left"), c("spd", "left", "greens")),
  seats_majority = 300L,
  collapse = "_"
)

Arguments

seats_tab

A data frame containing number of seats obtained by a party. Must have columns party and seats.

coalitions

A list of coalitions for which coalition probabilities should be calculated. Each list entry must be a vector of party names. Those names need to correspond to the names in majority_df.

seats_majority

The number of seats needed to obtain majority.

collapse

Character string passed to base::paste.

Value

A data frame with one column per coalition. Each column is logical indicating whether the coalition obtained a majority in each simulation row.

Examples

library(coalitions)
library(dplyr)
library(purrr)
# get the latest survey for a sample of German federal election polls
surveys <- get_latest(surveys_sample) %>% ungroup() %>% slice(1)
# check for majorities of two coalitions
coals <- list(c("cdu", "fdp"),
              c("spd", "left", "greens"))
# only use 100 simulations for a fast runtime
surveys <- surveys %>% mutate(draws = map(survey, draw_from_posterior, nsim = 100),
                              seats = map2(draws, survey, get_seats),
                              majorities = map(seats, have_majority, coalitions = coals))
surveys$majorities
#> [[1]]
#> # A tibble: 100 × 2
#>    cdu_fdp greens_left_spd
#>    <lgl>   <lgl>          
#>  1 FALSE   TRUE           
#>  2 FALSE   TRUE           
#>  3 FALSE   TRUE           
#>  4 FALSE   TRUE           
#>  5 FALSE   TRUE           
#>  6 FALSE   TRUE           
#>  7 FALSE   TRUE           
#>  8 FALSE   TRUE           
#>  9 FALSE   TRUE           
#> 10 FALSE   TRUE           
#> # ℹ 90 more rows
#>