R/coalition-probability.R
calculate_probs.RdGiven 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
calculate_probs(majority_df, coalitions, exclude_superior = TRUE, ...)A data frame containing logical values indicating if the coalitions (columns) have a majority (rows).
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.
Logical. If TRUE, superior coalitions will
be excluded, otherwise total coalition probabilities will be returned.
Usually it makes sense to exclude superior coalitions.
Further arguments passed to get_superior
A data frame with columns coalition (character) and
probability (numeric, 0–100), one row per coalition.
test_df <- data.frame(
cdu = c(rep(FALSE, 9), TRUE),
cdu_fdp = c(rep(FALSE, 8), TRUE, TRUE),
cdu_fdp_greens = c(TRUE, TRUE, rep(FALSE, 6), TRUE, TRUE))
calculate_probs(test_df, list("cdu", "cdu_fdp", "cdu_fdp_greens"))
#> # A tibble: 3 × 2
#> coalition probability
#> <chr> <dbl>
#> 1 cdu 10
#> 2 cdu_fdp 10
#> 3 cdu_fdp_greens 20
calculate_probs(test_df, list("cdu", "cdu_fdp", "cdu_fdp_greens"), exclude_superior=FALSE)
#> # A tibble: 3 × 2
#> coalition probability
#> <chr> <dbl>
#> 1 cdu 10
#> 2 cdu_fdp 20
#> 3 cdu_fdp_greens 40