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.

Examples

library(coalitions) library(dplyr) library(purrr) # get the latest survey for a sample of German federal election polls surveys <- get_latest(surveys_sample) # 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 x 2 #> cdu_fdp greens_left_spd #> <lgl> <lgl> #> 1 TRUE FALSE #> 2 FALSE FALSE #> 3 FALSE FALSE #> 4 FALSE FALSE #> 5 FALSE FALSE #> 6 FALSE FALSE #> 7 FALSE FALSE #> 8 FALSE FALSE #> 9 FALSE FALSE #> 10 FALSE FALSE #> # … with 90 more rows #>