R/coalition-probability.R
calculate_prob.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_prob(majority_df, coalition, exclude_superior = TRUE, ...)A data frame containing logical values indicating if the coalitions (columns) have a majority (rows).
The coalition of interest for which superior coalitions
will be obtained by get_superior.
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 one numeric column giving the coalition probability (percentage of simulations in which the coalition obtained a majority, after optionally excluding superior coalitions).
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_prob(test_df, "cdu_fdp_greens") # exclude_superior defaults to TRUE
#> cdu_fdp_greens
#> 1 20
calculate_prob(test_df, "cdu_fdp_greens", exclude_superior=FALSE)
#> cdu_fdp_greens
#> 1 40