View source: R/coalition-probability.R
have_majority | R Documentation |
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 = "_"
)
seats_tab |
A data frame containing number of seats obtained by a party.
Must have columns |
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 |
seats_majority |
The number of seats needed to obtain majority. |
collapse |
Character string passed to |
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.