get_probabilities {coalitions}  R Documentation 
Given a table with simulations in the rows and coalitions in the columns, this function returns the coalition probabilities for a specified coalition, by default excluding superior coalitions first
get_probabilities(
x,
coalitions = list(c("cdu"), c("cdu", "fdp"), c("cdu", "fdp", "greens"), c("spd"),
c("spd", "left"), c("spd", "left", "greens")),
nsim = 1e+05,
distrib.fun = sls,
seats_majority = 300L,
seed = as.numeric(now()),
correction = NULL
)
x 
A table containing one row per survey and survey information in
long format in a separate column named 
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 
nsim 
number of simulations 
distrib.fun 
Function to calculate seat distribution. Defaults to

seats_majority 
The number of seats needed to obtain majority. 
seed 
sets seed 
correction 
A positive number. If not 
library(coalitions)
library(dplyr)
# get the latest survey for a sample of German federal election polls
surveys < get_latest(surveys_sample)
# calculate probabilities for two coalitions
probs < get_probabilities(surveys,
coalitions = list(c("cdu", "fdp"),
c("spd", "left", "greens")),
nsim = 100) # ensure fast runtime with only 100 simulations
probs %>% tidyr::unnest("probabilities")